Yunohost Apache MaxRequestWorkers: Diagnosing latency spikes under concurrent load
0 reputation · 25 Jun 2026, 03:42 UTC
0 reputation · 25 Jun 2026, 03:42 UTC
Determine whether the default MaxRequestWorkers setting is a bottleneck when Yunohost handles many simultaneous web requests.
It is unclear whether raising MaxRequestWorkers, pm.max_children, or both will reduce latency without causing resource exhaustion.
29775 reputation · 25 Jun 2026, 12:04 UTC
On a 4 GB Yunohost machine the safe MaxRequestWorkers value is around 80–100. This keeps Apache’s memory consumption (~3–4 GB) below physical RAM when you keep the PHP‑FPM pool at 5 children. Scaling pm.max_children proportionally to MaxRequestWorkers is not required; you should match pm.max_children to the expected peak number of concurrent PHP requests, not to the number of Apache workers. Raising MaxRequestWorkers alone will not usually trigger swapping if PHP‑FPM stays at 5, because Apache workers are lightweight, but a very large idle worker pool can still consume significant RAM. Monitor swap usage to confirm the behaviour.
Because Apache workers are lighter than PHP‑FPM children, the primary memory consumer is the PHP‑FPM pool. The safest strategy is to keep MaxRequestWorkers high enough to avoid queuing (≈80–100) while keeping pm.max_children at a level that matches the real concurrency of PHP scripts. If you raise MaxRequestWorkers without adjusting PHP‑FPM, the idle worker pool may grow large enough to approach the RAM limit, but this is less common than hitting the PHP‑FPM child limit.
ps -eo pid,comm,rss | grep apache2
ps -eo pid,comm,rss | grep php-fpm
free -m
sudo nano /etc/apache2/mods-available/mpm_prefork.conf
# change MaxRequestWorkers 150 to 90
sudo systemctl restart apache2
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
# set pm.max_children 5
sudo systemctl restart php7.4-fpm
ab -n 2000 -c 200 http://localhost/ 2>&1 | tee ab.log
free -m | grep Swap
Verify that swap usage stays below 10 % of total RAM.
Do you currently have any swap configured on the server? Knowing the swap size (or if it is disabled) will help decide whether a larger MaxRequestWorkers value is safe.
Use comments to ask for clarification. Post a solution as an answer.
29,775 reputation · 25 Jun 2026, 12:49 UTC
When diagnosing latency in a YunoHost environment, it is important to distinguish between connection queuing and execution queuing. Increasing MaxRequestWorkers allows Apache to accept more simultaneous TCP connections, but if those requests are routed to PHP-FPM, they will still queue at the FPM level if pm.max_children is capped at 5.
If MaxRequestWorkers is significantly higher than pm.max_children, you may see a decrease in "Connection Refused" errors, but you will likely see an increase in Gateway Timeout (504) or high TTFB (Time to First Byte) because the PHP workers are saturated. To verify the actual bottleneck, check the Apache error logs for [mpm_event:error] AH00163: server reached MaxRequestWorkers setting versus the PHP-FPM logs for server reached pm.max_children setting.