<?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>Cruncht &#187; caching</title>
	<atom:link href="http://cruncht.com/tag/caching/feed/" rel="self" type="application/rss+xml" />
	<link>http://cruncht.com</link>
	<description>Semantic web development and publishing</description>
	<lastBuildDate>Sun, 21 Mar 2010 23:54:04 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Drupal Caching (part 9)</title>
		<link>http://cruncht.com/95/drupal-caching</link>
		<comments>http://cruncht.com/95/drupal-caching#comments</comments>
		<pubDate>Thu, 04 Feb 2010 10:02:08 +0000</pubDate>
		<dc:creator>Murray Woodman</dc:creator>
				<category><![CDATA[Drupal Planet]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://cruncht.com/?p=95</guid>
		<description><![CDATA[Several advanced options exist to take caching to the next level in Drupal. With advanced caching Drupal is able to scale to levels required by the most demanding of sites.

We have already discussed (i) page  and block caching and (ii) other caches which come baked into the core of Drupal in the Out of [...]]]></description>
			<content:encoded><![CDATA[<a href="http://cruncht.com/95/drupal-caching" title="Drupal Caching (part 9)"><img src="http://cruncht.com/wp-content/uploads/2010/02/squirrel-150x150.jpg" alt="Red Squirrel" class="feed-image" title="Drupal caching" /></a><p>Several advanced options exist to take caching to the next level in Drupal. With advanced caching Drupal is able to scale to levels required by the most demanding of sites.</p>
<p><span id="more-95"></span></p>
<p>We have already discussed (i) page  and block caching and (ii) other caches which come baked into the core of Drupal in the <a href="/87/drupal-performance-out-of-the-box">Out of the Box</a> section. Whilst big gains can be made through enabling simple config options it is possible to make several more improvements to the way Drupal caches and serves data, making Drupal a system which can scale to serve 1000s of requests a second if the need arises.</p>
<h2><a id="page-caching">Page Caching</a></h2>
<h3><a id="drupal-bootstrap">The Bootstrap</a></h3>
<p>Every time Drupal code needs to be run either through a web page or script, Drupal must undertake the boostrap process which has a certain amount of overhead. Generally this process cannot be avoided &#8211; you need to run code after all. However, there are a couple of cases where it is possible. Firstly, Normal Page caching avoids much of the bootstrap save for hook_boot() and hook_exit() hooks which are used by the statistics and throttle modules. Secondly, Aggressive Page Caching allows for all of the bootstrap to be avoided when serving content.  Finally, contributed modules such as Boost and Varnish allow for the avoidance of PHP and bootstrap since they are operating at a stage before PHP is invoked. This is the main reason Boost and Varnish are so attractive as a page cache.</p>
<h3><a id="boost">Boost</a></h3>
<p><a href="http://drupal.org/project/boost">Boost</a> is a page cache which works in a similar way to aggressive page caching in that it attempts to serve cached data without running the bootstrap. However, it is able to go one step further and avoid PHP being run as the redirect takes place in rewrite rules located in .htaccess. If the static file exists then it is served as the response. The end result is super fast response without running PHP or the bootstrap. This frees up the server to handle more requests from logged in users.</p>
<p>Boost is an attractive module because it is easy to install, has a lot of configuration options which give good control over cache building and invalidation. It is highly recommended.</p>
<p>One aspect of Boost which may be forgotten is that it isn&#8217;t an entirely a file based solution. If the operating system file cache is working well then there is a good chance that the &#8220;file&#8221; will come out of RAM rather than off disk. This makes Boost a competitive option when compared to other more complicated reverse proxy setups such as Squid or Varnish.</p>
<p>Because Boost is file based it is able to potentially cache a lot more data than a RAM based solution. If you have thousands or millions of pages to cache putting them all in RAM is probably not optimal. Best to put them on disk and save the RAM for DB indexes or possibly a CacheRouter cache.</p>
<p class="summary">All sites, especially big, infrequently changing, high traffic: Big gains. Easy setup.</p>
<h3><a id="varnish">Varnish</a></h3>
<p>The <a href="http://drupal.org/project/varnish">Varnish HTTP Accelerator Integration</a> module integrates Drupal with <a href="http://varnish-cache.org/">Varnish</a>, a reverse proxy which sits in front of Apache, PHP and Drupal. Varnish stores cached content in RAM and avoids the overhead of Apache and the Drupal bootstrap. As such it offers very high performance for anonymous users on cached pages and is the preferred option for many sites where scaling is paramount.</p>
<p>Varnish requires either a patch to core to add HTTP headers, PressFlow or Drupal 7. Most people are therefore running Varnish in conjunction with PressFlow.</p>
<p class="summary">High Traffic: Big gains when performance critical.</p>
<h3><a id="squid">Squid</a></h3>
<p>Squid is a reverse proxy similar to Varnish and is in use on drupal.org. It doesn&#8217;t seem to be such a commonly deployed solution probably because PressFlow has been altered to work with Varnish which is higher performing apparently.</p>
<p class="summary">Varnish preferred over Squid.</p>
<h3><a id="varnish-vs-boost">Varnish vs Boost</a></h3>
<p>A popular thread <a href="http://groups.drupal.org/high-performance">High Performance</a> Drupal group is for the <a href="http://groups.drupal.org/node/46042">perfect recipe for page caching</a> &#8211; whether to use Varnish or Boost. Varnish has the edge in speed over Apache+Boost as well as Nginx+Boost. Look at <a href="http://groups.drupal.org/node/45514#comment-119868">results</a> published by <a href="http://groups.drupal.org/user/16022">brianmercer</a>.</p>
<table style="height: 88px;" width="417">
<tbody>
<tr>
<th style="text-align: left;">Setup</th>
<th style="text-align: left;">Approx requests/s</th>
</tr>
<tr>
<td>Boost with Apache-prefork</td>
<td>500</td>
</tr>
<tr>
<td>Boost with Nginx</td>
<td>2000</td>
</tr>
<tr>
<td>Varnish</td>
<td>2400</td>
</tr>
</tbody>
</table>
<p>Varnish may have the edge in speed but it is more complex to install and requires a patched core. Some people may not want to run a non standard Drupal installation. Varnish also requires RAM to store the cached material &#8211; something which may be better spent elsewhere (database or max clients). Boost offers similar performance, is easy to install and has good control of cache invalidation and warmup. Boost is also able to serve files from RAM if the OS has cached them.</p>
<p>It is certainly up to you to decide which avenue to take. This guide is attracted to the relative simplicity of Drupal + Nginx + Boost over Pressflow + Varnish + Apache/Nginx. Nginx brings better performance to the web server as a whole, ie. pages not in the cache, and RAM savings if it is needed elsewhere. It must be stressed that each site has a different profile and the ultimate decision is up to you.</p>
<dl class="more">
<dt><a href="http://groups.drupal.org/node/26485">Has anyone tried nginx caching with Drupal?</a></dt>
<dd>Drupal Groups thread with lots of benchmarking. Final conclusion seems to be that Varnish vs Boost+Nginx is a pretty close thing.</dd>
<dt><a href="http://www.chapterthree.com/blog/josh_koenig/project_mercury_preconfigured_drupalvarnish_ec2_ami">Project Mercury: A pre-configured Drupal+Varnish EC2 AMI</a></dt>
<dd>Josh Konig of Chapter Three claims that Varnish is faster than Boost but gives no numbers.</dd>
<dt><a href="http://www.metaltoad.com/blog/quick-drupal-cacherouter-and-boost-benchmarks">Quick Drupal Cacherouter and Boost benchmarks</a></dt>
<dd>Dylan Tack likes Boost: &#8220;Response times are all close enough that it doesn&#8217;t really matter what caching backend you choose&#8230; The only factor that&#8217;s really relevant is how good your system&#8217;s cache expiration and regeneration logic is&#8230; it seems like Boost is the clear winner here as well.&#8221;</dd>
<dt><a href="http://groups.drupal.org/node/46042">What&#8217; recipe should i choose for best performance?</a></dt>
<dd>Discussion with participants split between Varnish and Boost depending on circumstances. Nginx+Boost seems pretty equal with Varnish.</dd>
<dt><a href="http://groups.drupal.org/node/21897">Caching: Modules that make Drupal scale</a></dt>
<dd>Table of modules, performance gains and features.</dd>
</dl>
<h2><a id="cache-router">Cache Router</a></h2>
<p><a href="http://drupal.org/project/cacherouter">Cache Router</a> is a module which enables you to cache the Drupal cache tables (including views, blocks, menus, variables, and filters) in RAM. Drupal no longer has to hit the database to pull out this content &#8211; a big win for logged in users who might not be able to enjoy the advantages of a page cache. Cache Router therefore fills an important niche in your caching strategy.</p>
<p>Cache Router is able to do this via a number of backends including APC or Memcache. APC should be considered if you are running Drupal on a single node and only need the single local store. <a href="http://www.chapterthree.com/blog/josh_koenig/project_mercury_preconfigured_drupalvarnish_ec2_ami">According to Josh Konig</a>, APC &#8220;is less error-prone, more secure, and allegedly as fast (if not faster) than running memcached according to the folks at Facebook.&#8221; Memcache can be used to share cached data between or across multiple servers.</p>
<p class="summary">High Traffic, Logged in: Massive gains when page cache not hit.</p>
<hr />
<p>This article forms part of a series on Drupal performance and scalability. The first article in the series is <a href="http://cruncht.com/75/drupal-performance-scalability">Squeezing the last drop from Drupal: Performance and Scalability</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cruncht.com/95/drupal-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
