Websites on PHP-FPM are unavailable or loading slowly: "server reached max_children setting" OR "pool seems busy"

Follow

Comments

18 comments

  • Avatar
    Markus

    Great help and tutorial ! Thanks a lot

    0
    Comment actions Permalink
  • Avatar
    Sharul Hafiz

    Possible to apply this setting to all domains with single file editing? I have lots of domains to be configured 1 by 1

    0
    Comment actions Permalink
  • Avatar
    Nikolay Zhmuk

    @Sharul Hafiz You can check the article mentioned in Additional Information section - https://support.plesk.com/hc/en-us/articles/115001201949
    Keep in mind that increasing of pm.max_children parameter for all domains can affect the server performance significantly. It is better to filter only affected domains in /var/log/plesk-phpXX-fpm/error.log file
    ===
    grep "server reached max_children setting" /var/log/plesk-phpXX-fpm/error.log
    ===
    and adjust max_children just for them.

    0
    Comment actions Permalink
  • Avatar
    Sharul Hafiz

    @Nikolay What is the limit of pm.max_children? let say if I have 10GB free ram.

    0
    Comment actions Permalink
  • Avatar
    Konstantin Annikov

    @Sharul

    The setting is purely depends on amount of traffic for the website. Try to double the default value (from 5 to 10) and monitor the site for several days. 

    If the same error appears again, analyze the time period between reaching MaxChildren. In case the time like several minutes, double the value again (from 10 to 20), in case the error appears once a day, just add one more child to the configured value (20 to 21). 

    Typically, 20 is more than enough for medium-loaded websites. 

    0
    Comment actions Permalink
  • Avatar
    Marco Marsala

    This line

    # grep "server reached max_children setting" /var/log/php-fpm/error.log | awk '{print $5}' | sort -n | uniq -c

     is wrong, as it should be

    # grep "server reached max_children setting" /var/log/plesk-phpXX-fpm/error.log | awk '{print $5}' | sort -n | uniq -c
    0
    Comment actions Permalink
  • Avatar
    Marco Marsala

    May you insert 

    pm.max_children = 40

    in Additional PHP directives field of PHP Settings page for domain?

    0
    Comment actions Permalink
  • Avatar
    Konstantin Annikov (Edited )

    Hello Marco, 

    Both files (/var/log/php-fpm/error.log and /var/log/plesk-phpXX-fpm/error.log) exist on the filesystem. The first is used to store errors from system php-fpm, and the second is used when we are speaking about php-fpm which is provided bu Plesk. 

    Meanwhile, I have edited the article in this way: 

    # grep "server reached max_children setting" /var/log/*php*-fpm/error.log | awk '{print $5}' | sort -n | uniq -c

    As for the second question, Additional PHP directives field is used to insert configuration directives in /var/www/vhosts/system/example.com/conf/php.ini file (configuration file for php itself), however pm.max_children directive should be added to the configuration file of php-fpm pool (/var/www/vhosts/system/example.com/conf/php.ini). 
    So, this is two different files. And now Plesk could manage only php settings, but not php fpm pool settings. 
    If you would like Plesk to manage php fpm pool settings, vote for this feature on Plesk Uservoice portal. 

    0
    Comment actions Permalink
  • Avatar
    Lars Doe

    @Konstantin

    You provided the same path for both php.ini files and said these were two different files. 

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Lars,

    Thank you for noticing. Indeed, additional directives are stored in/var/www/vhosts/system/example.com/conf/php.ini and PHP-FPM settings are stored in /opt/plesk/php/X.X/etc/php-fpm.d/example.com.conf.

    As it is stated in the article, now it is possible to change PHP-FPM settings in Pleks GUI.

    0
    Comment actions Permalink
  • Avatar
    Bob Benson

    I'd like to create a weekly scheduled task (cron job) to check for "server reached max_children setting" in the plesk-php*-fpm error.log, on CentOS 7.  It looks like that log is rotated weekly. 

    Could someone make a suggestion for a good way to schedule a weekly task, which will e-mail the server administrator, weekly, with a list of domains that have reached "max_children"?  I suppose I could create something in "/etc/cron.weekly", but how do I make sure the script runs before the weekly log rotation?

    0
    Comment actions Permalink
  • Avatar
    Taras Ermoshin

    Hello @Bob B!

    You are right, the log files from the directories /var/log/plesk-phpXX-fpm/ are rotated weekly - in the logrotate configuration files /etc/logrotate.d/plesk-phpXX, options daily, weekly, monthly, or yearly are not specified, and in the main configuration file /etc/logrotate.conf, the option weekly is set.

    For the weekly task you would like to create, you can write a corresponding script and put it into the option prerotate/endscript in the logrotate configuration files /etc/logrotate.d/plesk-phpXX. For more details on logrotate configuration options, see the link https://linux.die.net/man/8/logrotate. Please note that the script should be made on your own.

    1
    Comment actions Permalink
  • Avatar
    Nick Bucko

    Bob Benson

    I created a little shell script to do this daily, /root/fpmwatch.sh. Be sure to give the script executable permissions (chmod +x fpmwatch.sh) It checks for any occurrences of max_children in all the plesk-php*-fpm error logs for the current day and if it exists sends an email.  I include the server IP in the subject line as we have many servers so be sure to update that with your IP and the email address.  There may be a much better way of writing the script, but this works for us.  I'm not sure if the date format in the log can be different but if it is you have to modify that part of the grep command.  The date part of our log format is 30-Jul-2020.  

     

    #!/bin/bash
    grep "$(date +"%d-%b-%Y")" /var/log/plesk-php*-fpm/error.log | grep max_children > /root/fpmlimitreached.txt
    if [ $? -eq 0 ]
    then
    cat /root/fpmlimitreached.txt | mail -s "PHP-FPM limit reached for site(s) on ipaddresshere" your@emailaddress.com
    fi
    rm -rf /root/fpmlimitreached.txt

     

    Then I set a cron to run the script at 11:55 PM each night.  

    55 23 * * * /root/fpmwatch.sh

    1
    Comment actions Permalink
  • Avatar
    Lindsay Adamson

    This is exactly what i was looking for, thanks!  Do you have a way to date sort them, and grab only head, to find only the latest offenders, so that when adjusting you can ony get the results you want?

    I was using this, but cant pin down the sort. 
    `sudo find /var/log/*php*/ -type f -exec grep max_child {} \; | sort -t ' ' -k 3.9,3.12n -k 3.5,3.7M`
    `| sort -k2M -k3n -k4`
    `| sort -k 2,1`
    `| sort -s -k 1M -k 4,4`
    alot of them are shots in the dark, beacuse i cant seem to output exactly (and only) what `k` sees, or is filtering with, so not sure how to dial it in yet. 

    Your script is VERY helpful, but doesnt help me find the latest offenders. 

    0
    Comment actions Permalink
  • Avatar
    JEAN-CHARLES BURGER

    mon serveur est super lent 

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello JEAN-CHARLES BURGER

    This may have various reasons: high load on websites, hardware issues, DDoS attacks.

    Please, inspect all these points. 

    0
    Comment actions Permalink
  • Avatar
    JEAN-CHARLES BURGER

    Bonjour, je suis débutant, connaîtrez-vous un spécialiste en plesk pour vérifier la config que j'ai faite même si je dois payer car mon site inreims.fr est vraiment très lent en attendant votre réponse cordialement burger jc

    0
    Comment actions Permalink
  • Avatar
    Anton Maslov

    Hello JEAN-CHARLES BURGER we do not have any contacts  of individuals performing such tasks Thought you may look into Plesk partners list, some of them provide managed services: https://www.plesk.com/partner-directory/ 

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request