title: Apache performance tuning with 1 GB with httpd.conf
body: <p>I have a 1 GB VPS and Apache slows to a crawl almost from start up. I ran ApacheBench on a static.html file and things don't differ. However, the site will have both MySQL and PHP and a high volume of AJAX requests, so I'd like to tune for that.</p>
  
  <p>When I restart, error logs show this almost immediately:  </p>
  
  <blockquote>
    <p>[error] server reached MaxClients setting, consider raising the MaxClients setting  </p>
  </blockquote>
  
  <pre><code>ab -n 1000 -c 1000
  </code></pre>
  
  <p>shows:</p>
  
  <pre><code>Document Path:          /static.html
  Document Length:        7 bytes
  
  Concurrency Level:      1000
  Time taken for tests:   57.784 seconds
  Complete requests:      1000
  Failed requests:        64
     (Connect: 0, Receive: 0, Length: 64, Exceptions: 0)
  Write errors:           0
  Total transferred:      309816 bytes
  HTML transferred:       6552 bytes
  Requests per second:    17.31 [#/sec] (mean)
  Time per request:       57784.327 [ms] (mean)
  Time per request:       57.784 [ms] (mean, across all concurrent requests)
  Transfer rate:          5.24 [Kbytes/sec] received
  
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:        0   25  13.4     25      48
  Processing:  1070 16183 15379.4   9601   57737
  Waiting:        0 14205 15176.5   9591   42516
  Total:       1070 16208 15385.0   9635   57783
  
  Percentage of the requests served within a certain time (ms)
    50%   9635
    66%  20591
    75%  20629
    80%  36357
    90%  42518
    95%  42538
    98%  42556
    99%  42560
   100%  57783 (longest request)
  </code></pre>
  
  <p>If I run ab on a php file, it finishes sometimes, most of the time it won't and sometimes gets errors like</p>
  
  <pre><code>apr_socket_recv: Connection reset by peer (104)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>socket: No buffer space available (105)
  </code></pre>
  
  <p>httpd.conf items:</p>
  
  <pre><code>Timeout 10
  KeepAlive On
  MaxKeepAliveRequests 100
  KeepAliveTimeout 1
  
  &lt;IfModule prefork.c&gt;
  StartServers 3
  MinSpareServers 5
  MaxSpareServers 9
  ServerLimit 40
  MaxClients 40
  MaxRequestsPerChild 5000
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Top... (CPU and Load 1min are very erratic during testing):</p>
  
  <pre><code>top - 10:44:51 up 11:50,  3 users,  load average: 0.17, 0.42, 0.90
  Tasks:  84 total,   2 running,  82 sleeping,   0 stopped,   0 zombie
  Cpu(s):  2.8%us,  3.1%sy,  0.0%ni, 94.1%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
  Mem:   1793072k total,   743604k used,  1049468k free,        0k buffers
  Swap:        0k total,        0k used,        0k free,        0k cached
  
    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                             
  21831 mysql     18   0  506m  71m 6688 S  0.7  4.1   4:03.18 mysqld                               
   1828 root      15   0  113m  52m 2052 S  0.0  3.0   0:02.85 spamd                                
   1830 popuser   18   0  113m  51m  956 S  0.0  2.9   0:00.00 spamd                                
   8012 apache    15   0  327m  35m  17m S  3.7  2.0   0:11.83 httpd                                
   8041 apache    15   0  320m  28m  15m S  0.0  1.6   0:11.83 httpd                                
   8022 apache    15   0  321m  27m  14m S  2.3  1.6   0:11.05 httpd                                
   8033 apache    15   0  320m  27m  14m S  1.7  1.6   0:10.06 httpd 
  </code></pre>
  
  <p>Is there something obvious that is wrong here? or what would be my next step in troubleshooting?</p>