Memcached slower than Caching in files?

Silvan Mühlemann silvan.muehlemann at
Mon Oct 30 07:59:39 UTC 2006


We are running a high-traffic photo album website (100 million page 
impressions a month).

Currently we are using Cache/Lite to cache query results or pregenerated 
HTML pages. Cache/Lite (*Cache*_*Lite)* is storing 
the data in files. These files are either stored on the local drive or 
on a NFS share.

We are thinking about moving memcached for performance reasons.

To compare both methods (file vs. memcache) I have written a benchmark. 
Here's the setup:

- PHP 5.1.6 on Linux 2.6.14, memcached 1.1.12
- 10 different sample items to cache
- every item is a random ASCII-String of 100'000 characters.
- every iteration has the following steps
  - choose one of the 10 items to cache by random
  - if they are already in the cache, retrieve them
  - if not, store them in the cache
- there are 1000 iterations.
- the random number generator produces the same sequence of numbers for 
each test case to ensure comparability among the tests
- the test scenario produces a hit rate of exactly 99.0%.
- memcached setup:
  - the memcached has 64MB of memory
  - the connection to the memcached is only being set up once per test case.
- disks: IDE-Disks (hdparm -t: 40MB/s)

a) Cache items in local files: 345ms
b) Cache items in local memcache: 1003ms
c) Cache items in remote (NFS) files: 3854ms
d) Cache items in remote memcache: 16607ms

I am surprised caching in memcache is over 3 times slower than caching 
in files. I expected memcache to be much faster. Or ist the test 
scenario not adequate for memcache?

Is there something I overlooked when I did my tests? With this result I 
should stick to caching in files instead of using memcache.


More information about the memcached mailing list