Score:0

slow php (php-fpm) (long apache php waiting)

co flag

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.

enter image description here

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.

djdomi avatar
za flag
what kind of queries are you running that a MYSQLD is eating your system?
luky avatar
co flag
some anagram queries, on takes on average 0.5s some may take also 1.5s but usually around 0.5s.
djdomi avatar
za flag
are you using memcached? or similar for caching?
luky avatar
co flag
yes i am, and even the cache setting is so effective that 84% requests go from cache not from db. its not much visible on cpu load. maybe 10-15% smaller.
in flag
Amigo tengo i3 + 4gb de ram y ajuste de esta forma.[enter image description here](https://i.stack.imgur.com/kG2FR.png)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.