Drupal caching


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Drupal caching

  1. 1. Caching with Drupal DrupalCamp Helsinki 27.05.2009 Kalle Virta, Exove
  2. 2. Why to cache with Drupal <ul><li>As Drupal is made with PHP it tends to burden the SQL server pretty much </li></ul><ul><li>Drupal is a single-controller architecture, and it loads a lot of code by default on every pageload </li></ul><ul><li>Compared to a pure MVC-model (e.g. CodeIgniter framework), the architecture of Drupal makes it usually somewhat slower </li></ul><ul><li>You always need caching, and you should always be aware of your scalability, i.e. the upgrade path </li></ul><ul><li>Even positive problems (too much traffic) are problems at the end </li></ul>
  3. 3. Overview of caching levels <ul><li>Drupal block caching </li></ul><ul><li>Drupal internal page caching </li></ul><ul><li>HTTP cache, e.g. reverse proxy </li></ul><ul><li>CDN (Content Delivery Network) solutions </li></ul><ul><li>Custom cache built-in to your code with Drupal’s cache API </li></ul><ul><li>Opcode caching (e.g. APC) </li></ul><ul><li>SQL query caching </li></ul>
  4. 4. Drupal internal caching <ul><li>From Drupal 6, there’s been a block cache available </li></ul><ul><li>Drupal also has internal pagecache in it’s core </li></ul><ul><li>It caches pages by saving the finished HTML to the database </li></ul><ul><li>It (in the usual cases) turns off if you’re logged in to the system </li></ul><ul><li>With a contrib module you can make Drupal use other caching systems instead of the database </li></ul>
  5. 5. HTTP level caching <ul><li>If you can use it fully, HTTP caching can make the site really fast, depending on the software used (Using nginx as the system paired with it’s own connection to your pagecache running on memcached, you can get to over 3000 reqs/sec with a single server) </li></ul><ul><li>Only for anonymous users </li></ul><ul><li>Most pages logged in user views are really not that dynamic </li></ul><ul><ul><li>You can use Javascript to cheat and use http caching partially for logged in users </li></ul></ul>
  6. 6. Magnitude of performance gain through a couple of “page” caching techniques
  7. 7. Code level caching <ul><li>Code level caching in Drupal usually focuses to caching data coming from SQL, since all data is usually saved into the SQL server </li></ul><ul><ul><li>Not always, though. An XML data storage is usually way slower and needs caching even more. </li></ul></ul><ul><li>Drupal has it’s own cache control API for custom caching, many contrib modules are already programmed to use this </li></ul><ul><li>Drupal’s own cache saves data to the SQL server, this is fine from low to medium traffic sites, but high traffic sites need to save the cache to memory </li></ul><ul><li>For saving the Drupal cache (through the normal API) to memory, you can override the Drupal default database caching to use e.g. memcached using Cache Router contrib module, now in beta8 for D6 </li></ul><ul><li>This is the best way to make very dynamic content fast </li></ul>
  8. 8. Opcode cache <ul><li>Opcode caching mean caching the compiled bytecode of PHP program code </li></ul><ul><li>Essentially it skips the parsing and compiling of PHP code when the cached code is ran </li></ul><ul><li>Opcode caching with a PHP accelerator is simple, works with most PHP applications and gives you a significant boost in performance </li></ul>
  9. 9. Caching with Drupal Drupal HTTP cache Drupal page cache
  10. 10. What should I do with my site? <ul><li>Usually it comes to three questions </li></ul><ul><ul><li>“ Is the site already built?” </li></ul></ul><ul><ul><li>“ What’s the share of anonymous/logged in users?” </li></ul></ul><ul><ul><li>“ What options does my hosting environment even allow?” </li></ul></ul><ul><li>Profile! </li></ul><ul><ul><li>Use xdebug or similar profiling tool to see what actually happens during a page load (remember to profile under load, the results tend to change when the system is under load) </li></ul></ul><ul><ul><li>Usually the first couple of rounds of profiling give you clear bottlenecks in the system – after that it gets harder </li></ul></ul><ul><li>Call for professional help  </li></ul>
  11. 11. <ul><li>Questions? </li></ul>Thank you for your time