Zed A. Shaw
2007-Jan-02 18:41 UTC
[Mongrel] Recommendation: Stalled Mongrel? Memcache Hates Spaces
Hi Everyone, There''s quite a few of you who have contacted me about Mongrel suddenly stopping. After a lot of investigation, I found that the common thread between all of you is memcache and Eric Hodel''s memcache-client. People who were running this combination would have intermittent pauses and investigating the stalled mongrels showed that memcache-client was waiting for information from memcached. A friend just told me that he found out the problem is memcache does not accept keys with spaces in them. From this spec: http://cvs.danga.com/browse.cgi/wcmtools/memcached/doc/protocol.txt?rev=HEAD We have this paragraph: "Data stored by memcached is identified with the help of a key. A key is a text string which should uniquely identify the data for clients that are interested in storing and retrieving it. Currently the length limit of a key is set at 250 characters (of course, normally clients wouldn''t need to use such long keys); the key must not include control characters or whitespace." Notice the last part "the key most not include control characters or whitespace". Since memcache-client doesn''t currently escape your keys for you (not sure if it should actually), you have to do this yourself or bad super evil things happen. The few people who have made this change report no more stopped mongrel processes. Please try this out and report back to me if it fixes things. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.
Michael Moen
2007-Jan-04 17:45 UTC
[Mongrel] Recommendation: Stalled Mongrel? Memcache Hates Spaces
On Jan 2, 2007, at 10:41 AM, Zed A. Shaw wrote:> Since memcache-client doesn''t currently escape your keys for you > (not sure if it should actually), you have to do this yourself or > bad super evil things happen. The few people who have made this > change report no more stopped mongrel processes. > > Please try this out and report back to me if it fixes things.Zed- I rolled out a patch on the JibJab cluster yesterday to address this and I haven''t had to go after any dogs with a rubber hose since, and beating bad dogs has been a regular task for a while now. I have no idea where spaces or control characters could get into the keys, but I''m not the only monkey banging on a keyboard here so who knows. In case anybody wants a painless way to handle this, I added the following to my overrides: class MemCache protected def make_cache_key(key) key.gsub!(/[^\w:]/, ''_'') @namespace.nil? ? key.to_s : "#{@namespace}:#{key}" end end