Best practices for Drupal sessions in memcached?

blender1968's picture

Hi All,

I'm using memcache module for cache tables.

Now I am interested in doing some testing of using memcache for sessions.

In production we are using RHEL and CentOS in testing so for setup of memcached I'm using the start-memcached and memcached init scripts offered here:

http://www.dev411.com/wiki/Memcached_startup_files_for_Red_Hat_(RHEL)

This uses a /etc/memcached.conf which looks something like this:

-u apache
-d
-m 32
-l 127.0.0.1
-p 11211

Based on info contained within this thread:

http://drupal.org/node/354420 (Cannot access modules page when using memcache-session.inc)

it states that "Note you MUST have a session and a users server set up for memcached sessions to work."

My question then is: Using RHEL start-memcached/memcached init scripts how does one go about creating a second memcached server on the same Linux server?

There is a very good article from lullabot (http://www.lullabot.com/articles/how_install_memcache_debian_etch) in Debian environment that just uses a bash script to start several memcached servers but I would like to stick with the RHEL init scripts if at all possible.

Anyone been down this path before?

Thanks!

Cheers

P.S.

It seems like the docs for the memcache module are dated? At least on the project page (http://drupal.org/project/memcache) they seem to be:

  • "Also note that the 3.x versions of the PECL package have not been tested with this module and are reported not to work."

3.0.3 seems to be working fine for me. At least I hope it is! Logged in as admin I see gets, sets, bins and hits so it looks good. Are others using memcache module with PECL memcache 3.0.x?

  • ""Drop-in" replacement libraries for session handling. One that uses memcache exclusively (session-memcache.inc) and one that uses memcache if available and fails over to the database if memcache becomes unavailable.(session-memcache-db.inc)"

The README.txt makes no mention of session-memcache-db.inc and this file does not exist in the memcache-6.x-1.2.tar.gz download. Was this removed for some reason?

Login to post comments

Hacked RHEL init scripts

blender1968's picture
blender1968 - Mon, 2009-02-02 22:46

I have Drupal sessions in memcached.

I basically just added another set of RHEL init scripts. i.e.:

[root@XXXXX bin]# diff start-memcached start-memsessiond
17c17
< my $etcfile = shift || "/etc/memcached.conf";
---
> my $etcfile = shift || "/etc/memsessiond.conf";
25c25
< my $pidfile = "/var/run/memcached.pid";
---
> my $pidfile = "/var/run/memsessiond.pid";

[root@XXXXX etc]# diff memcached.conf memsessiond.conf
10c10
< -p 11211
---
> -p 11212

[root@XXXXX init.d]# diff memcached memsessiond
6c6
< # chkconfig: - 80 12
---
> # chkconfig: - 81 13
19,21c19,21
< DAEMONBOOTSTRAP=/usr/local/bin/start-memcached
< DAEMONCONF=/etc/memcached.conf
< NAME=memcached
---
> DAEMONBOOTSTRAP=/usr/local/bin/start-memsessiond
> DAEMONCONF=/etc/memsessiond.conf
> NAME=memsessiond

[root@XXXXX init.d]# ps -ef | grep mem
apache 21791 1 0 13:52 ? 00:00:00 /usr/local/bin/memcached -u root -u apache -m 32 -l 127.0.0.1 -p 11212

apache 30288 1 0 Jan30 ? 00:00:00 /usr/local/bin/memcached -u root -u apache -m 32 -l 127.0.0.1 -p 11211

Needs more testing before I'd consider deploying - but it works.

Cheers

P.S.

Would still like to hear about session-memcache-db.inc since if the memcached process providing bins for session and users dies no one (including admin) can login.


Falling back to DB sessions?

markus_petrux's picture
markus_petrux - Tue, 2009-02-03 04:02

In case memcache is dead during bootstrap... maybe adding a fallback path to DB sessions? It would have to create some kind of alert so the site admin knows something is going wrong.


DB sessions

blender1968's picture
blender1968 - Tue, 2009-02-03 15:47

Yah, I assume that's what session-memcache-db.inc was supposed to do. Still interested in why this option seems to have been withdrawn from the memcache module... it's a dead file in CVS without much reasoning (AFAICT) why it was removed.

Definitely could run sessions in memcached, monitor process (check_tcp) and alert if down.

Cheers


Because it was not worth the

slantview's picture
slantview - Wed, 2009-02-04 21:35

Because it was not worth the added overhead. It was slowing down page loads considerably which is what you are trying to avoid if you are using memcache sessions.