how to optimize drupal's performance using memcache

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 to install memcache.

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 test 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.

你可能感兴趣的:(PHP,cache,Blog,UP,performance)