Applicable to:
- Plesk for Linux
Symptoms
- Websites on the server are experiencing 504 Gateway Time-out nginx errors consistently after working without issues for a period of time
- The Apache web server goes down periodically with the following error message in Apache error log:
-
on CentOS/RHEL-based distributions:
/var/log/httpd/error_log
-
on Debian/Ubuntu-based distributions:
/var/log/apache2/error.log
CONFIG_TEXT: AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
CONFIG_TEXT: server is within MinSpareThreads of MaxRequestWorkers, consider raising the MaxRequestWorkers setting
-
- The following error message is logged in domain's log at Plesk > Domains > Logs:
CONFIG_TEXT: [error] 26927#0: *417 connect() failed (110: Connection timed out) while connecting to upstream, client: 203.0.113.2, server: example.com, request: "GET /?amp HTTP/1.1", upstream: "https://203.0.113.2/?amp", host: "example.com"
Cause
The MaxRequestWorkers
limit set for the Apache web server has been reached and there are no free workers to serve new requests to Apache. As a result, requests are being served slowly or not served at all and therefore the websites become inaccessible, even though the server's CPU and RAM resources are not exhausted.
Resolution
Adjust the MaxRequestWorkers
settings for Apache. The general formula for making the necessary calculation is the following:
# MaxRequestWorkers = (Total RAM - Memory used for Linux, DB, etc.) / average Apache process size
-
MPM Event: The default ServerLimit value is 16. To increase it, you must also raise
MaxRequestWorkers
using the following formula: ServerLimit value x 25 =MaxRequestWorkers
value. For example, ifServerLimit
is set to 20, thenMaxRequestWorkers
will be 20 x 25 = 500. -
MPM Prefork: The default
MaxRequestWorkers
value is 256. To increase it, you must also raiseServerLimit
.
Note: The below values are examples. They must be adjusted according to the server capabilities and load.
-
Find which Multi-Processing Module (MPM) is currently in use:
# httpd -V | grep MPM
-
Open the
/etc/httpd/conf.modules.d/01-cgi.conf
file in a text editor (for example, vi editor) and increase the values of the following directives (or add them if they are not present in the file):-
For MPM Event:
CONFIG_TEXT: <IfModule mpm_event_module>
LoadModule cgid_module modules/mod_cgid.so
MaxRequestWorkers 400
ServerLimit 16
</IfModule> -
For MPM Prefork:
CONFIG_TEXT: <IfModule mpm_prefork_module>
LoadModule cgi_module modules/mod_cgi.so
MaxRequestWorkers 400
ServerLimit 400
</IfModule>
-
-
Save the changes and close the file.
-
Restart Apache to apply the changes:
# service httpd restart
-
Find which Multi-Processing Module (MPM) is currently in use:
# apache2ctl -V | grep MPM
-
Change the MPM configuration:
-
For MPM Event:
Open the
/etc/apache2/mods-enabled/mpm_event.conf
in a text editor (for example, vi editor) and increase the values of the following directives (or add them if they are not present in the file):CONFIG_TEXT: MaxRequestWorkers 400
ServerLimit 16 -
For MPM Prefork:
Open the
/etc/apache2/mods-enabled/mpm_prefork.conf
file in a text editor (for example, vi editor) and increase the values of the following directives (or add them if they are not present in the file):CONFIG_TEXT: MaxRequestWorkers 400
ServerLimit 400
-
-
Save the changes and close the file.
-
Restart Apache to apply the changes:
# service apache2 restart
Note: If the issue persists, switch MPM mode to Prefork at Tools & Settings > Apache Web Server.
Comments
1 comment
Hi Kuzma Ivanov,
Please note that the results of calculations for lots and lots of servers, of the below, to the best of my understanding totally does not suit, the default recommended values, as set in this current article.
Can you please advise?
MaxRequestWorkers = (Total RAM - Memory used for Linux, DB, etc.) / average Apache process size
MPM Event: The default ServerLimit value is 16. To increase it, you must also raise
MaxRequestWorkers
using the following formula: ServerLimit value x 25 =MaxRequestWorkers
value. For example, ifServerLimit
is set to 20, thenMaxRequestWorkers
will be 20 x 25 = 500.MPM Prefork: The default
MaxRequestWorkers
value is 256. To increase it, you must also raiseServerLimit
.MPM EVENT
Please sign in to leave a comment.