Setting Apache2 ulimit for Maximum Performance 6 Comments5 December 2012Posted in Apache-httpd, Load Testing As strange as it seems, when you start up the standard RedHat or CentOS release, it is not configured for running Apache2 with any sort of performance! In fact, even on a large server you’ll be lucky to handle 100 concurrent users on even simple web pages. So many websites have very few visitors so often its not noticeable, but even if you adjust all of the other apache2 settings, if you don’t bother to adjust the ulimits, the site will be handicapped by really bad performance. First, in running the tests I decided to stick with the default prefork MPM. There’s dozens of sources on the web for configuring Apache prefork for maximum performance that I won’t repeat here. Typically, though, the first thing to do is set a high number of MaxClients, which really isn’t that high considering a “client” is a socket connection, and modern browsers can open eight socket connections at a time. This turns the “8192” below into only 1,024 actual concurrent users. Of course its possible to set MaxClients higher than that, but with a typical test scenario only 500 clients can potentially max out the available bandwidth and CPU, so this isn’t a bad place to start: StartServers 20 MinSpareServers 25 MaxSpareServers 100 ServerLimit 8192 MaxClients 8192 MaxRequestsPerChild 10000 So, what type of performance do you get with these settings? The testcase I used was browsing our company website, configured as static pages, with 4 second think times and a page-load goal of 2 seconds per page. Even though it should have been able to handle at least 512 browsers, the webserver started crashing at less than 100 concurrent users. As it turns out, despite setting MaxClients to 4096, the system never actually reaches that level because the compiled in limit for the number of processes is 1024, as can be seen below: [root@faith ~]# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 59400 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited The fix on RedHat/CentOS is to edit the file /etc/security/limits.conf and these lines, adjusting the limits based on your system capacity and needs. * soft nofile 10240 * soft nproc 10240 Restarting Apache and Re-running the tests resulted in a huge increase in performance, increasing the capacity of the server to around 600 concurrent users.