Handle Users and Their Sessions via Memcached

For busy sites the sessions table will be read very frequently and can cause performance locking problems. This is not an issue for small and medium sites. But to take Drupal performance a step further, let APC or Memcache handle the sessions. I prefer and recommend using the Drupal Memcached module, which has a built-in feature to handle sessions via Memcache. I usually create a special user bin for Memcached (recommended).

Example code for settings.php

This example shows four Memcache bins. The fourth is called "other" and is dedicated to handling users and sessions. Notice the setting "session_inc". Read the Memcache module README.TXT for instructions. Also check your paths /sites/all/modules... etc.

$conf = array(
  'cache_inc' => './sites/all/modules/contrib/memcache/memcache.inc',
  'session_inc' => './sites/all/modules/contrib/memcache/memcache-session.inc',
  'memcache_servers'  => array(
                            'localhost:11211' => 'default',
                            'localhost:11212' => 'page',
                            'localhost:11213' => 'views',
                            'localhost:11214' => 'other',
                          ),
  'memcache_bins'  => array(
                            'cache' => 'default',
                            'cache_content' => 'page',
                            'cache_page' => 'page',
                            'cache_views_data' => 'views',
                            'session' => 'other',
                            'users' => 'other'
                          ),
  'memcache_key_prefix' =>  'domain_com',
);

Advantages

  • Reduce MySQL load / requests by moving Users and Sessions into the caching layer

References

Morningtime