Ultrafast Frog With Funky Cache

November 21st, 2008

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.


8 Responses to “Ultrafast Frog With Funky Cache”

  1. Marc Friederich says:

    Terve

    Nice to see another way of cache approach. Since our cache system could (with some improvement) cache some snippets or some pages and some not (depends what you decide). We based the idea on keeping granularity and decide which part should be cached and which not. But you’re test expose that our way is at the expense of speed … Anyhow .. I subscribe to your RSS and follow your improvement of CMS Frog.

    Even if we are swiss, we trully love Finland and Estonia also. We’ll contact you soon to find ways to import minttu here.

  2. Mika Tuupola says:

    Marc: Terve :)

    You are correct. My approach goes for maximum speed. Unfortunately it also means caching all or nothing. You cannot use it on pages which have parts which need to be generated dynamically (unless you use JavaScript for dynamic parts).

  3. Helms says:

    I’ve installed the funky cache plugin step by step, but after I enable the plugin, the tab never shows in the admin.

    Any ideas?

  4. Nick says:

    Is the funky cache plugin compatible with SQLite and PDO? I seem to be having issues with the install as well.

  5. Mika Tuupola says:

    Nick: There are many problems with Frog and SQLite. I do not test my plugins with SQLite. If there is problem with installing it is most likely caused by the SQL clauses in enable.php.

    You might want to check them. If you manage to make them SQLite compatible please send a patch!

  6. Mika Tuupola says:

    Helms: Are you using SQLite or MySQL. Windows or *NIX? Do you get any errors? etc etc…

  7. turcio says:

    Hi, I experience the same problem as Helms. No “Cache” tab after enabling plugin in Administration (after refresh of course). I’m on Ubuntu 9.04 Linux machine and MySQL. Other plugins show their tabs.

  8. Mika Tuupola says:

    turcio: What folder have you installed the plugin into? Do you have rights alter and add tables to database?

Sorry, comments are closed for this article.