Faster way to serve up simple requests?

Sean Chittenden sean at gigave.com
Mon Jul 11 14:14:55 PDT 2005


> > It must be remembered though that a common configuration of
> > passing all requests through some kind of "application server"
> > (ie.  Apache+PHP+memcached) just to serve what is essentially
> > static content is such a waste in my opinion. The reduced overhead
> > of not needing Apache+PHP can be dramatic. Both of these take up
> > valuable CPU and memory (how many Apache processes do you have
> > running? with each one taking up how many megabytes of memory?). A
> > modern filesystem cache may make better use of the CPU and memory
> > resources.
> 
> Another option would be to hook libmemcache directly into thttpd or
> mathopd.  A filesystem-based cache would do more local caching than
> memcached could provide, but with memcached multiple frontends will
> have a coherent picture of the cached data.  There are pros and cons
> for everything, really.

I have to concur, using memcache as a backend is a poor use of
memcache.  Assuming your files are smaller than an Ethernet frame,
you're probably going to max out at ~4K req/sec (sent in serial from a
single process).  A standard FE circuit yields ~8Kpps.  Introduce a
read(2) off of the socket, plus a write(2) to send the data out the
front end and are likely only going to get less than 4K responses/sec.
The read(2) results in a kernel to userland copy, followed by a
userland to kernel copy for the write(2) command.  If your write(2)
call is disk backed on an OS that doesn't suck, you get to take
advantage of zero-copy-sockets so the write(2) has the opportunity to
happen inside of the span of a single interrupt and no data gets
copied (file data is DMA'ed from disk directly into the Ethernet
card's output buffer).

Don't, I repeat, *do not* use memcache as a backend unless you're
looking for mediocre performance... and if you do, don't come crying
when life starts to suck.  memcache != panacea.  Ram disk, hell, even
a kernel NFS client that performs local caching of data would be
better than memcache.  memcache is quick because it does a specific
thing well, don't over use a tool for more tasks than it was intended.

-sc

-- 
Sean Chittenden


More information about the memcached mailing list