1

Seeking Advice on High Number of PHP-FPM Processes in Magento Environment (Magento 2.4.6 & php 8.2 ) Hello Magento Community,

I hope this message finds you well. I'm currently managing a Magento store and have observed a high number of PHP-FPM processes on my server, even during periods of moderate traffic. I'm seeking advice and insights from the community to better understand and optimize the PHP-FPM configuration for Magento.

Here are some specifics about my environment:

PHP-FPM Configs:

listen = 127.0.0.1:9000 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35

catch_workers_output = yes php_admin_flag[log_errors] = on php_admin_flag[display_errors] = off php_admin_value[error_reporting] = E_ALL & ~E_DEPRECATED & ~E_STRICT php_admin_value[error_log] = /var/log/php-fpm/error.log access.log = /var/log/php-fpm/access.log php_value[memory_limit] = 768M php_value[post_max_size] = 24M php_value[upload_max_filesize] = 24

The servers are equipped with [8-cores and 16gb Memory with load balancer], and I'm noticing Spikes on different time intervals high load of PHP-FPM processes even during non-peak hours. I want to ensure that the configuration is optimized for both performance and resource efficiency. TOP Command at time of issue:

top - 11:48:34 up 874 days, 21:08, 1 user, load average: 49.72, 49.53, 42.80 Tasks: 214 total, 50 running, 110 sleeping, 0 stopped, 0 zombie Cpu(s): 96.8%us, 2.9%sy, 0.1%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.2%si, 0.0%st Mem: 15951580k total, 15737856k used, 213724k free, 142396k buffers Swap: 0k total, 0k used, 0k free, 9243988k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30056 apache 20 0 769m 215m 159m R 18.3 1.4 4:34.05 php-fpm 30050 apache 20 0 781m 262m 193m R 18.0 1.7 4:32.23 php-fpm 30060 apache 20 0 786m 240m 166m R 17.3 1.5 4:32.23 php-fpm 30064 apache 20 0 784m 248m 178m R 17.3 1.6 4:31.67 php-fpm 29242 apache 20 0 806m 271m 177m R 17.0 1.7 5:22.64 php-fpm 29243 apache 20 0 787m 276m 203m R 17.0 1.8 5:32.13 php-fpm 29388 apache 20 0 789m 280m 204m R 17.0 1.8 5:11.79 php-fpm 29389 apache 20 0 771m 282m 226m R 17.0 1.8 5:14.63 php-fpm 30067 apache 20 0 777m 242m 176m R 17.0 1.6 4:33.43 php-fpm 29380 apache 20 0 771m 242m 184m R 16.6 1.6 5:18.49 php-fpm 29391 apache 20 0 785m 241m 174m R 16.6 1.6 5:16.27 php-fpm 30055 apache 20 0 767m 200m 147m R 16.6 1.3 4:32.00 php-fpm 29236 apache 20 0 778m 240m 176m R 16.3 1.5 5:32.46 php-fpm 7329 apache 20 0 807m 338m 245m R 16.0 2.2 15:59.15 php-fpm 29239 apache 20 0 782m 255m 186m R 16.0 1.6 5:46.10 php-fpm 29245 apache 20 0 785m 273m 201m R 16.0 1.8 5:20.65 php-fpm 29392 apache 20 0 785m 274m 201m R 16.0 1.8 5:02.05 php-fpm 30054 apache 20 0 771m 239m 180m R 16.0 1.5 4:35.17 php-fpm 29233 apache 20 0 782m 240m 170m R 15.6 1.5 5:33.47 php-fpm 29234 apache 20 0 796m 276m 192m R 15.6 1.8 5:33.33 php-fpm 29235 apache 20 0 792m 303m 224m R 15.6 1.9 5:16.15 php-fpm 29237 apache 20 0 821m 295m 186m R 15.6 1.9 5:34.35 php-fpm 29238 apache 20 0 768m 227m 175m S 15.6 1.5 5:22.32 php-fpm 29384 apache 20 0 788m 265m 189m R 15.6 1.7 5:33.77 php-fpm 29387 apache 20 0 805m 285m 195m R 15.6 1.8 5:14.28 php-fpm 30048 apache 20 0 770m 285m 227m R 15.6 1.8 4:33.40 php-fpm 30053 apache 20 0 774m 247m 184m R 15.6 1.6 4:32.99 php-fpm 30061 apache 20 0 788m 280m 206m R 15.6 1.8 4:31.77 php-fpm 30063 apache 20 0 787m 259m 186m R 15.6 1.7 4:34.28 php-fpm 7328 apache 20 0 797m 307m 230m R 15.3 2.0 16:44.80 php-fpm 7330 apache 20 0 822m 354m 247m R 15.3 2.3 15:21.52 php-fpm 7332 apache 20 0 806m 323m 228m R 15.3 2.1 17:10.16 php-fpm 29231 apache 20 0 790m 291m 217m R 15.3 1.9 5:20.02 php-fpm 29241 apache 20 0 777m 271m 206m R 15.3 1.7 5:30.39 php-fpm 29244 apache 20 0 796m 285m 203m R 15.3 1.8 5:32.68 php-fpm

CPU Graph at time of Issue: Cpu.png

Note:DB CPU was in normal range through out the time

If you've encountered a similar situation or have expertise in tuning PHP-FPM for Magento, I would greatly appreciate any advice, best practices, or recommendations you could share. Additionally, if there are specific metrics or tools you recommend for monitoring and adjusting PHP-FPM settings in a Magento environment, please feel free to suggest them.

Thank you in advance for your time and assistance. I look forward to hearing from the Magento community experts!

1
  • Let's find out how many Sleeping processes your server is managing with this query. SELECT 'SLEEPING Ram use', COUNT(*),SUM(time),SUM(memory_used),SUM(max_memory_used) FROM information_schema.processlist WHERE command="Sleep"; Jan 17 at 1:57

1 Answer 1

0

Right off the bat, you set maximum children too high for an 8-core machine.

A rule of thumb I'm using - max_children = # of CPU cores.

Static distribution performs better from my experience.

Try different solutions:

  • Switch to pm = static with pm.max_children = 8
  • You might have a code bottleneck. Hook up the site to a code profiler (new relic, tideways or similar, just google for them, they are all good). It will show you what slows the site down
  • Do a 3rd-party extension audit. My experience tells me it's a custom extension that breaks performance. Turn them all off and see if it makes a difference. Kind of hard to do on a live site but if you could.

What you need to do is to try and optimize TTFB (time to first byte), then you wouldn't need so many php-fpm processes.

And in the end, of course, it could be as simple as:

php bin/magento cache:enable
1
  • Thanx for sharing your exp i will config it according to VM. Jan 12 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.