Score:0

php-fpm optimization : "seems busy" warnings, CPU peaks and low RAM usage

fm flag

I have ubuntu 18.04 LTS with apache 2.4.29 and php fpm 7.2.24 running on VMware websphere vm with 16 Core (2.4GHz) and 16GB of RAM. Apache is configured with mpm_event:

<IfModule mpm_event_module>
    ServerLimit     1000
    StartServers             4
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestWorkers     1500
    MaxConnectionsPerChild   1000
</IfModule>

php-fpm is set in dynamic mode with this parameters:

pm.max_children = 256  
pm.start_servers = 64
pm.min_spare_servers = 32
pm.max_spare_servers = 64

these values are based on various docs found online (start : core * 4, min core * 2, max core * 4). max children are calculated assuming max memory a single php script could use (60Mb)

memcached is present (512Mb reserved, 100Mb tipically used), no other consuming memory services are present (mysql is on his own server) and memory status is:

              total        used        free      shared  buff/cache   available
Mem:            15G        1.4G        8.1G         50M        6.1G         13G
Swap:            0B          0B          0B

So basically only 10% of memory is used. Using the well known ps_mem.py I see these value:

 .....
 12.0 MiB +   2.3 MiB =  14.2 MiB   php7.2
 35.0 MiB + 202.5 KiB =  35.2 MiB   Xvfb
 46.7 MiB +  22.5 KiB =  46.7 MiB   snapd
 51.7 MiB +   4.1 MiB =  55.8 MiB   apache2 (4)
 94.6 MiB +  16.5 KiB =  94.7 MiB   memcached
688.0 MiB +  56.7 MiB = 744.7 MiB   php-fpm7.2 (65)
---------------------------------
                          1.1 GiB
=================================

recently, where the server is under stress (many web requests), I saw this warning in /var/log/php7.2-fpm.log:

[03-Jul-2023 11:25:31] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 4 idle, and 72 total children
[03-Jul-2023 11:25:32] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 27 idle, and 80 total children
[03-Jul-2023 11:38:45] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 73 total children
[03-Jul-2023 11:38:50] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 81 total children

As far as I know those are just warning but in the meanwhile server load goes to 22 (which means more than 100% of all available cores, just few seconds..).

I'm investigating to understand if there's something on php code that could be optimized using php-slow.log.

So my questions are:

  • how can I solve those warnings (and the cores peaks!)? I've tried to set pm.max_spare_servers = 128, so when spikes happen some children should be availables, is this the right way?
  • how can I optimize RAM usage? I suspect that it could be better

Any suggestions will be greatly appreciated, thanks

I sit in a Tesla and translated this thread with Ai:

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.