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:

 

 

Storing Cake Persistent Cache in APC

 

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



/index x100 x100 x100
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

/someother-page
Total Time 74.39 68.14 52.31
Requests/Second 1.34 1.47 1.91
Average request time 0.74 0.68 0.52
/some-category-page
Total Time 100.01 100.52 100.82
Requests/Second 0.39 0.40 0.43
Average request time 2.56 2.51 2.35
/some-item-page
Total Time 99.35 100.33 99.16
Requests/Second 0.59 0.63 0.71
Average request time 1.68 1.59 1.42