Drupal tries to cater to 80% of the market by taking most decisions for you. Generally this is a good idea. But if you fall in the remaining 20% then you need to get your hands dirty and start hacking around. Drupal by default stores all sessions in the database. This is a good idea if your site does not get a lot of load. But as your site starts growing, this will soon become a major bottleneck. Storing sessions in memcache works best in such situations. Not only is memcache easy to maintain, install and work with, but also provides in depth stats about itself. This is very handy if your planning on monitoring memcache using nagios or zabbix for example.
First you will need to have memcache support in php. This is a piece of cake in Ubuntu.
sudo apt-get install php5-memcache
Now you will need to add the following to your php.ini. For more information on consistent hash check out the article on wikipedia.
memcache.hash_strategy="consistent"
This will downloading and extract the memcache code for you.
cd modules wget http://ftp.drupal.org/files/projects/memcache-6.x-1.2.tar.gz tar zxvf memcache-6.x-1.2.tar.gz
Append the following to your settings.php
$conf = array( 'cache_inc' => 'modules/memcache/memcache.inc', 'session_inc' => 'modules/memcache/memcache-session.inc', 'memcache_servers' => array( 'localhost:11211' => 'session' ), 'memcache_bins' => array( 'session' => 'session' ), );
Update: You can also use session-memcache-db.inc to act as a fail over. This uses memcache if available and fails over to the database if memcache becomes unavailable.
Note: You can also run memcache -vvv for a while to ensure that everything is running fine.
Comments
Post new comment