Memcache page caching slow - troubleshooting suggestions?

My php.ini shows memcache (not the pecl memcached) running and configured. A simple (non Yii) PHP script fetches values out of memcache correctly. I’ve also run some of the scripts from the memcache site and there were no failures. phpinfo() shows: memcache version 3.0.1 - so I think memcache is running fine.

However, when I have caching enabled, I am not getting the request per second I would expect. I’m using Yii 1.1.6

Testing one page with apache benchmark "ab":

  • Static html version of page (non Yii): 1200 requests / second

  • Yii Page Caching using file caching: 90 requests / second

  • Yii Page Caching using memcache: 60 requests/second

  • Yii No caching for the same page: 17 requests / second

Admittedly I am doing this test on a lower end notebook, so the numbers are bit small, but regardless the memcache number should be higher than the file caching option. And I assume memcache is "working" since 60 is higher than 17, but I would think that number should be higher than 90 at the least.

When running the "ab" test, with either caching option no database queries are being made.

Is there a way to log or test the Yii caching to see exactly what it is doing? Or any other troubleshooting steps to see why memcache is slower than file caching?

You can try setting persistent to true. If the memcache deamon is running locally, you could also try to connect via linux socket instead of tcp/ip (see here under Parameters section for more info).

Though I think it’s expected that file based caching beats memcache in such a benchmark. For example, reading a single (cache-)file 1000 times in a row is much faster than reading 1000 files at different/random locations because the operating system does caching as well. Also memcache may has some additional connection overhead, whereas file access is managed by the os kernel.

There could be many reason why file based caching is faster. When the server load reaches a certain point (for example very high file io load) then memcache might be faster on a local server. The problem is you simply can’t simulate natural server load with an ab benchmark.

// Regarding your last question, take a look at this wiki on how to setup a web-logroute. Then, while in debug mode, you can see how long cache reads/writes take.