I have an apache with PHP-FPM module, 8 CPU cores. Average CPU all together load is around 75% CPU mainly due MySQL see the screen.
It is actually little bit smaller load now than usually.
But problem is, when I open homepage the load is randomly around 1s (time to first byte i guess).
I thought it could be waiting due mysql connection etc, but it seems the extra time for waiting is the time, before the PHP gets the voice from Apache.
I made two interesting tests:
- Simple html file (empty file with some word) takes 100ms to load.
- Simple php file (no connection to mysql etc, just empty php file with simple echo) takes around 1s to load.
So problem is obviously with the php or apache+php combination.
Why, and how to fix it.
I tried to increase some PHP fpm settings like
pm = dynamic
pm.max_children = 5
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 200
Move the values from default bit up. Yes the CPU load went instantly up almost to 99% all CPUs but speed was not fixed + server was totally loaded.
What to do?
Btw from Apache mod-status i see that currently there is 25 requests per second handled (normally double though). And i dont think i should wait 1s to load empty php script with 8 CPU cores.
Server version: Apache/2.4.29
PHP7.2-fpm
MPM-Event
8vCPU, 16 GB RAM
BTW the empty php file takes also around 3-4s so not only 1s.