+44 (0) 207 193 0834

How to Make Drupal Perform and Scale Like a Rockstar!

Some of the developers of our team had the opportunity to attend the drupalcon session:
Damn Quick Drupal: How to Make Drupal Perform and Scale Like a Rockstar! by Michael Cooper (Soyarma), you can find very useful information about the mentioned conference here:

http://london2011.drupal.org/conference/sessions/damn-quick-drupal-how-m...

It was very useful but also very quick, so we've written up the most important points in this quick reference guide.

There are 2 main parts: drupal configuration and apache configuration

Drupal configuration
 

  1. Consider always caching your pages (including front and 404s pages):
    This can be achieved in a lot of ways: the use of apache cache modules (as you will see in the server configuration section), the use of drupal default cache settings and you can use too extra modules like: http://drupal.org/project/authcache (APC apache module + AuthCache drupal module is a WIN combination for your page caching).
     
  2. Don't let anonymous hit imagecache generation URLs:
    An easy way that helps to avoid this is the use of generic hotlinking protection, you can find a lot of useful information about this here: http://bit.ly/piLnel
     
  3. Be careful with cookies and session data caching:
    An easy win to reduce pages load time in your site in relation with session data is to use the module: http://drupal.org/project/no_anon which allows drupal to avoid session data and cookie caching for anonymous users.
     
  4. Consider Path alias cache:
    You can use a module for this purpose: http://drupal.org/project/pathcache
     
  5. Examine your views queries and views pages:
    The main problem in views queries is the excesive use of JOINs, but the performance of views queries can be significantly improved by using index tables. There is a very interesting module which automates the mentioned process: http://drupal.org/project/shadow
     
  6. Double check your headers to avoid your browser requests continuously for freshed pages:
    This option is included by default in drupal 6 pressflow and drupal 7 core.
     
  7. Drupal aggresive cache:
    This kind of cache management can improve a lot the load times for your site pages but the problem is that a lot of modules are incompatible with this kind of caching becasuse some of their hooks are not called or called in the non appropriate way, so if you are thinking about enabling this setting be sure about your modules compatibility with it and about the existence of patches that can solve this kind of issue.

 

 
Server configuration (Apache, MySQL)
 

  1. Enable MYSQL query cache. If enabled, be sure about you are using sane settings:

    http://www.techiecorner.com/45/turn-on-mysql-query-cache-to-speed-up-mysql-query-performance/

    Use the following settings:
    key_buffer_size=12M (key cache)
    query_cache_size=24M
    query_cache_limit=2M
    table_cache=96
    sort_buffer_size=12M
    myisam_sort_buffer_size=12M
    tmp_table_size=12M
     

  2. Use Advanced PHP Cache (APC) module for Apache: Every time a file is read by PHP it is compiled (checked for syntax errors, optimized, compiled into byte-code).
    APC (advanced PHP cache) will do this once and then cache the results. APC will check the file every time it is accessed to determine if it is still the same. If that happens rarely, set apc.stat to 0 and you will save that check.
    The cacherouter module for drupal will integrate APC with the standard cache clearing functions:
    http://drupal.org/project/cacherouter
     
  3. Set the appropiate value for your max-clients apache parameter. Yo can calculate this parameter in this way:
    • Use a tracking system (GA, statistics, devel performance logging, webserver logs) to determine how many actual page loads you get at your peak traffic time.
       
    • Depending on how sharp the spike is, pike a time period that sits at around the top 90% of that spike.
       
    • Work out how many pageviews you get a minute during the peak of that spike.
       
    • Since you know how long (on average) it takes to generate a page, you can determine how many of those requests are concurrent. You can calculate this value in this way:

      (P / M) x (E / 60) = C
      P = Number of page views that hit Drupal
      M = Minutes page views collected over
      E = Average Execution time per page in seconds (obtained from your tracking system)

      C = Concurrent requests (the right value for apache max-clients parameter)
       

      Example:
      Number of requests: 5000 (P parameter)
      Time taken: 28.9 seconds = 28.9/60 = 0.482 minutes (M parameter)
      Mean time/request: 578ms = 0.578 sec (E parameter)
      C = (5000 / 0.482) x (0.578 / 60) = 100
      So the max-client parameter should be set to 100

       

 
Extra Tips: Improving front-end performance
 

  • Mod Pagespeed, help out your users by helping their browers load your site faster:
    Pagespeed is an apache module developed by Google team and based on its performance philosophy, you can find a lot of useful information here: http://bit.ly/bBPcYl
  • Reverse proxies save Apache/PHP from running when they don't have to:
    The best drupal accelerator based on reverse proxies idea is Varnish, you can find a lot of information here: http://drupal.org/project/varnish
     
  • CDNs offer shorter round trips for your users, but are often notfaster than a good reverse proxy and can cause some confusion when clearing caches.
     
  • Domain Sharding, a good way to help your users get content faster:
    Browsers open a limited number of connections per domain. Most notably, Internet Explorer 6 and 7 open only two connections per domain. Domain Sharding is a technique based on serving your site contents from different domains (normally used to improve the pages load in relation with images). There is a drupal module which can help you to configure a domain sharding to serve your images faster: http://drupal.org/project/parallel_css

 

 
Conclusions

 
Yo can easily improve a lot your site performance only doing the following:
 

  1. Use default cache options available in drupal (take care of the aggresive mode).
  2. Use APC + cacherouter module to cache compiled php code, APC + authcache will help you too with the page caching.
  3. Beware of: hotlinking, anonymous session data caching, url alias caching, views queries and headers.
  4. Use basic mysql cache settings (first point of the server configuration tips).
  5. Calculate the right value for your max-clients apache parameter and set it.

 

José's picture
13 Jun 2013
José

Add new comment