MySQL Forums
Forum List  »  Memory Storage Engine

Re: Session and your opinion
Posted by: J Rabbit
Date: January 03, 2008 03:49PM

I use this method and it works reasonably well, but isn't great for sites with a huge number of concurrent users.

The problem is that the MEMORY engine has a Fixed row format which means that you have to be careful setting the maximum length of the string containing the session data - too small and the session gets corrupt - too large and you run out of memory quickly. I'm considering changing it to innodb and reallocating the memory to the buffer.

Once nice advantage - you can ditch PHP's session garbage collection and have a cron job periodically clean up the data which doesn't block a user's page load while it happens.

One optimisation you can use - store a copy of the session value you read in a string variable and compare it before writing to avoid unnecessary updates. I create sessions with a 30 minute expiry time. When writing, if nothing has changed, I only update the expiry time if its less than 25 minutes. This means not all page hits update the memory table, so there are fewer locks.

Finally, have a server restart script that backs up the memory table to myisam before shutting down mysql and reimports it on startup so your sessions survive database restarts.

Options: ReplyQuote


Subject
Views
Written By
Posted
6392
October 22, 2007 12:27AM
Re: Session and your opinion
4327
January 03, 2008 03:49PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.