views:

488

answers:

2

For a single-server LAMP site (which is usually under quite high load), what is best way to use memcache?

Does it make sense to run the memcache daemon on the same server as the application, or is that just going to take valuable memory away from MySQL, giving a net performance loss. Does it even make sense to use memcache in this scenario- or is the best solution to always have dedicated servers for memcache?

I appreciate that profiling the site before and after would be required to really answer this question, but I would rather not do that at this stage on the live site. Especially as someone out there certainly knows the answer off the top of their head.

+2  A: 

Usually, the recommendation (see What about shared memory? in the memcached page) is to run memcached on the same machines as web servers, on the premise that web applications are CPU-heavy (which memcached is not), whereas memcached is memory-heavy (which most web applications are not, at least in comparison).

So, if your web server has plenty of memory, it's a good idea to run memcached on it. YMMV.

Chris Jester-Young
A: 

Another option to memcached - depending on the scale on information you are caching, is caching in APC. You should be running that (or a similar op-code cache) to help speed the PHP page delivery anyhow, so if you are caching somewhere from a few, to a hundred or more smaller (I've got a few at around 15KB each, out of more than 70) variables at a time, you may find some benefit to storing them in APC.

I've got a site that caches some DB lookups, and also caches a post-parsing config.ini file - and on my (busy) site, I'll save literally millions of potential DB hits per day.

Alister Bulman