Ultrafast Frog With Funky Cache

Blog Projects
frog php

Funky caching is technique popularized by PHP.net site. It was first mentioned by Rasmus Lerdorf in 2002 PHPCon slides (page 25). Content is cached as static file on the first access. All following requests are served using the cached static file. Editing a page will automatically expire cached files. Page is then re-cached on the next hit.

Frog CMS is PHP port of Rails based Radiant CMS. Radiant is great but there is always the hosting problem. Even with mod_rails existing it is still easier to get quality PHP hosting. Both Frog and Radiant are the only CMS’es I can say I like. Expression Engine I can live with. Edicy looks really promising. Everything else I rather not touch.

How About the Speed?

Frog is reasonably fast. Simple ApacheBench running on localhost (to rule out network latency) shows it can deliver around 90 requests per second.

> ab -n 1000 -c 20 http://dev.example.com/about_us.html

Time taken for tests:   10.600109 seconds
Requests per second:    94.34 [#/sec] (mean)
Time per request:       212.002 [ms] (mean)
Time per request:       10.600 [ms] (mean, across all concurrent requests)
Transfer rate:          255.66 [Kbytes/sec] received

I have seen slower. This would not stand Digg effect though.

File Cache Plugin

Using Gilles Doge’s File Cache plugin gives improvement. Test server gives 150 requests per second. Problem is requests are still routed to backend. PHP logic decides whether to show cached contents or not.

> ab -n 1000 -c 20 http://dev.example.com/about_us.html

Time taken for tests:   6.707378 seconds
Requests per second:    149.09 [#/sec] (mean)
Time per request:       134.148 [ms] (mean)
Time per request:       6.707 [ms] (mean, across all concurrent requests)
Transfer rate:          617.08 [Kbytes/sec] received

This still would not stand Digg effect.

Enter Funky Cache Plugin

Something needed to be done. Since I have had good experiences with Mephisto which uses funky caching I decided to give it a try. This is where Frog first showed its power. Software was totally new to me. Still their plugin API was so clear to understand I was able to create first working version in one evening. Second evening was spent polishing the code.

So does it work? With Funky Caching enabled test server delivered 1750 requests per second.

> ab -n 1000 -c 20 http://dev.example.com/about_us.html

Time taken for tests:   0.568727 seconds
Requests per second:    1758.31 [#/sec] (mean)
Time per request:       11.375 [ms] (mean)
Time per request:       0.569 [ms] (mean, across all concurrent requests)
Transfer rate:          7284.69 [Kbytes/sec] received

That should be enough to withstand both Digg effect and Slashdotting at the same time.

Yes Gimme Some!

Installation instructions at project page. If you want to peek under the hood check the source at GitHub. Code is still beta quality. Please leave a comment if you find a bug or you have improvement ideas.



When asking a question include an URL to example page where the problem occurs. Even better is to make a Fiddle which demonstrates the problem. If you have longer code examples please use pastie.org.