Alpha01
Alpha01

Reputation: 820

Memcached request loop or cache stampede in WordPress

I have a clustered WordPress webapp that is using a Memcached cluster consisting of six nodes to store WordPress's object cache, but I'm seem to be experiencing some sort of sporadic Memcached set/replace loop or cache stampede that occasionally causes a single node in the Memcached cluster to completely saturate the Memcached and database network link.

The set/replace loop or stampede seems to be caused by lots of attempts trying to “add” the WordPress “wp_:options:alloptions” key which Memcached replies with NOT_STORED to all those particular queries. While at the same time majority of MySQL queries look like this:

SELECT option_name, option_value 
FROM wp_options 
WHERE autoload = 'yes'

The only change that I've made to the Memcached Object Cache plugin (http://wordpress.org/extend/plugins/memcached/), is the default expiration setting.

#var $default_expiration = 0; //original
var $default_expiration = 1800;

So far I have been able to mitigate the problem by increasing the Memcached daemon maximum connection limit. I also changed the database storage engines from MyISAM to InnoDB, and also increased the APC shm_size from 128M to 1536M.

Is the object cache set/replace loop or stampede inevitable or is it a consequence of my current setup?

Environment:

Upvotes: 3

Views: 703

Answers (1)

AlexL
AlexL

Reputation: 1707

MatsLindh is right. Add random expiration to the options to minimize the number of entries that expire at the same time. You can also minimize stampedes with locks while the 1st racer writes the cache.

Upvotes: 0

Related Questions