Symptoms
Apache web server goes down periodically with the following error message in its error log:
-
on CentOS/RHEL-based distributions:
/var/log/httpd/error_log
-
on Debian/Ubuntu-based distributions:
/var/log/apache2/error.log
server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
Cause
The MaxRequestWorkers
limit 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.
Resolution
Adjust the MaxRequestWorkers
settings for Apache. General formula looks like below:
# 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:
<IfModule mpm_event_module>
LoadModule cgid_module modules/mod_cgid.so
MaxRequestWorkers 400
ServerLimit 16
</IfModule> -
For MPM Prefork:
<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):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):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 to Prefork in Tools & Settings > Apache Web Server.