Testing our new EC2 setup I noticed that when we restart memcache, the users lost their session and have to login again to the website?

This is our config:

$conf = array_merge($conf,array(
    'memcache_key_prefix' => 'pre_example.org', 
    'cache_inc' => './sites/all/modules/memcache/memcache.inc',
    'session_inc' => './sites/all/modules/memcache/memcache-session.inc',
    'memcache_servers' => array(
        'localhost:11211' => 'default',
        'localhost:11212' => 'page',
        'localhost:11213' => 'filter',
        'ec2-base-internal.example.org:11211' => 'default',
        'ec2-base-internal.example.org:11212' => 'page',
        'ec2-base-internal.example.org:11213' => 'filter',
        'ec2-base-internal.example.org:11214' => 'session',
    ),
    'memcache_bins' => array(
        'session'      => 'session',
        'cache'        => 'default',
        'cache_menu'   => 'menu',
        'cache_page'   => 'page',
        'cache_filter' => 'filter',
        'cache_block'  => 'default',
        'cache_content'=> 'default',
    ),
)
);

Thanks in advance, Simon.

Comments

SimonVlc’s picture

Anyone?

jeremy’s picture

Status: Active » Closed (works as designed)

Nope, this is by design. Memcache is not a permanent data store, and if restarted anything stored there will be flushed.

If you store your memcache session data on multiple servers, then you'd only be losing a portion of the sessions when you restart memcache on each server (assuming you're using consistent hashing).

SimonVlc’s picture

Thanks for your answer Jeremy, it was pretty clear now.

I have one monster server for MySQL with 68GB of RAM and several small high cpu webservers (but low on memory, 1.7G). I was thinking to centralize all memcache on the big one (I have splitted among all of them right now).

But, for your answer, it seems that the sessions will be better splitted, true? Are other caches candidate to reside on the webservers?

Thanks for your help Jeremy.

ywarnier’s picture

Hi there, in this article, you've got an explanation on how to combine the good side of memcached (speed) with the good side of the database (persistence) in an optimal way, with code provided: http://www.softwareprojects.com/resources/programming/t-memcached-for-ph...

I think you might to check it out. Combining this mechanism with the existing session handling of Drupal would make a real deadly weapon, so to speak.