Apache Server 2.4.57(event MPM)最大并发连接/请求数调整及相关配置咨询
Hi there! Let’s break down your questions one by one based on your Apache 2.4.57 (event MPM) setup and system configuration:
1. Can we just set MaxRequestWorkers to 16000 to double concurrent capacity?
No, you can’t just change MaxRequestWorkers alone—this value is strictly dependent on two other MPM parameters: ServerLimit and ThreadsPerChild.
For worker/event MPMs, the formula governing maximum concurrent requests is:
MaxRequestWorkers = ServerLimit × ThreadsPerChild
In your current config:
ServerLimit 250(max number of Apache child processes)ThreadsPerChild 32(threads spawned per child process)- 250 × 32 = 8000, which exactly matches your current
MaxRequestWorkers
To reach 16000 concurrent requests, you need to adjust either (or both) dependent parameters so their product equals 16000. Two common approaches:
- Keep
ThreadsPerChild 32and setServerLimit 500(500 × 32 = 16000) - Or keep
ServerLimit 250and setThreadsPerChild 64(250 × 64 = 16000)—just ensureThreadLimit(currently 64) is at least as high asThreadsPerChild(which it is here)
If you only set MaxRequestWorkers 16000 without updating ServerLimit/ThreadsPerChild, Apache will either fail to start or silently cap the effective limit at the original 8000. Always run apachectl configtest after changes to catch issues early.
2. How to check the current effective MaxRequestWorkers value?
You have three reliable ways to confirm this:
- Apache config dump command: Run
apachectl -t -D DUMP_RUN_CFG(orhttpd -t -D DUMP_RUN_CFGon some systems). Scan the output for theMaxRequestWorkersline—it will show the actual effective value, not just what’s in your config file. - Server status page: If you’ve enabled
mod_status, visithttp://your-server-ip/server-statusin a browser. It displays "Max Workers" (yourMaxRequestWorkersvalue) alongside real-time active/idle connection counts. - Error logs: If there’s a mismatch between
MaxRequestWorkersand theServerLimit×ThreadsPerChildproduct, Apache will log an error in its error log (usually/var/log/httpd/error_logor/var/log/apache2/error.log) on startup.
3. Troubleshooting bottlenecks with idle CPU/memory
Since your server’s CPU and memory aren’t maxed out, the bottleneck is likely tied to connection/resource limits rather than raw compute power. Here are quick checks:
- Use the
server-statuspage to see if you’re consistently hitting the currentMaxRequestWorkerslimit (look for "Busy Workers" staying close to "Max Workers"). - Verify if other Apache modules (like
mod_proxyif you’re using reverse proxy) have their own concurrency limits restricting throughput. - Ensure your system’s network stack isn’t limiting connections (e.g.,
net.ipv4.tcp_max_syn_backlogornet.core.somaxconnkernel parameters—though these are less likely if CPU/memory are idle).
4. Required changes to limits.conf (and related system configs)
Your ulimit -a output shows critical system limits that need adjustment for 16000 concurrent requests:
Open File Descriptors
Each Apache connection uses at least a few file descriptors (for the connection itself, log files, static assets, etc.). Your current open files limit is 1024—way too low for 16000 concurrent connections.
Update /etc/security/limits.conf (or create a cleaner override file like /etc/security/limits.d/99-apache.conf) with:
# Soft limit (default for the Apache user) apache soft nofile 20000 # Hard limit (maximum allowed) apache hard nofile 40000
(Replace apache with the user your Apache process runs as—common alternatives are www-data or httpd.)
Systemd Overrides (if applicable)
If your server uses systemd to manage Apache, it may override limits.conf settings. Create or edit /etc/systemd/system/httpd.service.d/limits.conf (adjust to apache2.service if needed) with:
[Service] LimitNOFILE=40000 # Max user processes is already 95053, which is more than enough for 500 Apache child processes—no need to change this unless you scale further LimitNPROC=95053
Then reload systemd and restart Apache:
systemctl daemon-reload systemctl restart httpd
Verify the Changes
To confirm limits are applied to the Apache user, run:
su - apache -c 'ulimit -n'
It should return the soft limit you set (20000).
Final Checklist
- Update your MPM config to match your target capacity (example for 16000 concurrent requests):
<IfModule mpm_worker_module> ServerLimit 500 StartServers 10 MinSpareThreads 75 MaxSpareThreads 250 ThreadLimit 64 ThreadsPerChild 32 MaxRequestWorkers 16000 MaxConnectionsPerChild 10000 </IfModule> - Adjust system file descriptor limits as outlined above
- Run
apachectl configtestto catch configuration errors - Restart Apache
- Verify effective
MaxRequestWorkersand system limits
备注:内容来源于stack exchange,提问作者rndm_acct1




