United States|United Kingdom|India
sudeepg
Feb 03, 2010

I believe you have already worked upon the Drupal 6 performance and optimzation techniques and now is the time to do some session handling improvements.

 

Drupal Sessions: Challenge

 

Drupal stores sessions in database tables that may make your drupal site slow if your application is too database intensive and you have too many users loging in and logging out.

 

Drupal Sessions: Solution

 

Memcache as always!

 

Use the beautifully written Memcache module and use the following session handler in settings.php after you have installed memcache.

 

$conf = array(
  'cache_inc' => './sites/all/modules/cacherouter/cacherouter.inc',
'session_inc' => './sites/all/modules/memcache/memcache-session.inc',
  'memcache_servers' => array(
    'localhost:11211' => 'sesion',
  ),
  'memcache_bins' => array(
    'session' => 'sesion'
  ),
);


 

Monitor with Brutis and check out your database session table. It would stop getting updated, but you are still able to log in and log out. This means your drupal site sesssions are correctly getting stored in Memcache.

 

Somethings we lose?

 

All is not well though. Drupal "who's online" core drupal block would stop working, since, it the program in the core queries the databse for people who are online and you can not override it in sessions.inc? Why? Finding out all the users who are currently maintaining sessions in the key-value format (this is how data is stored in memcache) on memcache can be resource intensive, though a separate key-value pair to track down your current sessions can be done and should be possible.

 

Another Challenge with memcache and cache_forms?

 

cache_forms has problems and errors when stored in memcache. One of the error you would see when uploading images for forms (when cache_form is getting stored in memcache) is  "An unrecoverable error occurred. This form was missing from the server cache. Try reloading the page and submitting again."

 

Solution?

 

Use cacherouter instead of memcache API module, since, cacherouter allows us to move certain components (like cache_form) out of memcache and in some other caching engine (like db, file, APC) which memcache module does not. So, now my settings.php would now look like:

 

$conf = array(
  'cache_inc' => './sites/all/modules/cacherouter/cacherouter.inc',
 'session_inc' => './sites/all/modules/memcache/memcache-session.inc',
  'memcache_servers' => array(
    'localhost:11211' => 'sesion',
  ),
  'memcache_bins' => array(
    'session' => 'sesion'
  ),

'cacherouter' => array(
'default' => array(
'engine' => 'memcache',
'server'=> array('localhost:11212', 'localhost:11213'),
'shared'=>TRUE,
'prefix'=>'',
),
'cache_form' => array(
    'engine' => 'file',
   'servers' => array(),
    'shared' => TRUE,
    'prefix' => '',
    'path' => 'sites/default/files/filecache',
    'static' => FALSE,
    'fast_cache' => TRUE,
  ),
),
);

My sessions continue to get stored in session handler (sites/all/modules/memcache/memcache-session.inc) of memcache api module.

 

Great! So everything is faster and stable now, though, we have lost "Who's online" functionality as of now.

No Page is Blank

i enabled the cacherouter  module..when i add previous code in my setting.php..the page was blank..so how can i clear this bug.

Post new Comment

  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Links to specified hosts will have a rel="nofollow" added to them.

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.