0

I am facing issue with my server response time when I restart php FPM websites loads fasts and then again after some time the same situation so I have to restart the fpm again.

I changed pm_max_children, pm_max_requests, pm_min_spare_servers setting but nothing worked.

Please help me for solving this issue.

Right now pm_max_children=600

2 Answers 2

0

I had a similar issue a couple of weeks back and found this article about php-fpm tweaks useful. It might be worth working through the sections in there to check against your settings. It has the calculation on how to set the memory limits for the PHP process. https://medium.com/@richb_/tweaking-nginx-and-php-fpm-configuration-to-fix-502-bad-gateway-errors-and-optimise-performance-on-17465f41fd87

0

How many cores and how much RAM does your server have? Before you restart the server how many PHP processes are there and what is "top" saying?

Count php processes

ps -ef | grep php

Work out top (edit your question to copy and paste the text of top in, formatted so it displays correctly. The first 4 or 5 lines are the most important)

top

I suspect you're trying to use more resources than your server has. PHP can use a lot of memory - 100MB per thread (child) or more sometimes. If you've told it to use 600 children that could be 60GB of RAM so you're well into swap.

I have an EC2 t3.nano with 500MB of RAM and 500MB of swap, running MySQL, PHP, Nginx, and a few others things. I set pm.max_children = 4 . Here's my key settings for the dynamaic PHP pool for my very lightly loaded server

pm = dynamic
pm.max_children = 4
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 2
; This next line restarts the PHP thread once it's serviced 100 threads - I have a buggy program
pm.max_requests = 100

I have another PHP pool which is only used for testing, which is rare, so it defaults to no spare PHP processes

pm = ondemand
pm.max_children = 2
pm.process_idle_timeout = 120s;
pm.max_requests = 50

In my Nginx configuration I use this command to send my test site to the PHP test pool

fastcgi_pass   php56-fpm-testpool;

Suggestions

Use a configuration something like this, to reduce RAM usage. This really depends on your load and you should tweak the numbers.

pm = dynamic
pm.max_children = 75
pm.start_servers = 25
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 500
2
  • Thanks for your reply , I have 30GB RAM out of which 8GB used. Oct 31, 2019 at 9:25
  • As per my question, can you please do a process count and run "top" before the problems occur and you do a restart, and edit your question to include that information. I'd also like to know how many cores you have, and how many requests to PHP per second - not requests to Nginx for images and such, requests to PHP - an estimate is fine. It sounds like resource exhaustion to me, particularly memory. I've edited my question to add a suggested config, which I can tweak once I have more info.
    – Tim
    Oct 31, 2019 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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