Created
December 18, 2012 11:22
-
-
Save K-Phoen/4327229 to your computer and use it in GitHub Desktop.
Storing Symfony2 sessions in memcached
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imports: | |
# .... | |
- { resource: services/session.yml } | |
framework: | |
# .... | |
session: | |
handler_id: session.handler.memcached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aptitude install memcached php5-memcached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
# ... | |
session_memcached_host: localhost | |
session_memcached_port: 11211 | |
session_memcached_prefix: sess | |
session_memcached_expire: 3600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
session.memcached: | |
class: Memcached | |
arguments: | |
persistent_id: %session_memcached_prefix% | |
calls: | |
- [ addServer, [ %session_memcached_host%, %session_memcached_port% ]] | |
session.handler.memcached: | |
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler | |
arguments: [@session.memcached, { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }] |
@cmenning Could you please show up your #1 gist?
https://gist.github.com/elmariachi111/5637669a028c29e3973a better late than never ;)
@cmenning you just made my day! Thanks a lot man!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HUGE caveat here... Spent several hours figuring out what was going on.
If you are using Apache prefork, giving the persistent_id when instantiating the service creates a connection to memcached that lasts for as long as the Apache worker child stays alive (this can be a good thing... less overhead). However, the addServer call does not check for duplicates; this causes the memcached server to be listed in the server list and a connection to be opened once for every single request served by the worker.
The default Ubuntu settings are for a maximum of 400 workers, each able to handle 10000 requests before being killed. That means there might be as many as 4,000,000 open connections to the memcached server.
When we hit the memcached open connection limit of 1024, we were no longer able to store or retrieve any sessions from that point forward because the old connections just wouldn't die. There are two possible fixes for this:
Short term (because it's easier) I've gone with #2 - testing shows it's stable for now. There's obviously a performance overhead that would be negated by implementing #1.