3

I have an application (Magento) that has an abstracted session storage layer. I'm trying to visualize the best way to store sessions.

mysql Database? I'm thinking a dedicated database with a very large innodb_buffer_pool_size so its basically like RAM Cache with disk backup. I'm thinking of having a seperate DB just for sessions and put the other DB stuff on a separate DB/DB Server.

Memcache? This is great but I am a bit concerned with what happens if the server crashes? I would lose that partition of sessions with the crash because from what I understand Memcache is not distrubuted. Can I make it distrubuted? ( I was just told that I can use pecl memcache module >= 3

tmpfs memory file storage? This works but I would have to sync the session on write with all the other servers using rsync or something that detects when an write happens in that folder. I'm sure something has got to exist for this.

Other solution I am not thinking about? Would love ideas.

Thanks!

Bryan Ruiz
  • 131
  • 3
  • Sounds like you are on the right track i.e. Memcache probably faster but not as persistent as in a database. For the file storage you could use a cluster file system for that (e.g. OCFS2) but the complexity of the setup probably far outweighs the benefit. Probably best to start out with a DB, no? – HTTP500 Aug 09 '11 at 20:42

1 Answers1

2

Memcache? This is great but I am a bit concerned with what happens if the server crashes? I would lose that partition of sessions with the crash because from what I understand Memcache is not distrubuted. Can I make it distrubuted? ( I was just told that I can use pecl memcache module >= 3

I'm using repcached. It is started like below:

  • on server 1:

    memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached.pid -x <server2_ip>

  • on server 2:

    memcached -d -p 11211 -u memcached -m 64 -c 1024 -P /var/run/memcached.pid -x <server1_ip>

Configuration for PHP Memcache extension:

extension=memcache.so
memcache.allow_failover = 1
memcache.redundancy = 1
memcache.session_redundancy=2
memcache.hash_strategy = consistent

And the session handler in php.ini:

session.save_handler = memcache
session.save_path="tcp://ip1:11211, tcp://ip2:11211"
quanta
  • 50,327
  • 19
  • 152
  • 213