<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kristian&#039;s web log</title>
	<atom:link href="http://kristian.blog.linpro.no/feed/" rel="self" type="application/rss+xml" />
	<link>http://kristian.blog.linpro.no</link>
	<description>A Free Software Hacker&#039;s blog</description>
	<lastBuildDate>Tue, 16 Feb 2010 23:35:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wikish &#8211; Mediawiki-editing on command line</title>
		<link>http://kristian.blog.linpro.no/2010/02/17/wikish-mediawiki-editing-on-command-line/</link>
		<comments>http://kristian.blog.linpro.no/2010/02/17/wikish-mediawiki-editing-on-command-line/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 23:09:19 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[/dev/random]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=163</guid>
		<description><![CDATA[wiki.sh (or wikish) is a shell-script I wrote to work with our internal mediawiki-wikis. It&#8217;s functional for both the new varnish-software wiki and the old redpill-linpro wiki I use.
Basically it lets you edit wiki-content with vi, vim, gvim or even nvi. Very simple, and a result of mvs, wikipediafs and mediawiki-fuse being seemingly horrible messes. [...]]]></description>
			<content:encoded><![CDATA[<p>wiki.sh (or wikish) is a shell-script I wrote to work with our internal mediawiki-wikis. It&#8217;s functional for both the new varnish-software wiki and the old redpill-linpro wiki I use.</p>
<p>Basically it lets you edit wiki-content with vi, vim, gvim or even nvi. Very simple, and a result of mvs, wikipediafs and mediawiki-fuse being seemingly horrible messes. It also makes it possible for me to easily script copy/pasting from one wiki to an other without much hassel. All in all it&#8217;s a little over 200 lines of sh-code using lwp-request/curl and awk. It works.</p>
<p>Get it from: <a href="http://github.com/KristianLyng/wikish">http://github.com/KristianLyng/wikish</a></p>
<p>Currently doesn&#8217;t support &#8220;normal&#8221; mediawiki-login, but rpl and varnish-software use basic auth over ssl and work fine. I&#8217;ll gladly add normal login if someone gives me an account on a wiki they own and operate where I can test it (not wikipedia please, unless you are wikimedia).</p>
<p>Usage example: wikiedit &#8220;Main Page&#8221;. (that simple, yes)</p>
<p>PS: Sorry for hijacking the name.</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/02/17/wikish-mediawiki-editing-on-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Varnish purges</title>
		<link>http://kristian.blog.linpro.no/2010/02/02/varnish-purges/</link>
		<comments>http://kristian.blog.linpro.no/2010/02/02/varnish-purges/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 13:55:33 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[Varnish]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[purging]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=152</guid>
		<description><![CDATA[Varnish purges can be tricky. Both the model of purging that Varnish use and the syntax you need to use to take advantage of them can be difficult to grasp. It took me about five Varnish Administration Courses until I was happy with how I explained it to the participants, specially because the syntax is [...]]]></description>
			<content:encoded><![CDATA[<p>Varnish purges can be tricky. Both the model of purging that Varnish use and the syntax you need to use to take advantage of them can be difficult to grasp. It took me about five Varnish Administration Courses until I was happy with how I explained it to the participants, specially because the syntax is the most confusing syntax we have in VCL. However, it&#8217;s not very hard to work with once you understand the magic at work.</p>
<h2>0. Separating purges and forced expiry</h2>
<p>There are two ways to throw something out of the cache before the TTL is due in Varnish. You can either find the object you want gone and set the TTL to 0 forcing it to expire, or use Varnish&#8217; purge mechanism. Setting ttl to 0 has it&#8217;s advantages, since you evict the object immediately, but it also means you have to evict one object at a time. This is fairly easy and usually done by having Varnish look for a &#8220;PURGE&#8221; request and handle it. This is not what I&#8217;ll talk about today, though. Read <a href="http://varnish-cache.org/wiki/VCLExamplePurging">http://varnish-cache.org/wiki/VCLExamplePurging</a> for information on forcibly expiring an object.</p>
<h2>1. The challenges of purging a cache</h2>
<p>The main reason people purge their cache, is to make room for updated content. Some journalist updated an article and you want the old one &#8211; possibly cached for days &#8211; gone. In addition, you may not know exactly what to cache, or it might be broader than just one item. En example would be a template used to generate multiple php files. Or all sports articles.</p>
<p>All in all, you do not purge to conserve memory. Because you expect that the cache will be filled soon.</p>
<p>If you are to purge all your php pages and you have 150 000 objects, you may not want to go looking for them either. This the reason some competing cache products are slow at large purging. By looking for all these objects, you might have to hit the disk to fetch cold objects.</p>
<p>In varnish, we also leave it up to VCL what&#8217;s unique to an object. That is to say: You can override the cache hash. By default it&#8217;s the host name or server IP combined with the &#8220;URL&#8221;. This is usually what people want, but sometimes you may want to add a cookie into the mix, for instance. The point is, we don&#8217;t know exactly what people cache on.</p>
<h2>2. How Varnish attacks the problem</h2>
<p>In Varnish, you purge by adding a purge to a list. This list can grow large if you add several very specific purges, but we try to reduce the overlap as much as possible. The purge in question can be pretty much anything you can match in VCL, including regular expressions on URLs, host names and user-agents for that matter. You can see the list by typing &#8220;purge.list&#8221; in the command line interface (CLI, or telnet).</p>
<p>Each object in your cache points to the last purge it was tested against. When you hit an object, it checks if there are any new purges in the list, test the object against them, then either evict the object and fetch a new one, or update the &#8220;last tested against&#8221;-pointer.</p>
<p>Because of this, the &#8216;req&#8217;-structure you are evaluating is actually that of the client to access the object next, not the client who pulled the object from the backend. It also means that every single object in your cache that is hit will be tested against all purges to see if it matches. But it&#8217;s spread out over time. It might sound wasteful, but it means you can add purges at constant time, and not really think about the cost of evaluating them.</p>
<p>It also means the object stays in the cache until it expires if it is not hit. So you don&#8217;t free up memory.</p>
<h2>3. Adding purges &#8220;by hand&#8221;</h2>
<p>Want to purge a http://example.com/somedirectory/ and everything beneath that path?</p>
<blockquote>
<pre>purge req.http.host == example.com &amp;&amp; req.url ~ ^/somedirectory/.*$</pre>
<p>or</p>
<pre>purge req.url ~ ^/somedirectory/ &amp;&amp; req.http.host == example.com</pre>
</blockquote>
<p>Want to purge all objects with a &#8220;Cache-Control: max-age=&#8221; set to 3600 ?</p>
<blockquote>
<pre>purge obj.http.Cache-Control ~ max-age=3600</pre>
<p>or to take white space into account and no trailing numbers:</p>
<pre>purge obj.http.Cache-Control ~ max-age ?= ?3600[^0-9]</pre>
</blockquote>
<p>Notice that all of the variables are in the same &#8220;VCL-context&#8221; as the client to hit the object next, so if you purge on req.http.user-agent, it&#8217;s fairly random if the object is really purged, because you (probably) can&#8217;t predict what user-agent the next person to visit a specific object is using. If you wish to purge based on a parameter sent from the &#8220;original&#8221; client, you will have to store that parameter in obj.http somewhere and remove it in vcl_deliver if you don&#8217;t want to expose it.</p>
<h2>4. Adding purges in VCL</h2>
<p>This is where it gets tricky. The normal example of why, is this: purge(&#8221;req.url == &#8221; req.url);</p>
<p>Normal programming-thinking would tell you that this would match everything, since the url is always equal to itself. This is where VCL string concatenation comes into the picture. In reality, you are writing: &#8220;add this to the purge list: The string containing &#8220;req.url == &#8221; and the value of the variable req.url&#8221;.</p>
<p>In other words, if the client access http://example.com/foobar and hit the code above, this would say: &#8220;Add the string containing &#8220;req.url == &#8221; and &#8220;/foobar&#8221; to the purge list.&#8221; <strong>The quotation marks are essential!</strong></p>
<p>I find it easier to think of it as preparing a string for the purge-command on cli. Varnish concatenates two strings without any special sign.</p>
<p>In the end, this is the rule of thumb: Put everything you expect to see literally when you type &#8220;purge.list&#8221; inside quotation marks, and put things you wish to replace with the variable of the calling session outside.</p>
<p>So you actually have three different VCL contexts to worry about:</p>
<ol>
<li>The context that originally pulled the object in from a backend (not much you can do here unless you hide things in obj.http)</li>
<li>The context that will hit the object and thereby test the object against the purge. Any variable in this context has to be inside quotation marks.</li>
<li>The context that triggered the purge, variables from this context should be outside quotation marks, so they are replaced with their string values before being added to the purge list.</li>
</ol>
<p>The reason you do not need quotation marks if you enter the purge command on the command line interface is because you don&#8217;t have the third context. There is no req.url in telnet, since you are not going through VCL at all.</p>
<p>Some examples, note that when I say &#8220;supplied by the client&#8221; I mean the client initiating the purge, typically some smart system you&#8217;ve set up:</p>
<blockquote><p>Purge object on the current host and URLs matching the regex stored in the X-Purge-Regex header supplied by the client:</p>
<pre>purge("req.http.host == " req.http.host " &amp;&amp; req.url ~ " req.http.X-Purge-Regex);</pre>
<p>Purge all php for any example.com-domain:</p>
<pre>purge("req.http.host ~ example.com$ &amp;&amp; req.url ~ ^/.*\.php");</pre>
<p>Same, but for the host provided in the X-Purge-HostPHP:</p>
<pre>purge("req.http.host ~ " req.http.X-Purge-HostPHP " &amp;&amp; req.url ~ ^/.*\.php");</pre>
<p>Purge objects with X-Cache-Channel set to &#8220;sport&#8221;:</p>
<pre>purge("obj.http.X-Cache-Channel ~ sport");</pre>
<p>Same, but purge the cache-channel set in the header &#8216;X-Purge-CC&#8217;:</p>
<pre>purge("obj.http.X-Cache-Channel ~ " X-Purge-CC);</pre>
<p>Purge in vcl_fetch if the backend sent a X-Purge-URL header (weird thing to do, but fun example):</p>
<pre>sub vcl_fetch {</pre>
<pre style="padding-left: 30px">(....)</pre>
<pre style="padding-left: 30px">if (obj.http.X-Purge-URL) {</pre>
<pre style="padding-left: 60px">purge("req.url ~ " obj.http.X-Purge-URL);</pre>
<pre style="padding-left: 30px">}</pre>
<pre style="padding-left: 30px">(...)</pre>
<pre>}</pre>
</blockquote>
<p>(PS: I have not actually tested all these examples, but they <em>look</em> correct)</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/02/02/varnish-purges/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Varnish best practices</title>
		<link>http://kristian.blog.linpro.no/2010/01/26/varnish-best-practices/</link>
		<comments>http://kristian.blog.linpro.no/2010/01/26/varnish-best-practices/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 15:21:34 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[/dev/random]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[tuning]]></category>
		<category><![CDATA[Varnish]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=142</guid>
		<description><![CDATA[A while ago I wrote about common Varnish issues, and I think it&#8217;s time for an updated version. This time, I&#8217;ve decided to include a few somewhat uncommon issues that, if set, can be difficult to spot or track down. A sort of pitfall-avoidance, if you will. I&#8217;ll add a little summary with parameters and [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote about <a href="http://kristian.blog.linpro.no/tag/varnish/">common Varnish issues</a>, and I think it&#8217;s time for an updated version. This time, I&#8217;ve decided to include a few somewhat uncommon issues that, if set, can be difficult to spot or track down. A sort of pitfall-avoidance, if you will. I&#8217;ll add a little summary with parameters and such at the end.</p>
<h2>1. Run Varnish on a 64 bit operating system</h2>
<p>Varnish works on 32-bit, but was designed for 64bit. It&#8217;s all about virtual memory: Things like stack size suddenly matter on 32bit. If you must use Varnish on 32-bit, you&#8217;re somewhat on your own. However, try to fit it within 2GB. I wouldn&#8217;t recommend a cache larger than 1GB, and no more than a few hundred threads&#8230; (Why are you on 32bit again?)</p>
<h2>2. Watch /var/log/syslog</h2>
<p>Varnish is flexible, and has a relatively robust architecture. If a Varnish worker thread was to do something Bad and Varnish noticed, an assert would be triggered, Varnish would shut down and the management process would start it up again almost instantly. This is logged. If it wasn&#8217;t, there&#8217;s a decent chance you wouldn&#8217;t notice, since the downtime is often sub-second. However, your cache is emptied. We&#8217;ve had several customers contact us about performance-issues, only to realize they&#8217;re essentially restarting Varnish several times per minute.</p>
<p>This might make it sound like Varnish is unstable: It&#8217;s not. But there are bugs, and I happen to see a lot of them, since that&#8217;s my job.</p>
<p>An extra note: <strong>On Debian-based systems, /var/log/messages and /var/log/syslog is not the same. </strong>Varnish will log the restart in /var/log/messages but the actual assert error is only found in /var/log/syslog, so make sure you look there too.</p>
<p>The best way to deal with assert errors is to search our bug tracker for the relevant function-name.</p>
<h2>3. Threads</h2>
<p>The default values for threads is based on a philosophy I&#8217;ve since come to realize isn&#8217;t optimal. The idea was to minimize the memory footprint of Varnish. So by default, Varnish uses 5 threads per thread pool. By default, that&#8217;s 10 threads minimum. The maximum is far higher, but in reality, threads are fairly cheap. If you expect to handle 500 concurrent requests, tune Varnish for that.</p>
<p>A little clarification on the thread-parameters: thread_pool_min is the minimum number of threads <em>for each thread pool.</em> thread_pool_max is the maximum <em>total number of threads.</em> That means the values are not on the same scale. The thread_pools parameter can safely be ignored (tests have indicated that it doesn&#8217;t matter as much as we thought), but ideally having one thread_pool for each cpu core is the rule of thumb, if you want to modify it.</p>
<p>You also do not want more than 5000 as the thread_pool_max. It&#8217;s dangerous, though fixed in trunk. It&#8217;s also more often than not an indication that something else is wrong. If you find yourself using 5000 threads, the solution is to find out why it&#8217;s happening, not to increase the number of threads.</p>
<p>To reduce the startup time, you also want to reduce the thread_pool_add_delay parameter. &#8216;2&#8242; is a good value (as opposed to 20 which makes for a slow start).</p>
<h2>4. Tune based on necessity</h2>
<p>I often look at sites where someone has tried to tune Varnish to get the most out of it, but taken it a bit too far. After working with Varnish I&#8217;ve realized that you do not really need to tune Varnish much: The defaults are tuned. The only real exception I&#8217;ve found to this is number of threads and possibly work spaces.</p>
<p>Varnish is &#8211; by default &#8211; tuned for high performance on the vast majority of real-life production sites. And it scales well, in most directions. By default. Do yourself a favor and don&#8217;t fix a problem which isn&#8217;t there. Of all the issues I&#8217;ve dealt with on Varnish, the vast majority have been related to finding out the real problem and either using Varnish to work around it, or fix it on the related system. Off the top of my head, I can really only remember one or two cases where Varnish itself has been the problem with regards to performance.</p>
<p>To be more specific:</p>
<ul>
<li>Do not modify lru_interval. I often see the value &#8220;3600&#8243;. Which is a 180 000% (one hundred and eighty thousand percent) increase from the default. This is downright dangerous if you suddenly need the lru-list, and so far my tests haven&#8217;t been able to prove any noticeable performance improvement.</li>
<li>Setting sess_timeout to a higher value increase your filedescriptor consumption. There&#8217;s little to gain by doing it too. You risk running out of file descriptors. At least until we can get the fix into a released version.</li>
</ul>
<p>So the rule of thumb is: Adjust your threads, then leave the rest until you see a reason to change it.</p>
<h2>5. Pay attention to work spaces</h2>
<p>To avoid locking, Varnish allocates a chump of memory to each thread, session and object. While keeping the object workspace small is a good thing to reduce the memory footprint (this has been improved vastly in trunk), sometimes the session workspace is a bit too small, specially when ESI is in use. The default sess_workspace is 16kB, but I know we have customers running with 5MB sess_workspace without trouble. We&#8217;re obviously looking to fix this, but so far it seems that having some extra sess_workspace isn&#8217;t that bad. The way to tell is by asserts (unfortunately), typically something related to &#8220;(p != NULL) Condition not true&#8221; (though there can obviously be other reasons for that). Look for it in our bug report, then try to increase the session workspace.</p>
<h2>6. Keep your VCL simple</h2>
<p>Most of your VCL-work should be focused around vcl_recv and vcl_fetch. That&#8217;s where you define the majority of your caching policies. If that&#8217;s where you do your work, you&#8217;re fairly safe.</p>
<p>If you want to add extra headers, do it in vcl_deliver. <em>Adding a header in vcl_hit is not safe. </em>You can use the &#8220;obj.hits&#8221; variable in vcl_deliver to determine if it was a cache hit or not.</p>
<p>You should also review the default vcl, and if you can, let Varnish fall through to it. When you define your VCL, Varnish appends the default VCL, but if you terminate a function, the default is never run. This is an important detail in vcl_recv, where requests with cookies or Authroization-headers are passed if present. That&#8217;s far safer than forcing a lookup. The default vcl_recv code also ensures that only GET and HEAD-requests go through the cache.</p>
<p>Focus on caching policy and remember that the default VCL is appended to your own VCL &#8211; and use it.</p>
<h2>7. Choosing storage backend (malloc or file?)</h2>
<p>If you can contain your cache in memory, use malloc. If you have 32GB of physical memory, using -smalloc,30G is a good choice. The size you specify is for the cache, and does not include session workspace and such, that&#8217;s why you don&#8217;t want to specify -smalloc,32G on a 32GB-system.</p>
<p>If you can not contain your cache in memory, first consider if you really need that big of a cache. Then consider buying more memory. Then sleep on it. Then, if you still think you need to use disk, use -sfile. On Linux, -sfile performs far better than -smalloc once you start hitting disk. We&#8217;re talking pie-chart-material. You should also make sure the filesystem is mounted with noatime, though it shouldn&#8217;t be necessary. On Linux, my cold-hit tests (a cold hit being a cache hit that has to be read from disk, as opposed to a hot hit which is read from memory) take about 6000 seconds to run on -smalloc, while it takes 4000 seconds on -sfile with the same hardware.  Consistently. However, your milage may vary with things such as kernel version, so test both anyway. My tests are easy enough: Run httperf through x-thousand urls in order. Then do it again in the same order.</p>
<p>Some of the most challenging setups we work with are disk-intensive setups, so try to avoid it. SSD is a relatively cheap way to buy yourself out of disk-issues though.</p>
<h2>8. Use packages and supplied scripts</h2>
<p>While it may seem easier to just write your own script and/or install from source, it rarely pays off in the long run. Varnish usually run on machines where downtime has to be planned, and you don&#8217;t want a surprise when you upgrade it. Nor do you want to risk missing that little bug we realized was a problem on your distro but not others. If you do insist on running home-brew, make sure you at least get the ulimit-commands from the startup scripts.</p>
<p>This is really something you want regardless of what sort of software you run, though.</p>
<h2>9. Firewall and sysctl-tuning</h2>
<p>Do <span style="text-decoration: underline">not</span> set &#8220;tw_reuse&#8221; to 1 (sysctl). It will work perfectly fine for everyone. Except thousands of people behind various NAT-based firewalls. And it&#8217;s a pain to track down. Unfortunately, this has been an advice in the past.</p>
<p>Avoid connection-tracking on the Varnish server too. If you need it, you&#8217;ll need to tune it for high performance, but the best approach is simply to not do connection-tracking on a server with potentially thousands of new connections per second.</p>
<h2>10. Service agreements</h2>
<p><span>(Service agreements are partly responsible for my salary, so with that &#8220;conflict of interest&#8221; in mind&#8230;.)</span></p>
<p>You do not need a service agreement to run Varnish. It&#8217;s free software.</p>
<p>However, if you intend to run Varnish and your site is business critical, it&#8217;s sound financial advice to invest some money in it. We are the best at finding potential problems with your Varnish-setup before they occur, and solving them fast when they do occur.</p>
<p>We typically start out by doing a quick sanity-test of your configuration. This is something we can do fast, both with regards to parameters, VCL and system configuration. Some of our customers only contact us when there&#8217;s something horribly wrong, others more frequently to sanity-check their plans or check up on how to use varnisncsa for their particular logging tool and so on. It&#8217;s all up to you.</p>
<p>We also have a public bug tracker anyone can access and submit to. We do not have a private bug tracker, though there are bugs that never hit the public bug tracker &#8211; but that&#8217;s because we fix them immediately. Just like any other free software project, really. We have several public mailing lists, and we answer them to the best of our ability, but there is no guarantee and our time is far more limited. If you run into a bug, my work on other bugs will be postponed until your problems are solved. Better yet: if you run into something you don&#8217;t know is a bug, we can track it down.</p>
<p>A service agreement gives you saftey. And your needs will get priority when we decide where we want to take Varnish in the future.</p>
<p>We also offer training on Varnish, if you prefer not to rely on outside competence.</p>
<p>Oh, and I get to eat. Yum.</p>
<h2>Summary</h2>
<p>Keep it simple and clean. Do not use connection tracking or tw_reuse. Try to fit your cache into memory on a 64-bit system.</p>
<p>Watch your logs.</p>
<p>Parameters:</p>
<blockquote>
<pre>thread_pool_add_delay=2
thread_pools = &lt;Number of cpu cores&gt;
thread_pool_min = &lt;800/number of cpu cores&gt;
thread_pool_max = 4000
session_linger = 50
sess_workspace = &lt;16k to 5m&gt;</pre>
</blockquote>
<p>So if you have a dual quad core CPU, you would have 8 cpu cores. This would make sense: thread_pools=8, thread_pool_min=100, thread_pool_max=4000. The number 800 is semi random: it seems to cover most use-cases. I addedd session_linger into the mix because it&#8217;s a default in Varnish 2.0.5 and 2.0.6 but not in prior versions, and it makes good sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/01/26/varnish-best-practices/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Real-time and hit-and-run based statistics for VSTS</title>
		<link>http://kristian.blog.linpro.no/2010/01/19/real-time-and-hit-and-run-based-statistics-for-vsts/</link>
		<comments>http://kristian.blog.linpro.no/2010/01/19/real-time-and-hit-and-run-based-statistics-for-vsts/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 13:18:37 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[Varnish]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[rrd]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[vsts]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=137</guid>
		<description><![CDATA[A while ago I wrote VSTS &#8211; the Varnish Stress Testing Suite. It&#8217;s not nearly as fancy as the name makes it sound: It&#8217;s a simple set of shell scripts that runs on a set of test servers and pounds Varnish under a couple of different scenarios. The idea is simple: Detect possible performance issues [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote VSTS &#8211; the Varnish Stress Testing Suite. It&#8217;s not nearly as fancy as the name makes it sound: It&#8217;s a simple set of shell scripts that runs on a set of test servers and pounds Varnish under a couple of different scenarios. The idea is simple: Detect possible performance issues during the development cycle of Varnish by periodically testing the current code against the same well-established test.</p>
<p>It does the job, but could be far better. Specially when it comes to statistics.</p>
<p>The rrdtool-backed Python script is simply insufficient. As rrdtool likes to put data entry into a time-slot, and I don&#8217;t really operate in time slots, the data is both slow and imprecise. This is fine if you want data for every 5 minute throughout a year, but not if you want data collected anwhere from one time to ten times a day. Simply put: I want one data entry to represent one unit on the X-scale.</p>
<p>I also want to add &#8220;real-time&#8221; statistics. The current data is collected after each test, but I want data to be gathered throughout the relevant tests. This should be seperate from the other statistics. Hopefully, the system I end up with is flexible enough to allow me to plot all the datasets on the same graph, which should make any variations easy to spot.</p>
<p>Up until now I&#8217;ve only ever dealt with rrdtool when it comes to statistics (unless you count pre-rrdtool mrtg and the like), so I was hoping for some pointers before I start digging through what I suspect is a jungle of similar but different solutions. I&#8217;m comfortable working with most languages, and the primary concerns I&#8217;m looking at is implementation complexity and flexibility.</p>
<p>When I&#8217;m done with this batch of refactoring, I&#8217;ll do a proper writeup. However, what I&#8217;m most excited about is adding OpenSolaris into the target-platforms (should help clean out a few bugs that have been plaguing the Solaris-users for a while), adding better support for customized tests and improved robustness of VSTS.</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/01/19/real-time-and-hit-and-run-based-statistics-for-vsts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pushing Varnish even further</title>
		<link>http://kristian.blog.linpro.no/2010/01/13/pushing-varnish-even-further/</link>
		<comments>http://kristian.blog.linpro.no/2010/01/13/pushing-varnish-even-further/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 20:33:46 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[Varnish]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=88</guid>
		<description><![CDATA[A while ago I did a little writeup on high-end Varnish tuning, where I noted that I made our single core 2.2GHz Opteron reach 27k requests/second. This begged the questions as to how well Varnish scale with hardware. So I went ahead and tried to overload our quad-core Xeon at 2.4GHz. It would obviously take [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I did a little writeup on <a href="http://kristian.blog.linpro.no/2009/10/19/high-end-varnish-tuning/">high-end Varnish tuning</a>, where I noted that I made our single core 2.2GHz Opteron reach 27k requests/second. This begged the questions as to how well Varnish scale with hardware. So I went ahead and tried to overload our quad-core Xeon at 2.4GHz. It would obviously take some extra fire power. At the very least, four times as much as the last batch of tests.</p>
<h1>Hardware involved</h1>
<p>Our main set of test servers for Varnish are called varnish1, varnish2, varnish3, varnish4, varnish6 and varnish7. These have mostly different software and hardware &#8211; which is done intentionally so we can perform tests under different circuimstances. We routinely run tests against Varnish2 and Varnish4, which run CentOS and FreeBSD, respectively. For my last test, I used Varnish2 as the server and the remaining servers as test nodes. By any normal math, I would need  about 4 times more fire power to overload a 2.4GHz Quad core, compared to a single core Opteron at 2.2GHz.</p>
<p>To sum it up as far as this round of tests go:</p>
<ul>
<li>Varnish1 &#8211; Single core Opteron</li>
<li>Varnish2 &#8211; Single core Opteron at 2.2GHz (used in the last round of tests)</li>
<li>Varnish3 &#8211; Single core Xeon (if I&#8217;m not much mistaken). It&#8217;s also the nginx server used as backend, but that just means 1 request every X minutes.</li>
<li>Varnish4 &#8211; Single core Opteron (FreeBSD)</li>
<li>Varnish6 &#8211; Dual core Xeon of some kind</li>
<li>Varnish7 &#8211; Quad-core Xeon at 2.4GHz</li>
</ul>
<p>So I needed more power. As it happens, we do alot of training and we have three classrooms full of computers for students, and I borrowed two of these class rooms, adding the following to the mix:</p>
<ul>
<li>10 x single core Pentium Celerons at 2.9x GHz</li>
<li>10 x Core 2 Duos at 2.4ish GHz</li>
</ul>
<p>As you might notice &#8211; a large part of the challenge when you want to test <em>Varnish</em> is getting your test systems to keep up.</p>
<h1>Basic test procedures</h1>
<p>Same as last time, more or less: 1 byte pages and httperf. I&#8217;ve tried ab, siege and curl&#8230; And they simply do not offer the raw power of httperf combined with the control &#8211; if anyone cares to enlighten me on how to get the most out of them, then I&#8217;m more than willing to listen.</p>
<p>Ideally I wanted to test with 10 requests for each connection, and with mixed data set size. As it turns out, I ended up using 100 requests / second and bursting all of the requests, which is far from realistic. More on this later.</p>
<p>I have an intricate script system for the nightly tests, but that&#8217;s a story for an other time. For these tests I simply used clusterssh to replicate my input on 37ish shells. This has allowed me to instantly test identical setups on all the nodes, and to quickly review what their status is. I probably ran a thousand or more different variants of the same test this time around.</p>
<p>I&#8217;ve used varnishstat to monitor the request rate and other relevant stats, and top to monitor general load.</p>
<p>The backend I use is hosted on varnish3, which runs nginx and a simple rewrite to &#8216;current.txt&#8217;, which for this occasion was linked to a 1byte file.</p>
<h1>Results</h1>
<p>Varnish uses alot of threads, and as such, when it does finally saturate the CPU, the load average will skyrocket. On the last test, Varnish2 had a load of 600-700. During this load, Varnish2 would use 10-15 seconds to start &#8216;top&#8217;.</p>
<p>During this round of tests I had roughly 87GHz worth of clients, spread over 25 physical computers. All of the tests systems were running at full load. Varnish7 had a load average around 45. Logging in and starting top was close to instant. And Varnish was serving 143k requests per second.</p>
<p>Based on the load and general snappiness, I think it is safe to conclude that while Varnish was close to the breaking point, it hadn&#8217;t actually reached it. To put it simply: My clients were not fast enough. Before I told httperf to burst 100 requests for each connection, Varnish was serving 110-120k requests per second with a load less than 1.0, and the clients were still using all their fire power. I ended up stress testing my clients. Dammit.</p>
<p>However, as I came fairly close to the breaking point, I still believe there are a few interesting things to look at.</p>
<h1>The scaling nature of Varnish</h1>
<p>It&#8217;s very rare that you can see an application scale so well just by throwing cpu power and cpu cores at it. Varnish essentially didn&#8217;t get affected at all by the extra work needed to synchronize work on 4 cpu cores. In fact, if you look at the math, the raw performance on 4 cpu cores was actually BETTER than on one cpu core, when you look at it on a cycle-by-cycle.</p>
<p>I think it&#8217;s reasonably safe to say that when it comes to raw performance, we&#8217;ve nailed it with Varnish.</p>
<p>In fact, scaling Varnish is far more difficult when you increase your active data set beyond physical memory. Or when you introduce latency. Or when when you have a low cache hit rate. Or any other number of corner cases. There will always be bottlenecks.</p>
<p>What you can learn from this is actually simple: Do not focus on the CPU when you want to scale your Varnish setup. I know it&#8217;s tempting to buy the biggest baddest server around for a high-traffic site, but if your active data set can fit within physical memory and you have a 64-bit CPU, Varnish will thrive. And for the record: All CPU-usage graphs I&#8217;ve seen from Varnish installations confirm this. Most of the time, those sexy CPUs are just sitting idle regardless of traffic.</p>
<h1>Myths and further research</h1>
<p>Since I didn&#8217;t reach the breaking point, there&#8217;s not much I can say conclusively. However, I can repeat a few points.</p>
<p>Adjusting the lru_interval had little impact regardless of data set and access patterns. If I repeat this often enough, perhaps I&#8217;ll stop seeing new installations with an lru_interval of 3600: DO NOT SET lru_interval TO 3600. There. I didn&#8217;t even add the usual &#8220;unless you know what you are doing&#8221; part. I might&#8217;ve explained it before, but the problem is that it leaves you with a really badly sorted lru-listed that will cause Bad Things once you need to lru-nuke something. Possibly really really bad things. Like throwing out the 200 most popular objects on your site at the same time.</p>
<p>And the size of your VCL has little impact on the performance. I have not tested this extensively, but I&#8217;ve never registered a difference, and since your cpu will be idle most of the time anyway, you should NOT worry about CPU cycles in VCL.</p>
<p>An otherimportant detail is that your shmlog shouldn&#8217;t trigger disk activity. On my setup, it didn&#8217;t sync to disk to begin with, but you may want to stick it on a tmpfs just to be sure. I suspect this has improved throughout the 2.0-series of Varnish, but it&#8217;s an easy insurance. Typically the shmlog is found in /usr/var/varnish, /usr/local/var/varnish or similar (&#8221;ls /proc/*/fd | grep _.vsl&#8221; is the lazy way to find it).</p>
<p>I tried several different settings of thread pools, acceptors, listen depth, shmlog parameters, rush exponent and such, but none of it revealed much &#8211; most likely because I never pressured Varnish enough. This will be what I want to investigate further. But it should tell you something about how far you have to go before these obscure settings start to matter.</p>
<h1>Feedback wanted</h1>
<p>I figure this must be some sort of record, but I&#8217;m interested in what sort of numbers others have seen or are seeing. Have anyone even come close to the numbers above &#8211; synthetic or otherwise &#8211; from a single server? Regardless of software or hardware? This is not meant as a challenge or boast, but I&#8217;m genuinely curious on what sort of traffic people are able to push. I&#8217;m interested in more &#8220;normal&#8221; requests rates too &#8211; I&#8217;m a sucker for numbers. What are you seeing on your site? Have you had scaling issues?</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/01/13/pushing-varnish-even-further/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Hitpass objects and Varnish</title>
		<link>http://kristian.blog.linpro.no/2010/01/08/hitpass-objects-and-varnish/</link>
		<comments>http://kristian.blog.linpro.no/2010/01/08/hitpass-objects-and-varnish/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 09:39:22 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[Varnish]]></category>
		<category><![CDATA[educational]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=118</guid>
		<description><![CDATA[Yesterday presented an interesting case of &#8220;what the hey is going on!?&#8221; for a customer of ours. The problem presented itself as a front page that sporadically needed 40 to 50 seconds to purge. After a brief hunt I discovered a somewhat interesting set of coincidences.
Before I go into detail, I need to tell you [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday presented an interesting case of &#8220;what the hey is going on!?&#8221; for a customer of ours. The problem presented itself as a front page that sporadically needed 40 to 50 seconds to purge. After a brief hunt I discovered a somewhat interesting set of coincidences.</p>
<p>Before I go into detail, I need to tell you what a hitpass object is and why it&#8217;s needed.</p>
<p>Varnish can pass objects &#8211; that is to say, deliver an object without storing it in the cache &#8211; at two different stages in the request handling. The first and simplest stage you can pass at is before you have contacted the web server. This can be because you know that every page under a specific url should not be cached, or that a cookie is present and needed. This is done in vcl_recv. The slightly more complex stage to  purge at is after Varnish has gotten a reply from the backend, typically because it sent a &#8220;Set-Cookie&#8221; header or otherwise had headers that indicate that the page isn&#8217;t cacheable. This is done in vcl_fetch.</p>
<p>Normally Varnish tries to only request a specific object once, since it will look the same to all users there is no reason to make the web server generate it multiple times, and it&#8217;s definitely not faster either. When you are passing an object, every client request has to go to the web server, so serializing the requests for the same url is not wanted.</p>
<p>If you pass in recv, it&#8217;s easy for Varnish to avoid this serialization . It already knows that the next request for the same URL will have to go to the backend. Varnish makes an &#8220;anonymous&#8221; object that is never entered into the cache. A very simple and effective design.</p>
<p>But in vcl_fetch, things are not so easy. Varnish can&#8217;t predict a pass in vcl_fetch ahead of time, so it has to serialize these requests as if it was being cached. This is obviously not a desirable situation. Enter the hitpass object.</p>
<p>To avoid serialized requests after a pass in vcl_fetch, Varnish makes a hitpass object which is entered into the cache for &#8216;obj.ttl&#8217; period of time, which simply says that this url will be passed for the next obj.ttl period of time. This looks almost just like a normal object in the cache, but it has no content, just a flag telling Varnish to fetch it from a backend. And thus Varnish can perform parallel requests again, because it knows the request will not be cached before it contacts the web server. The moment Varnish sees a hitpass object, it will dereference (and thus unlock) the hitpass object and make an anonymous one, entering the same code-path as if it was a pass in vcl_recv.</p>
<p>Now, back to my original story and purging. What&#8217;s it got to do with hitpass objects? Well, the purges on this particular site is done in vcl_hit/vcl_miss by resetting ttl to 0, effectively expiring the object. The problem was that at some point, a header on the relevant front page had told Varnish not to cache. So a hitpass object was made, and it had a ttl of roughly 4 days. So the VCL never hit vcl_hit or vcl_miss &#8211; where the purging was being done &#8211; but instead went to vcl_pass and directly to the backend, which kindly generated the page even though it just got a PURGE request, which is a bit strange, but not all that strange. What&#8217;s worse, of course, is that the front page wasn&#8217;t cached at all for this period of time. As it turns out, Varnish also has a minor issue which I also discovered yesterday, in that it doesn&#8217;t actually purge hitpass objects correctly, at least not in this particular version of Varnish.</p>
<p>And if you are thinking &#8220;why not set the ttl to 0 in vcl_pass if you see a PURGE?&#8221;, even if we allowed you to modify obj.ttl in vcl_pass, it wouldn&#8217;t be the ttl of the hitpass object, but the anonymous object. This is also why you can&#8217;t simply decide to start caching it again &#8211; when you reach vcl_fetch after hitting a hitpass object, the object you are working on is anonymous, and never entered into the cache.</p>
<p>My solution? Add an &#8216;x&#8217; to the cache hash for the particular url/host combination for an immediate &#8220;fix&#8221;. It was either that or restarting Varnish at peak hour. Oh, and add some sanity to the VCL to reduce the effect of this in the future.</p>
<h2>Recommendations</h2>
<p>Understand hitpass objects. If you are doing &#8216;pass&#8217; in vcl_fetch, remember that the TTL matters. You may want to switch &#8216;pass&#8217; in vcl_fetch with your own pass subroutine which just sets the ttl to 1 minute for instance, and use that function consistently. That way, you avoid long-lived hitpass objects, but still get the benefit of them when you want them.</p>
<p>Also: If you are using the artificial http &#8220;PURGE&#8221;-method to set ttl to zero in vcl_hit, don&#8217;t forget to check for it in vcl_pass. You probably want to throw a 503-error in vcl_pass if you see a PURGE request.</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/01/08/hitpass-objects-and-varnish/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The problem with piracy</title>
		<link>http://kristian.blog.linpro.no/2010/01/04/107/</link>
		<comments>http://kristian.blog.linpro.no/2010/01/04/107/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 23:27:04 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[/dev/random]]></category>
		<category><![CDATA[drm]]></category>
		<category><![CDATA[file sharing]]></category>
		<category><![CDATA[political]]></category>
		<category><![CDATA[ranting]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=107</guid>
		<description><![CDATA[If you are paying attention to the news, you will be aware of the rising piracy-problem. International authoroties have tried desperately to stop the piracy, but so far little has helped. It has had large economic impacts, both in stolen goods and in the cost of the war on piracy.
As it turns out, the core [...]]]></description>
			<content:encoded><![CDATA[<p>If you are paying attention to the news, you will be aware of the rising piracy-problem. International authoroties have tried desperately to stop the piracy, but so far little has helped. It has had large economic impacts, both in stolen goods and in the cost of the war on piracy.</p>
<p>As it turns out, the core of the prolem lies in the nature of the piracy: Piracy is taking place because the people feel that there is little to loose. The environment in which the piracy takes place is one where the pirates and the community around them is constantly bullied and given little hope of improvement. The situation has only gotten worse over the years, and the efforts to stop the piracy is ultimately focused on enforcing the existing laws instead of solving the problems of the society. And while authoroties might be able to quench the piracy, it comes at a cost too: The society is again left to improve itself without any help real from the outside because the rest of the world is happy with the situation as it is and doesn&#8217;t want to stir things up.</p>
<p>For those who haven&#8217;t been paying attention to the news, I&#8217;m talking about Somalia, a country that was ranked 161st on UNs list of roughly 180 countries based on it&#8217;s &#8220;human development index&#8221;. That is, the last time it was included in the ranking, which was in 2001.</p>
<p>So called illegal file sharing and the war on sharing has many similarities with the story above. Beyond the obvious, there&#8217;s insistance on calling both pirates and file sharers for immoral outcasts of society that only prey on their surroundings and doesn&#8217;t give anything back. If it could be linked to terrorists; even better. And yes, according to the propaganda-movie at the end of my &#8220;House MD&#8221; dvd, file sharing funds terrorism. I&#8217;m not entirely sure how, but hey, I bet it&#8217;s a good argument. The reality is &#8211; of course &#8211; different. It also states that it costs jobs&#8230;. well&#8230; isn&#8217;t that a GOOD thing for me? I don&#8217;t want to pay a bunch of guys for sitting around doing nothing. The distribution networks of today is terribly inefficient. The concept of being &#8220;out of stock&#8221; should&#8217;ve gone away with the invention of the DVD. And the idea that it costs jobs is also strange, because all the propaganda-makers and lawyers wouldn&#8217;t have jobs if it wasn&#8217;t for the war on sharing.</p>
<p>There is one big difference: Piracy is carried out by means of violence. Pirates steal actual goods. File sharing doesn&#8217;t actually have any material costs, nor is it by any conclusive and through research possible to say that it even reduces sales. In fact, I&#8217;m sure I&#8217;m not the only one who suspect that file sharing increases sales. I own over 350 dvds and blueray movies now. I bought several of them after I had seen them. Why? Two reasons: 1. Because it&#8217;s right. 2. Because I liked the movie.</p>
<p>An other difference is that the somali pirates struggle to improve the conditions of a geographicly limited society, whereas file sharers operate in a global society. All in all it&#8217;s not that different, though: File sherers don&#8217;t get any real out-side help either, and are always on the defensive, regardless of how they &#8220;fight&#8221;. It is hard for outsiders to understand the society that the pirates live in, just as it&#8217;s hard for someone who wasn&#8217;t brought up in the digital age to understand how wrong the war against file sharing feels.</p>
<p>I do not condone piracy. But I can understand why it&#8217;s taking place and I belive it&#8217;s extermely cynical to use brute force to stop it without any hint of a public debate as to the soiciological conditions that allowed it in the first place. In the same way that I don&#8217;t like the idea of breaching copyrights through illegal file sharing, but I think it&#8217;s extermely cynical &#8211; and naive &#8211; to think that the real problem can be stopped by means of authority, laws and technology created to maintain the status quo in an ever-changing global class struggle.</p>
<p>It&#8217;s also very hard to talk openly about illegal file sharing: Admitting the act is difficult because it&#8217;s illegal. So who&#8217;s to speak for the file sharers? What we need, is asylum for file sharers to enable a proper public debate&#8230;.. But that&#8217;ll never happen.</p>
<p>Oh, and let&#8217;s quit calling it &#8220;piracy&#8221; when we mean one of or all of:</p>
<ul>
<li>Copying a movie to your friend</li>
<li>Sharing a movie to strangers on the internet</li>
<li>Buying an obviously illegaly copied movie on the streets of some foreign country (this you should never do &#8211; ever. Get it on the net instead, since this really is for-profit crime)</li>
<li>Downloading a movie or series off the net because it&#8217;s not available where you live.</li>
</ul>
<p>In the end, this is what I want:</p>
<ul>
<li>Movies and music</li>
<li>The ability to pay for said movies and music</li>
<li>Market models designed around current technology</li>
<li>NOT technology designed around and designed to enforce the current market model (ie: DRM)</li>
<li>Freedom</li>
<li>Fairness</li>
</ul>
<p>If you can sell 100 copies of the same movies for one tenth of the price you could sell ten movies for (distribution costs included) then why not do it? That&#8217;s what copyright is for: Enabling the public to get access to professional copyrighted works. It is not to protect the thoughts of the copyright holder. You have a skull to protect your intellectual property, and we have laws against bashing your skull in. And if you need technology to protect your intellectual property, then wear a god damned helmet. In the mean time, I don&#8217;t use hemlets to protect from robbers, so don&#8217;t force a helmet onto my blyeray disc movies.</p>
<p>I could go on and on with this rhetoric and endless digressions to underline the point&#8230; But what&#8217;s the point&#8230;. Money talks, after all, but not my money, it seems.</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2010/01/04/107/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Varnishstat for dummies</title>
		<link>http://kristian.blog.linpro.no/2009/12/08/varnishstat-for-dummies/</link>
		<comments>http://kristian.blog.linpro.no/2009/12/08/varnishstat-for-dummies/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 13:16:51 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[/dev/random]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[Varnish]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=91</guid>
		<description><![CDATA[Varnishstat is the tool used to monitor the basic health of Varnish. Unlike all the other tools, it doesn't read log entries, but counters that Varnish update in real-time. It can be used to determine your request rate, memory usage, thread usage, and just about anything that's not related to a specific request. As such, it's nice to know how to work with it. Below is a rough introduction.]]></description>
			<content:encoded><![CDATA[<p>Varnishstat is the tool used to monitor the basic health of Varnish. Unlike all the other tools, it doesn&#8217;t read log entries, but counters that Varnish update in real-time. It can be used to determine your request rate, memory usage, thread usage, and just about anything that&#8217;s not related to a specific request. As such, it&#8217;s nice to know how to work with it. Below is a rough introduction.</p>
<h1>Reading varnishstat</h1>
<p>In it&#8217;s simplest form, varnishstat is run with: «varnishstat». It will look something like this, depending on your terminal size:</p>
<p><img src="http://users.linpro.no/~kristian/varnish/varnishstat3.png" alt="" /></p>
<p>I&#8217;ve added the red text, in case you didn&#8217;t already guess that.</p>
<p>The uptime here is 5 days, 7 hours, 36 minutes. The server name is the hostname by default, or what you specify with the -n argument to varnishd (and varnishstat).</p>
<p>While running varnishstat, you will see the three numbers right of &#8220;Hitrate ratio:&#8221; increase from 0 to 10, 100 and 1000 respectively. They are simple indicators for the numbers in the &#8220;Hitrate avg:&#8221; listing below. In the picture above, we can see that during the last 10 seconds, the hitrate average was 0.9671, during the last 100 seconds, it was 0.9687, and during the last 131 seconds, it was 0.9688. The actual numbers in hitrage average is how many cache hits you have, compared to cache misses. Keep in mind that &#8220;pass&#8221; in vcl_recv is not a cache miss, so you can have a hitrate average of 1.0, and still see backend requests. For puny mortals, you typically multiple the number with 100 and pronounce it as percentage. (Ie: 96.71%, 96.87% and 96.88%).</p>
<p>The rest of the output is a list of all counters. In Varnish 2.0.5 (and 2.0.4, possibly 2.0.3?), an interactive varnishstat <strong>only prints numbers that are different from zero. </strong>This is a futile attempt to display as much information as possible, as the varnishstat I have on my laptop currently has 98 counters.</p>
<p>The first column is the raw data of the counter. In case of cache hits, for instance, this is the total number of cache hits since Varnish was started.</p>
<p>The second column is the change per second in realtime. So on the image above, the server is handling 1546 requests per second. The next column is the average change per second since Varnish started. So during the past 5+ days, this server has handled 925 requests per second in average.</p>
<p>You will notice that some counters do not have the &#8220;per second&#8221; columns. These are counters that can decrease. Number of objects, for instance, will go both up and down, so the value of a change/second is small, since it doesn&#8217;t really tell you much.</p>
<h1>Some values to care about</h1>
<p><span style="color: #888888">(Assuming you are the caring, loving type)</span></p>
<ul>
<li><span style="background-color: #ffffff">Client connections accepted (per second).</span></li>
<li><span style="background-color: #ffffff">Client requests received. Experience shows that a ratio close to 1:10 between connections and requests is natural on web sites. If it&#8217;s far below or far above that &#8211; investigate.</span></li>
<li><span style="background-color: #ffffff">Backend connections failures &#8211; Should be low, obviously. This typically results in 503-errors. Are your backends struggling?</span></li>
<li><span style="background-color: #ffffff">N struct object &#8211; number of cached objects.</span></li>
<li><span style="background-color: #ffffff">N worker threads &#8211; how many threads you have right now</span></li>
<li><span style="background-color: #ffffff">N worker threads created &#8211; how many threads have been created (should be close to the number you are running now)</span></li>
<li><span style="background-color: #ffffff">N worker threads not created &#8211; ZERO &#8211; Threads that Varnish tried to created but failed (should never happen)</span></li>
<li><span style="background-color: #ffffff">N worker threads limited &#8211; reasonably low after startup &#8211; Number of threads varnish wanted to created, but wasn&#8217;t able to either because of max threads or the thread_pool_add_delay.</span></li>
<li><span style="background-color: #ffffff">N overflowed work requests &#8211; requests that had to be put on the request queue. should be fairly static after startup.</span></li>
<li><span style="background-color: #ffffff">N dropped work requests. Requests Varnish never got to respond to because the request queue was full. Should ideally never happen.</span></li>
<li><span style="background-color: #ffffff">N LRU nuked objects &#8211; Objects thrown out to make room for others. If this is zero, there&#8217;s no point to make your cache larger.</span></li>
<li><span style="background-color: #ffffff">esi_parse and esi_errors &#8211; ESI parsed pages and ESI pages parsed with errors, respectively. Only relevant if you use ESI.</span></li>
<li><span style="background-color: #ffffff">n_expired &#8211; Objects expired (ttl reached 0 (or was set to 0) and grace too). </span></li>
</ul>
<p>There are obviously more variables that might be of interest, but the list above is a good place to start and should give you a general idea of the state Varnish is in.</p>
<h1>Other uses</h1>
<ul>
<li><span style="background-color: #ffffff">To list all stats, use «varnishstat -1». This will list everything once.</span></li>
<li><span style="background-color: #ffffff">To list just a few values: use «varnishstat -l»to find the name for the field, then «varnishtat -f field1,field2,field3»</span></li>
<li><span style="background-color: #ffffff">Use munin to graph the data into related blocks.</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2009/12/08/varnishstat-for-dummies/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>High-end Varnish-tuning</title>
		<link>http://kristian.blog.linpro.no/2009/10/19/high-end-varnish-tuning/</link>
		<comments>http://kristian.blog.linpro.no/2009/10/19/high-end-varnish-tuning/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 11:19:29 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[Varnish]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=75</guid>
		<description><![CDATA[Most of the time when I tune varnish servers, the main problem is hit rate. That&#8217;s mostly a matter wack the weasel, and fairly straight forward. However, once you go beyond that, things get fun. I&#8217;ll take you through a few common tuning tricks. This is also based on no disk I/O too, so either [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time when I tune varnish servers, the main problem is hit rate. That&#8217;s mostly a matter wack the weasel, and fairly straight forward. However, once you go beyond that, things get fun. I&#8217;ll take you through a few common tuning tricks. This is also based on no disk I/O too, so either sort that out first or expect different results.</p>
<h1>The big ones</h1>
<p>The first thing you want to do is sort your threads out. One thread pool for each CPU core. Never run with less than, say, 800 threads. If you think that&#8217;s alot, then you don&#8217;t need these tips. For max, I don&#8217;t advice going over 6000, I&#8217;ll explain that shortly. So if you have 8 cpu cores, you will want to set:</p>
<blockquote>
<pre>thread_pools 8</pre>
<pre>thread_pool_min 100</pre>
<pre>thread_pool_max 5000</pre>
<pre>thread_pool_add_delay 2</pre>
</blockquote>
<p>Note that I also set the thread_pool_add_delay to 2ms. That should drastically reduce the startup time for your threads, and is fairly safe. The reason we don&#8217;t create everything instantly is to avoid bombing the kernel.</p>
<p>The main danger with threads &#8211; if we rule out I/O &#8211; is file descriptors. Currently the log format we use have a 16 bit field reserved for file descriptors, which I believe is fixed in trunk, but that limits us to 64k file descriptors. And your kernel will clean them up periodically, so running out is very very relevant, and please keep in mind that synthetic tests are horrible at testing this. You can probably use 40 000 threads in a synthetic test without running into file descriptor issues, but do not use that in production. 6000 might be high, and unless you really really really need it, I wouldn&#8217;t go beyond 2000 or 3000. I&#8217;ve done quite a bit of testing and tried out different options on production sites, and have found that 800 is a sane minimum, and I&#8217;ve rarely seen max threads be an issue until you hit the fd-limit. You can watch /proc/<em>&lt;PID of varnish child&gt;</em>/fd/ to see how many fds varnish have allocated at any given time.</p>
<p>The next issue you are likely to run in to is cli_timeout. If your varnish is heavily loaded, it might not answer the management thread in a timely fashion, which in turn will kill it off. To avoid that, set cli_timeout to 20 seconds or more. Yes, 20. That&#8217;s the extreme, but I have gradually increased this over months of  routine tests. I&#8217;m currently running these tests with a cli_timeout of  25 seconds, which so far has worked. 23 worked until today. For most sites and most real work loads, I doubt this is necessary, but if it is and you actually hit this in production, your Varnish will restart when it&#8217;s most bussy &#8211; which is probably the worst possible scenario you have. Set it to at least 10-15 seconds (we increased the default to 10 seconds a while ago. It&#8217;s a sane compromise, but a tad low for an overloaded Varnish)</p>
<p>Last but not least of the common tricks is a well kept seceret; session_linger.  When you have a bunch of threads and Varnish become CPU-bound, you are likely to get killed by context switching and whatnot. To reduce this, setting session_linger can help. You may have to experiment a bit, as it depends on your content. I recently had to set it to 120ms to get it to really do the trick. The site load would climb to 60k req/s then crumble to a measly 2-5k req/s during tests. Session linger did the trick. However, don&#8217;t set it too high. That will leave your threads idling.</p>
<p>Session_linger has been improved in trunk, and will be enabled by default in 2.0.5, but it&#8217;s still useful in 2.0.4.</p>
<p><strong>[Update] </strong>Session linger cause your threads to wait around for more data from the client it&#8217;s currently working with, without it, you risk switching threads between piped requests which requires moving alot of data around and allocating/freeing threads. It&#8217;s better to have spare threads than to constantly switch the ones you have around.</p>
<h1>Misc</h1>
<p>An other value you may want to change is lru_interval. This is mainly to update the lru list, and the default is 2 seconds. There are several pages that will mention an lru_interval of 3600, but we&#8217;ve seen such values cause problems in the past. I would consider something like 20 seconds. It&#8217;s not going to have a huge impact on your performance.</p>
<p>People also increase the listen depth, this might be necessary but I&#8217;ve not seen any solid evidence that it does, so I generally avoid it.</p>
<p>An other thing to consider is using critbit instead of classic hashing. That is more relevant for huge data sets, and I&#8217;ve not seen any significant performance gain on my synthetic tests yet, but I know some people have so it&#8217;s something you might want to look into.</p>
<p>Session timeout is generally fine at the default (4s), but you should not increase it, or you might run into file descriptor issues.</p>
<p>Then there&#8217;s your load balancer. We&#8217;ve had several cases where Varnish has run into issues because of enourmous amount of connections. You do NOT want to make a connection for every single request.</p>
<h1><span style="background-color: #ffffff">Summary</span></h1>
<blockquote>
<pre>thread_pools 8</pre>
<pre>thread_pool_min 100</pre>
<pre>thread_pool_max 5000</pre>
<pre>thread_pool_add_delay 2</pre>
<pre>cli_timeout 25</pre>
<pre>session_linger 50/100/150</pre>
<pre>lru_interval 20</pre>
</blockquote>
<h1>Testing</h1>
<p>Testing all of this is a different story, but I will point out a few common pit falls:</p>
<ul>
<li><span style="background-color: #ffffff"><strong>Testing your stress testing tool</strong>.  You need a number of machines to test Varnish &#8211; otherwise varnish isn&#8217;t going to be the bottleneck but your stress testing system is. I use a cluster of 6 servers to test Varnish, one will be the varnish server and the other 5 will hammer it &#8211; and that&#8217;s barely enough, even though the Varnish server is not specced for high performance compared to the other nodes.</span></li>
<li><span style="background-color: #ffffff">Using too few connections or too many &#8211; Real life seems to suggest that 10 requests per connection is fairly realistic.</span></li>
<li><span style="background-color: #ffffff">Testing only cache hits. This is great for getting huge numbers, but obviously not all that realistic. For a proper test, you may want to generate urls from log files and balance them accordingly.</span></li>
</ul>
<h1>Results?</h1>
<p>Our single-core Opteron at 2.2GHz handles 27k requests/s consistently. Sure, the load can hit 400-600 but hey, it works. This scales fairly well too, so if that was a dual quad core I wouldn&#8217;t be surprised if we could reach 180 k req/s (but I have no idea where we&#8217;d get the firepower from to test that &#8211; or the bandwidth. I assume there&#8217;d be some completely different issues at that point). This is with 1-byte pages, mind you. I&#8217;ve seen varnish deliver favicon.ico at 60k req/s on a dual quad, but that was an underachiever <img src='http://kristian.blog.linpro.no/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2009/10/19/high-end-varnish-tuning/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ADHD</title>
		<link>http://kristian.blog.linpro.no/2009/09/17/adhd/</link>
		<comments>http://kristian.blog.linpro.no/2009/09/17/adhd/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 22:28:30 +0000</pubDate>
		<dc:creator>kristian</dc:creator>
				<category><![CDATA[/home/kristian]]></category>
		<category><![CDATA[adhd]]></category>
		<category><![CDATA[ritalin]]></category>

		<guid isPermaLink="false">http://kristian.blog.linpro.no/?p=65</guid>
		<description><![CDATA[As many people know, I have Attention Deficit and Hyperactivity Disorder, also known as ADHD. What very few people know, is what this actually means. Most people relate it to problematic kids, and it&#8217;s difficult to understand the extent of how much ADHD affects those of us who live with it.
Since this affects me greatly, [...]]]></description>
			<content:encoded><![CDATA[<p>As many people know, I have Attention Deficit and Hyperactivity Disorder, also known as ADHD. What very few people know, is what this actually means. Most people relate it to problematic kids, and it&#8217;s difficult to understand the extent of how much ADHD affects those of us who live with it.</p>
<p>Since this affects me greatly, and I&#8217;m going through a period right now that&#8217;s fairly challenging (I&#8217;ll get back to that), I figure it&#8217;s time I write a little bit about it from my perspective. However this is a complicated subject, both because it&#8217;s a complicated disorder that, by its very nature, is hard to understand, but maybe more importantly because I&#8217;m essentially writing about myself and parts of me that has taken me decades to come to terms with. You&#8217;ll have to forgive me if I don&#8217;t do the subject justice.</p>
<p>Wikipedia has a reasonably good definition on ADHD:</p>
<blockquote><p><strong>Attention-deficit/hyperactivity disorder</strong> (<strong>ADHD</strong> or <strong>AD/HD</strong>) is a <a title="wikt:neurobehavioral" href="http://en.wiktionary.org/wiki/neurobehavioral">neurobehavioral<span style="border-style: solid ! important;border-width: 1px ! important;padding: 0px 2px ! important;overflow: visible ! important;font-family: arial,sans-serif;font-size: xx-small ! important;line-height: 130% ! important;margin-left: 2px;float: none ! important">26</span></a><sup><a href="http://en.wikipedia.org/wiki/Attention-deficit_hyperactivity_disorder#cite_note-autogenerated1-0"><span>[</span>1<span>]<span style="border-style: solid ! important;border-width: 1px ! important;padding: 0px 2px ! important;overflow: visible ! important;font-family: arial,sans-serif;font-size: xx-small ! important;line-height: 130% ! important;margin-left: 2px;float: none ! important">27</span></span></a></sup> <a title="Developmental disorder" href="http://en.wikipedia.org/wiki/Developmental_disorder">developmental disorder<span style="border-style: solid ! important;border-width: 1px ! important;padding: 0px 2px ! important;overflow: visible ! important;font-family: arial,sans-serif;font-size: xx-small ! important;line-height: 130% ! important;margin-left: 2px;float: none ! important">28</span></a>.<sup><a href="http://en.wikipedia.org/wiki/Attention-deficit_hyperactivity_disorder#cite_note-1"><span>[</span>2<span>]<span style="border-style: solid ! important;border-width: 1px ! important;padding: 0px 2px ! important;overflow: visible ! important;font-family: arial,sans-serif;font-size: xx-small ! important;line-height: 130% ! important;margin-left: 2px;float: none ! important">29</span></span></a></sup> ADHD is primarily characterized by &#8220;the co-existence of attentional problems and hyperactivity, with each behavior occurring infrequently alone.&#8221;<sup><a href="http://en.wikipedia.org/wiki/Attention-deficit_hyperactivity_disorder#cite_note-2"><span>[</span>3<span>]<span style="border-style: solid ! important;border-width: 1px ! important;padding: 0px 2px ! important;overflow: visible ! important;font-family: arial,sans-serif;font-size: xx-small ! important;line-height: 130% ! important;margin-left: 2px;float: none ! important">30</span></span></a></sup> <em><strong>While signs may appear to be innocent and merely annoying nuisances to observers, &#8220;if left untreated, the persistent and pervasive effects of ADHD signs can insidiously and severely interfere with one&#8217;s ability to get the most out of education, fulfill one&#8217;s potential in the workplace, establish and maintain interpersonal relationships, and maintain a generally positive sense of self.&#8221;</strong></em></p></blockquote>
<p>I want you to focus on the second part of this sentence, which is the real problem. It barely scratches the surface, but it&#8217;s a good start. Everyone faces difficulties in their life, and I&#8217;m pretty sure everyone can identify with one or several of the typical symptoms displayed when you have ADHD. And that&#8217;s great part of what makes it hard to write about this. And talk about. And most of all: live with.</p>
<p>However, some parts are far easier to explain than others. Hyperactivity, while often misunderstood, doesn&#8217;t really have to be all that bad when you&#8217;re an adult. For me, the main symptom of hyperactivity is that I have to keep active constantly, both mentally and physically. Working with a computer, the keyboard does the trick. In a meeting, pens, balls, or whatever happens to be in front of me. Annoying, but not really a show-stopper for a social life. Mentally it means getting to sleep is difficult and my mind is going non-stop regardless of what I&#8217;m doing or how tired I am. So far, this is fairly easy to deal with. This was a far bigger problem when I was a kid where the physical manifestation was far more extreme. Because all of this is fairly easy to grasp, this seems to be what most people consider the symptoms of ADHD. If only that was the case.</p>
<p>If we take hyperactivity out of the picture, it gets far more difficult to understand. In all fairness, the two are related, but it&#8217;s still the attention deficit that&#8217;s hard to explain, understand and live with. At least to me.</p>
<p>Without medication, I can go through an entire day switching constantly between tasks without actually getting a single thing done. And that would be a reasonably normal day. However, I am still very much able to focus on things that interest me. That&#8217;s how I got where I am today. Or to put it an other way: whatever I work on has to constantly distract me from all the OTHER distractions. And anything will do, as far as distractions go. Boredom too. This means that I can stare at a problem for an hour, not really do anything else, but still not make any progress, because I&#8217;m constantly shifting my thoughts around. It&#8217;s not a matter of &#8220;just concentrate&#8221; or &#8220;trying harder&#8221;. I can&#8217;t control whether or not I&#8217;m distracted. Imagine working on something in the middle of a circus &#8211; that&#8217;s how my mind works, roughly. And we are still talking short-term.</p>
<p>The distractions above only represent one part of the problem, but is at the core of the issue. Imagine for a moment that you need to make a somewhat difficult call, but every time you let your mind wander in that direction, an elephant whines. Or a lion chews on your leg. Extrapolate that to bills, appointments, registering work hours (which reminds me&#8230;.), or just about any task that you either don&#8217;t look forward to or find boring. While the result is the same, I don&#8217;t really delay these tasks, I&#8217;m just constantly distracted. Is that an excuse? No, it&#8217;s an explanation. Just like someone in a wheel chair can&#8217;t climb stairs &#8211; they are not using it as an excuse to not get to the post office.</p>
<p>This is an other reason it is very hard to talk seriously about ADHD &#8211; I do not wish to use it as an excuse, however, I can&#8217;t deny that it affects me. I do not want to burden my surroundings. The cruel fact of this situation is that my struggle is invisible. If you saw a person without feet crawling up stairs day after day, you&#8217;d understand the effort involved, but it&#8217;s not possible to see the struggle it takes to live with ADHD. Does that mean I want pity? No &#8211; I just want to live my life. Do I want help? Yes, and no. I do not want to be carried, but I&#8217;d appreciate an elevator, to continue the wheel-chair analogy.</p>
<p>As I have lived 25 years with ADHD, I&#8217;ve gotten fairly good at it. I am now able to, at great effort, get through the day and be a productive member of society without medication. The problem is that I&#8217;m still not sure I can get through my life that way, because life consists of more than just days. And since I&#8217;m fairly fond of life, that&#8217;s a bit disturbing. It worries me greatly, in fact, it scares me to death, but all I can do is live on. The most obvious example of how this affects my life is my eternally delayed studies, despite the actual subjects being relatively trivial, the constantly growing amount of over-due bills, the difficulty I have keeping in contact with friends&#8230; The latter problem is something I&#8217;ve suppressed for the longest time, and continue to suppress if I don&#8217;t pay attention. Because it&#8217;s very difficult to distinguish this from what one would easily qualify as &#8220;loser behavior&#8221;. As I hope the reader can understand, this is extremely difficult to write about too..</p>
<p>&#8230;</p>
<p>Too use a bit of humor, although there&#8217;s really nothing funny about this&#8230; Imagine being a social fun-loving person, wanting to go out or do something, but there&#8217;s an elephant on your phone.</p>
<p>And unlike cancer, this isn&#8217;t something that ends quickly. Because 5 years, 10 years, 15 years&#8230; would be quick. I will have ADHD my entire life.</p>
<p>&#8230;</p>
<p>I find myself asking why I&#8217;m writing this. Do I want your sympathy? No. I can only hope for understanding. And my life isn&#8217;t bad, I&#8217;m actually quite happy. I don&#8217;t want anyone thinking otherwise. But it&#8217;s difficult.</p>
<p>Enough with the whiny Kristian, it&#8217;s time to bring out some more facts.</p>
<p>Luckily for me, there are medications to help with the symptoms. Mainly Ritalin. I&#8217;ve been using it somewhat off-and-on for the last 15 years. When working properly, Ritalin is a blessing. While some people claim it&#8217;s wrong to &#8220;drug down&#8221; people with ADHD and whatnot, I like to say, in the most kind words that I have, that those people are fucking idiots. First of all, Ritalin is NOT a sedative. In fact, it&#8217;s the opposite. I am no medical expert, but I know quite well &#8211; and first hand &#8211; what Ritalin CAN do for someone with ADHD. And one thing it doesn&#8217;t do is sedate me. When working properly, it does not give me the ability to ignore distractions, but it allows me to never see them. And I&#8217;m not talking about not being able to notice if somebody talks to me, I&#8217;m talking about the random impulses to think about something else, like that interesting dot on the wall. They are virtually gone. It has made, and continues to make my day a better day. It does not, however, cure ADHD, and it comes at a high price. It also has several somewhat ironic flaws. Due to this, Ritalin is never an easy choice, nor do I think it&#8217;s right for everyone.</p>
<p>If we begin with the flaws, Ritalin is a class A narcotic substance in Norway. As such, getting and picking up a prescription requires more paperwork, phone calls and visits to a doctor. All of those tasks are naturally challenging to someone living with ADHD. This means that, from time to time, I&#8217;ll find myself without medication. Additionally, Ritalin has to be taken regularly. The pills I take have a duration from 2 to 4 hours or so (more on that later), timing it wrong can lead to periods without medication, which means that the circus is back, but this time it brought friends. More than the reduction in productivity, it&#8217;s the unstable mental condition that is troublesome when this happens. This is part of why I have been reluctant to use Ritalin over the last decade and a half, but found myself having to to get something done. It also means that when I wake up, I don&#8217;t have any medication in me, which means that I can easily spend 3 hours to get out the door if I&#8217;m not careful. It also means that it&#8217;s easy to forget.</p>
<p>Some of the medical side effects of Ritalin are also fairly scary. Depression, disturbed sleeping pattern/ability and loss of appetite. Over the years, I&#8217;ve had all of these to great extent. That I choose to still use Ritalin should tell you something about the seriousness of the condition.</p>
<p>One of the tougher drawbacks is the fact that I have to live with the knowledge that without medication, I wouldn&#8217;t function mentally. Knowing that does something to you.</p>
<p>So, to wind back a little bit. The reason I bring all of this up now is that I recently visited a private psychiatrist, since the only follow up I&#8217;ve gotten from the public sector has been what I can only describe as insulting forms to fill out, asking me how frequently I feel like someone else is controlling my mind, if I often hear voices others don&#8217;t and how often I want to smash things. During the consultation, I learned several new things about Ritalin, among other, its duration. I have not been happy with my medication for many years, and it was a relief to hear that it is likely just due to incorrect dosages. I&#8217;ve been using this dosage for at least 10-13 years, but in a life-time, that&#8217;s not really too much. I also learned that there are now capsules that have a far greater duration. I also debunked some of what I thought I knew about Ritalin, mainly about the negativity over over-medicating. In consultation with my psychiatrist, I&#8217;m now experimenting to find the right dosage. It&#8217;s tricky, but interesting. I&#8217;ve been doing that since Monday this week. When I&#8217;ve figured out the dosage, I&#8217;ll try using capsules, which should make it easer.</p>
<p>The results were immediate, though I&#8217;m not done. So far I&#8217;ve increased the daily dosage with about 250%. The main difference is the frequency. I&#8217;ll be experimenting like this for a month, smaller dosages one day, adjusting the frequency an other day and so on. And let me tell you, it&#8217;s tiring but worthwhile.</p>
<p>So far the results have been what I can only describe as a tremendous increase in productivity at work. It&#8217;s not like I was sitting on my ass doing nothing to begin with, but it&#8217;s far easier now. I have yet to experience the most alarming danger sign of over medication, which is a &#8220;speedy&#8221; feeling. A high, basically. However, since I&#8217;m also experimenting with the dosages affecting me while I&#8217;m going to sleep, I&#8217;ve also suffered from sleep loss. I&#8217;ve also noticed a change in appetite, not anything alarming, but noticeable. And this afternoon I also felt the typical and strange feeling of &#8220;chemical&#8221; depression. And I couldn&#8217;t be more thrilled. A month with sleep loss and variable amounts of depression is something I gladly pay if that&#8217;s what it takes to suppress some of the symptoms of ADHD.</p>
<p>During the weeks to come, I&#8217;ll try to find the right dosage so I can actually sleep at night and still functional optimally. One thing that&#8217;s important to remember, however, is that while it is far easier to measure the effect of Ritalin in the workplace, it&#8217;s also necessary to be medicated in the evenings. The difference is that if I go without medication at work, it&#8217;s the work that&#8217;s neglected and I drag other people down with me, so to speak. If I&#8217;m without medication at home, I&#8217;m only dragging myself down. This is something that&#8217;s somewhat difficult for me to accept, but it&#8217;s also fairly obvious. This means that I actually need to make sure that my medication works for as large a part of the day as possible, which means I might have to risk some more sleepless nights.</p>
<p>I could go on, but I think I&#8217;ve driven the point home, and while there are other challenges, there is little point in enumerating them all. It should also be noted that people experience ADHD differently, and this turned out to be more personal than I had initially intended. Maybe it was more for myself than for you.</p>
<p>So, if you work with me and notice I&#8217;m a bit different, strange or tired these days, now you know why. If you read through this, I hope you learned something&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://kristian.blog.linpro.no/2009/09/17/adhd/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
