15 02 2012
CakePHP Benchmarks on Storing Persistent Cache in APC. Hint: It’s Faster!
It’s been a while since I last posted on here so I thought I’d get something up here before my next big blog post. Since starting a new job back in September I’ve been working in CakePHP 1.3 (soon to be 2.0). The other day I had the opportunity to explore optimizing CakePHP. My employers solution is a modified version of CakePHP that powers 100s of websites off of a single install. Unfortunately our component initialization and startup (according to the CakePHP Debug Kit) was looking something like this:
After following the instructions in this excellent blog post on 8 ways to speed up CakePHP we saw a speed improvement of roughly 760% in the Component initialization and startup phase of CakePHP. You can see what all its storing in memory by going to the APC info page on your local machine or server and clicking on User Cache Entries. The great thing about this change is its literally 1 extra line of code to your bootstrap.php file:
Cache::config('_cake_core_', array('engine'=> 'Apc','duration'=> 3600,'probability'=> 100));
Here are the numbers from the excellent shell utility provided by the CakePHP Debug Kit. To get the benchmark I executed each page listed in the table 100 times to derive averages (Note: I obfuscated the actual page names). Tests were done on my local computer running the LAMP stack on Ubuntu 11.04 64bit (2.6.38-13-generic kernal) with a Quad Core Intel i5 3.10Ghz processor, 8GBs (2x4GB) RAM, and 500GB SATA Drive. For services the machine runs MySQL 5.1.54, PHP 5.3.8, and APC 3.1.3.
|Page / Metric||No APC||APC Default||Cake APC Cache|
|Total Time (lower is better)||85.31||78.40||61.34|
|Requests/Second (higher is better)||1.17||1.28||1.63|
|Average request time (lower is better)||0.85||0.78||0.61|
|Average request time||0.74||0.68||0.52|
|Average request time||2.56||2.51||2.35|
|Average request time||1.68||1.59||1.42|