I've found lots of discussion here and elsewhere about the tradeoffs between Apache vs. Nginx, worker vs. prefork, mod_php vs. FastCGI + PHP-FPM, etc., but I'm finding it difficult to determine how I should go about tuning my own site to optimize performance.
I have a PHP+MySQL website that is CPU bound; the data is very static (though the dataset is quite large) but delivering a page requires looping through thousands of records. I was running it on CentOS 5.x with Apache and mod_php using prefork, on a VPS with 2GB of RAM and 4 (virtual) cores.
It ran pretty well but the occasional traffic spikes caused it to choke, so I took the opportunity to try out PHP-FPM + FastCGI with mpm_worker. I spun up a new VPS from the same hosting provider with the same specs, but used Ubuntu 12.04 LTS since it had all the necessary modules in its repo.
Long story short, my load average is much higher now than it was under the old setup, which is surprising. I figured removing the overhead of spinning up a new PHP instance would be a significant boost. I seem to have plenty of free memory but the PHP-FPM processes are constantly pegging the CPUs.
Following is my Apache config. I typically see around 10-30 requests being served at a time.
StartServers 6 ThreadLimit 64 ThreadsPerChild 10 MaxClients 60
I reduced the number of PHP-FPM processes from 10 to 5 (set to static with named pipe) under the assumption that it's better to have a few requests wait a bit longer than trying to serve too many at once. That seems to have helped a bit but my load average still goes above 4 too often.
So my question is, how do I systematically dig into this issue without just randomly playing with a bunch of numbers and spending a lot of money on load tests while I figure it out? Any good articles/pointers on what to try first? I'm looking for things like what percentage of memory Apache, MySQL, and PHP-FPM should each be taking; how many FPM workers to run vs. the number of Apache workers; whether to adjust processes or threads in mpm_worker and what that ratio should be; etc.
Even though the data is static, caching pages to disk isn't really a viable option due to the size and variability of the output.