Unicorn, Rails and Memcached

Stefan Maier stefanmaier at gmail.com
Tue Jan 5 17:47:38 EST 2010

Am 1/5/10 11:34 PM, schrieb Eric Wong:
> Stefan Maier <stefanmaier at gmail.com> wrote:
>> Hi,
>> I am running unicorn with rails and memcached. The combination usually
>> works flawlessly but sometimes when I retrieve an item from memcached i
>> get a different, unrelated item.
>> At the moment I'm more or less investigating in all directions and after
>> reading
>> http://www.modrails.com/documentation/Users%20guide.html#%5Fexample%5F1%5Fmemcached%5Fconnection%5Fsharing%5Fharmful
>> I thought that maybe the forking nature of unicorn has something to do
>> with it.
> Hi Stefan,
> If you're using "preload_app true" in your config file, then all the
> gotchas from Passenger with sharing memcached sockets across processes
> apply to Unicorn as well.
>> So, are there any steps you have to take to ensure unicorn works with
>> memcached?
> Which memcached library are you using?
> I believe some memcached libraries will delay opening a socket until
> it's actually needed (inside the worker processes), but if you use
> memcached in your app initialization code, then the socket will be
> opened in the master process (which is bad).
> So the safe thing would be to reconnect to your memcached servers in the
> after_fork hook.

This is what i thought and lsof also confirms that the workers have
their own connections.
So it's not a unicorn problem,
At the moment it seems like memcached gets confused by a malformed key.

Thanks for the quick reply,


More information about the mongrel-unicorn mailing list