APC Rocks my world!

May 17th, 2008

Posted at 12:00am by Stan

I've been spending any free time I have working on performance for HT's site. Over the last week with some increased traffic to the site and increased staff work for the conferences I've been noticing some serious lag. Benchmarking with Apache AB revealed how bad things were getting, and then with a little profiling love from APD I was able to identify exactly where things were going down hill.

It seems like every couple of months I find myself re-evaluating our framework and searching for bottlenecks. This time I was lead to MySQL in general, and the communication delay between PHP's MySQLi extension and the actual server. Probably 6+ months ago I implemented a caching layer into PageSite, we were still on a shared web host when I did this, so the joys of something like APC were out of my grasp. What I resorted to was a database table to store stuff in. In a single query all of the "cache" was loaded and then if changes were made things were saved when the object was destroyed at the end of execution. It worked well, I really can't complain... but there were better options available that weren't as slow as communicating with MySQL.

Welcome to APC, also known as the Alternative PHP Cache. It was designed to be a simpler solution to the problem that memcache solved, memory storage for PHP applications. Shared hosts don't use this extension for a variety of reasons, but now that HT is on a vded it makes it a possibility for ys. Thanks to APC's caching of includes, optimizing of *_once()'s and the memory storage, HT's site has sped up about 10+x from what it was last week when benchmarked by APC and I've seen execution times drop drastically on the server.

There are still some issues to be solved, including code optimization and better communication with MySQL. I'm always working to improve code performance, and as for the MySQL issue... well, I'm holding out for PHP 5.3, with the MySQL Native Driver (mysqlnd) which should cure most of my speed woes. In the meantime, if you're out there and have access to your install of PHP I highly recommend giving APC a spin, simple run pecl install apc from your command line (assuming you have PEAR installed) and you're good to go. Double props to the guys behind APC!

Post Comment:


Enter the code you see in the image below.