We have a VPS (2GB RAM/2 vCPU's). That is serving a phpBB forum on PHP 5.6, Centos 6, Apache 2.2. However sometimes the forum is super slow to respond. Using Chrome network browser I found that TTFB sometimes goes up to 30 seconds. Weirdly enough also cached items have this problem. (see screenshot)
I already tried :
- load of the server during the issue is not above .20, and there is free memory.
I pinged the server : around 10ms
install zend opcache (99.9% hits)
- install memcached (stats)
I installed mytop to see if MySQL is the problem but as far as I understand MySQL is not doing much
Queries: 6.0M qps: 26 Slow: 4.0 Se/In/Up/De(%): 75/02/08/01 qps now: 2 Slow qps: 0.0 Threads: 1 ( 1/ 0) 00/00/00/00 Key Efficiency: 99.4% Bps in/out: 4.4k/51.1k Now in/out: 48.4/ 7.5k
Since its not always the case, the only way to replicate this issue, is spamming F5, although I'm not sure that is really replicating the problem. I could in lesser extend (2s ttfb) replicate this with the same page copy'd in html (removed the dynamic part).
http://s21.postimg.org/ql6eywn3b/ttfb.png
I have keepalive on (100 max, 15 seconds), with maxclients 30. Where do I go from here ?
Profiling. There are various PHP profiling tools. I like blackfire.io - it will easily and clearly pinpoint any bottlenecks, whether it's PHP code, MySQL queries or a combination of the two. Without profiling, you're randomly trying things in the dark.
Rather than F5ing, you can also do some load testing with tools like ab, yandex tank, Siege etc.
Another thing to do to verify this problem is real is to test in webpagetest.org and repeating the test multiple times (advanced settings, number of runs). Or through their API.
The issue was a combined problem :
The VPS got moved to a better IO one, and firewall was not set as strictly and the problem was solved. I also disabled memcached as MySQL was clearly not the choke point)