On 21 juil, 10:59, Guille -bisho- <[email protected]> wrote: > On Wed, Jul 21, 2010 at 10:37, dormando <[email protected]> wrote: > >> I'm having an issue with my memcached farm. I'm using 3 memcached > >> servers (v1.2.6) and python-memcached client (v1.43). > > >> When using get_multi function, memcached returns sometimes keys that I > >> wasn't asking for. Memcached can return less data than expected (if > >> key-value does not exist), but documentation says nothing about > >> returning more data than it should. What can cause this? > > We have experienced similar behaviours with php memcache under heavy > load. Sometimes the clients seems to mix requests from different > replies.
This happens when your client forks and forgets to reopen a connection, but re-uses the one that was open before the fork. As a results, several clients use the same socket which ends up interleaving the traffic. This is completely evil, not about memcache, really (it will happen just the same with any network protocol), and is solved by disconnecting and reconnecting. Also, it is only visible under heavy load because this is when you have a chance of seeing actually concurrent requests despite the very short roundtrip of a typical memcached query. Solutions: #1 make very sure you open the connection after the fork, or #2 have a simple check in your memcached layer that checks the PID hasn't changed. If it has, do a disconnect_all() or whatever it's called in your language, and then run your queries. There is some overhead when you adopt solution #2, but #1 is not always applicable if you have spaghetti code and/or lax coding policies. David
