We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cache experience - DATA vs. NONE

Hi, i would like to share my current experience with caching.

We currently launched a rewrite of our discussion forum with approx 10 thousand visits daily, used Phalcon 1.2.4. The site is stable, but in comparation with previous results (measured by NewRelic monitoring agent), we saw massive increase in web transaction time (server processing - php + db + memcached + external services). php stayed low, db as well (both together under 200ms), but memcached increased drastically up to 2000ms for each transaction. CPU load (machine has 2xCPU 2620, 24 mT cores alltogether, used to run under 1.00 load) went up massively to values around 7.00-8.00

I wondered why :)

Tried to change memcache setup, size, free it, etc, no help, still saw massive memcache usage and the monitoring page showed that WRITE to memcache went to MegaBytes per second, while READ was low (60kb/s). Amount of requests was low as well, not more than 70/s. What the heck !

When reading about possible caching mechanism, maybe to replace memcache with redis, mongo or any other "new magic" (dont get me wrong, im oldschool php programmer :D ), i realised one small note in caching using


The values are being SERIALISED. Well, gotcha ! Im storing arrays, sometimes huge arrays of values, sometimes parts of html code and so on. Serialization in php never worked really fast. Changed my code to


restarted app, restarted memcache to get rid of old serialised data, and voila :

The measured memcached delay went down from 2000ms to non measurable 58ms ... CPU load went down to 1.50 average ... Site reports time to first byte down from 1.5 second to 0.6 second, which I consider to be normal for my site. Memcache reporting shows reads and writes in similiar numbers, around 100kb/s. Cool.

So in case you are having slow caching mechanism, please check, if your data are being serialised, and if they are needed to be serialised, or not.

edited Mar '15

well my happiness was premature ... after few hours, the cache is back to insane number of writes (1Mb on read side, 6Mb on write side) and speed starts to fall down again ... seems like phalcon or memcache (does it remember all the keys maybe ??) is unable to handle several tens of thousands of keys :( time to upgrade phalcon first and if not doesnt help, i will try redis ...

After night spent on this, memcache seems to be doomed on my server for some reason ... when doing simple test with 1000 inserts and 1000 reads of 1000 keys into memcache and redis, redis took 0.05 seconds to do so ... memcache took appalling 300 seconds !!! i switched to redis for now.