Optimising use and using multiple memcache servers in a pool
marcus at synchromedia.co.uk
Fri Jan 19 12:19:56 UTC 2007
On 19 Jan 2007, at 11:58, Alan Jay wrote:
> In my simple implementation I have 7 web servers each running their
> own copy of “memcached” on each server the local php code selects
> that local memcached server and checks to see if the article it is
> loading has been cached. And loads it if it has. The Article
> Management System when someone edits an article resets the expire
> time from 6hrs to 5 seconds on each of the servers in turn when the
> article is updated.
> This seems to be working OK this morning and we will get more stats
> over time but the pecl-memcahced interface has the ability to run
> multiple servers by adding and opening them all for selection. But
> if (as I am) my script opens a single file it seems like quite a
> lot of potential overhead and I’m not sure what the advantages to
> doing it like that are.
Hm. I think you've also missed what memcached does to some extent
(see below). I'm not sure where the breakpoint will lie. I'd be
tempted to try running just a few instances (say 3-4) that are used
by all servers. That way you lower the overhead of having so many
connections to make, though of course it's also dependent on how much
stuff you are putting in the cache. Remember that a single cache/
retrieve operation will only ever result in a single request to one
memcached server, no matter how many servers you have.
> At present the code already fails safe in that if it is unable to
> connect to the local memecached server it just gets the data from
> mySQL server direct.
> What advantages are there to using the multiple memcached servers
> added to the connection pool?
One server can benefit from getting something from the cache that was
put there by another server. By not sharing your servers, you're
missing out on this big feature. Also, if you're only doing local
caching, you're far better off doing it in APC as it will be much
faster. Also, by not sharing your caches, you're just asking for
coherency problems - where different servers end up with different
versions of the same item, e.g.
server A fetches object 1, stores in local cache
server B fetches object 1, stores in local cache
server A saves a change to object 1, updates its local cache
Server B now has outdated version of object 1.
By having all servers use the same list of memcached servers, you
avoid this problem.
Synchromedia Limited: Creators of http://www.smartmessages.net/
marcus at synchromedia.co.uk | http://www.synchromedia.co.uk/
More information about the memcached