GrepBoard/Manuals
605 manuals ·

Apache "reached MaxRequestWorkers": cause and tuning

·Tested on Ubuntu 24.04.5 · Apache 2.4.58 (event, prefork) · 2.4 docs·Test scope ↓·8 steps

AH00484 or AH00161 in error.log means every worker slot is busy. Reproduce the queueing, find the slow requests, then size MaxRequestWorkers against memory.

When error.log shows the line below, Apache has used all of its MaxRequestWorkers slots. Start by working out which MPM wrote it and what happens to connections that arrive while the server is full.

[1] Read the message number to tell the MPM apart. The text is identical, but the event MPM logs AH00484 and prefork logs AH00161. These lines come from the same load run against each MPM; timestamps and PIDs are trimmed.

console
… [mpm_event:error] … AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting… [mpm_prefork:error] … AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting

apache2ctl -V prints the active MPM on the Server MPM: line. Then look at the access log around the time of the error line.

console
# apache2ctl -V | grep -i mpm# grep -n 'MaxRequestWorkers' /var/log/apache2/error.log | tail

[2] Check what happens to connections while the limit is reached. The test server had MaxRequestWorkers 5. Eight requests that take 8 seconds each were sent at once, and a static file was requested two seconds later.

console
$ bash load.shindex 000 3.002993slow4 200 8.009385slow2 200 8.006115slow5 200 8.006900slow3 200 8.006544slow1 200 8.004954slow8 200 16.002803slow6 200 16.008152slow7 200 16.008072

Five slow requests took every worker. The other three started after 8 seconds and finished at 16. The cheap index request hit the client's 3-second limit (curl -m 3) without an answer. Connections over the limit are not refused; they wait. The Apache docs say the same: connections beyond the limit are normally queued, up to a length based on ListenBacklog.

[3] Look at the waiting connections with ss. On a LISTEN socket, Recv-Q is the number of connections not yet accepted and Send-Q is the maximum queue length.

console
$ ss -tln 'sport = :18700'State Recv-Q Send-Q Local Address:Port  Peer Address:PortLISTEN 4      511        127.0.0.1:18700      0.0.0.0:*

Recv-Q 4 was the three waiting slow requests plus the index request. Send-Q 511 is the ListenBacklog default. A Recv-Q that stays above 0 means too few workers, or slow requests holding them.

[4] To see a full queue, the test was repeated with ListenBacklog 1 (five slow requests, then five ordinary ones). The kernel counters rose.

console
$ nstat -az TcpExtListenOverflows TcpExtListenDropsTcpExtListenOverflows           18                 0.0TcpExtListenDrops               18                 0.0

Both were 0 before the run. When the queue overflows, the kernel drops the new connection and the client retransmits, so answers still arrive but several seconds late (6–7 s for the ordinary requests here). With the default of 511 this is hard to reach, and the docs say tuning is normally not needed. The OS may cap the value lower.

[5] Before raising anything, find out why workers are tied up. If requests are slow, a higher limit only delays the same saturation. If the access log records the time taken (%D, microseconds), count the slow paths.

httpd.conf
LogFormat "%h %t \"%r\" %>s %b %D" lab
console
# awk '{print $NF/1000000, $5}' /var/log/apache2/access.log | sort -rn | head

The command assumes that format (%D last, path in field 5); adjust the field numbers to your own format. In the test, the slow requests appeared in the access log as values like 8003764, about 8 seconds.

[6] When you do raise the limit, each MPM needs a companion setting. Without it the value is lowered at startup. These are the warnings produced by setting MaxRequestWorkers 400:

console
AH00180: WARNING: MaxRequestWorkers of 400 exceeds ServerLimit value of 5 servers, decreasing MaxRequestWorkers to 5. To increase, please see the ServerLimit directive.AH00515: WARNING: MaxRequestWorkers of 400 would require 80 servers and would exceed ServerLimit of 1, decreasing to 5. To increase, please see the ServerLimit directive.

The first is prefork (ServerLimit 5); the second is event (ServerLimit 1, ThreadsPerChild 5). Defaults and rules from the official docs:

MPMWhat MaxRequestWorkers countsRaise togetherDocumented default
preforkchild processesServerLimit above 256256
event, workertotal threadsServerLimit above 16 processes16 × 25 = 400

With event, MaxRequestWorkers must be a multiple of ThreadsPerChild; otherwise it is rounded down with a warning. Distribution packages may ship other values: the Ubuntu 24.04 apache2 package sets MaxRequestWorkers 150 in both mpm_event.conf and mpm_prefork.conf.

[7] Size the new value by memory. With prefork each worker is one process, so the memory of one child is the multiplier. Check the RSS of the current children:

console
# ps -ylC apache2 --sort=rss | awk 'NR>1{print $8/1024 " MB"}' | tail -3

A rough ceiling is (free memory − what other services use) ÷ RSS of one child. RSS counts shared pages in every process, so it overstates the real cost. The test children were about 4.6 MB, but that was a minimal module set and says nothing about a production server; measure on the real one. After raising the value, watch free -m for swap use.

[8] Check the syntax and apply the change. A graceful restart does not cut running requests.

console
# apache2ctl configtestSyntax OK# apache2ctl graceful

Analyze your Apache log in the browser ↗ — nothing is uploaded.

#apache#mpm#error-log