sudeepg
Feb 02, 2010

Drupal memcache can have stunning improvements on server resources.

 

Assuming you are using memcache API module, there are certain not-so obvious steps you may need to perform to get your server behave nicely. In case, you need help installing memcache and memcache tools, check out the link.

 

One of our Drupal sites had immediate effects the moment memcache was installed and configured correctly as follows:

 

1) Using memcache.inc instead of memcache.db.inc in your $conf['cache_inc']. If you are sure you need memcache, stop storing your tables completely on database.  


<?php
$conf = array(
   // The path to wherever memcache.inc is. The easiest is to simply point it
   // to the copy in your module's directory.
   'cache_inc' => './sites/all/modules/memcache/memcache.inc',
   // or
   // 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc',
);
?>


2) Configuring the necessary memcache instances and bins.

 

I typically run number of memcache instances 2 to 4 depending on my requirement.

 

<?php
$conf = array(
  'cache_inc' => './sites/all/modules/memcache/memcache.inc',
  'memcache_servers' => array('10.1.1.1:11211' => 'default',
                              '10.1.1.1:11212' => 'default',
                              '10.1.1.2:11211' => 'default',
                              '10.1.1.3:11211' => 'cluster2',
                              '10.1.1.4:11211' => 'cluster2'),

  'memcache_bins' => array('cache' => 'default', 'users' =>'cluster2,
                           'cache_filter' => 'cluster2'
),
);
        ?>

3) Storing Sessions with memcache.

This can be another important step for a high traffic site. Drupal stores sessions into database. Moving it to memcache is helpful. Following is how my settings.php would look like now.

 

$conf = array(
  'cache_inc' => 'modules/memcache/memcache.inc',
  'session_inc' => 'modules/memcache/memcache-session.inc',

'memcache_servers' => array('10.1.1.1:11211' => 'default',
                              '10.1.1.1:11212' => 'default',
                              '10.1.1.2:11211' => 'default',
                              '10.1.1.3:11211' => 'cluster2',
                              '10.1.1.4:11211' => 'cluster2'

  'memcache_bins' => array('cache' => 'default', 'users' =>'cluster2,
                           'cache_filter' => 'cluster2'
,
'session' => 'session')

);

4) Now is the time to monitor your memcache if it is all working well.  You should 100% hits.

 

Great. I did all of the above. Performance is great.

 

But, one last thing to be resolved, there is this error that pops up when we submit a form or upload an image:

""An unrecoverable error occurred. This form was missing from the server
cache. Try reloading the page and submitting again." and the form
dissapear."

The solution seems to be to take out cache_form out from memcache (http://drupal.org/node/500646). Memcache module does not allow this. We had to do this using cache router module. More on this on another blog post.

 

Improvements we had with memcache are spectular with the changes above.

 

Given the same traffic on each day:

Traffic on Drupal site

 

The results were as follows:

 

Load:

Memcache performance Load on Munin

 

Memory Usage (typically the same):

 

Drupal Memcache performance CPU improvement Load on Munin

 

CPU Usage:

Drupal Memcache performance CPU improvement Load on Munin

 

Drupal Memcache performance Interrupts improvement Load on Munin

 


 

 

 

great article

this is a great article nice work it explans many things thank you خلفيات

Post new Comment

  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.