600+ memcache req/s problems - help! 600+ memcache req/s problems - help! nginx nginx

600+ memcache req/s problems - help!


Switch away from using TCP sockets and going to UNIX sockets (assuming you are on a unix based server)

Start memcached with a socket enabled:Add -s /tmp/memcached.socket to your memcached startup line (Note, sockets disables networking support)

Then in PHP, connect using persistent connections, and to the new memcache socket:

$memcache_obj = new Memcache;$memcache_obj->pconnect('unix:///tmp/memcached.socket', 0);

Another recommendation, if you have multiple "types" of cached objects, start a memcached instance for each "type" and distribute your hot items amongst them.

Drupal does this, you can see how their config file and memcached init is setup here.

Also, it sounds to me like your memcached timeout is set WAY to high. If it's anything above 1 or 2 seconds, you can lock scripts up. The timeout should be reached, and the script should default to retrieving the object via another method (SQL, file, etc)

The other thing is verify that your memcache isn't being put into a swap file, if your cache is smaller than your average free ram, try starting memcache with the -k option, this will force it's cache to always stay in ram and can't be swapped.

If you have a multi-core server, also make sure memcached is compiled with thread support, and enable it using -t <numcores>


600 requests per second is profoundly low for memcached.

If you're establishing a connection for every request, you'll spend more time connecting than requesting and burn through your ephemeral ports very rapidly which might be the problem you're seeing.


There's a couple of things you could try:

  • If you have memcached running locally, you can use the named socket 'localhost' instead of '127.0.0.1'
  • Use persisntent connections