fast and secure web hosting. from a simple website to a highly visited e-shop  

Optimize Apache on cPanel - apache benchmark

Requirements: If you don't have Prefork installed, then please install it via Easy Apache on your WHM. You will have to recompile Apache.

Run apache benchmark on terminal:
ab -n 500 -c 50

It's best to select your heavier webpage.
You'll get something like the following screen:

Document Path: /el<br />
  Document Length: 0 bytes<br /><br />
Concurrency Level: 50<br>
  Time taken for tests: 28.558 seconds<br>
  Complete requests: 500<br>
  Failed requests: 0<br>
  Write errors: 0<br>
  Non-2xx responses: 500<br>
  Total transferred: 243000 bytes<br>
  HTML transferred: 0 bytes<br>
  Requests per second: 17.51 [#/sec] (mean)<br>
  Time per request: 2855.831 [ms] (mean)<br>
  Time per request: 57.117 [ms] (mean, across all concurrent requests)<br>
  Transfer rate: 8.31 [Kbytes/sec] received<br /><br />
Connection Times (ms)<br>
  min mean[+/-sd] median max<br>
  Connect: 0 0 0.5 0 3<br>
  Processing: 337 2829 916.6 2779 6550<br>
  Waiting: 337 2828 916.6 2777 6550<br>
  Total: 338 2829 916.5 2779 6550<br /><br />
Percentage of the requests served within a certain time (ms)<br>
  50% 2779<br>
  66% 2917<br>
  75% 3018<br>
  80% 3111<br>
  90% 4094<br>
  95% 4836<br>
  98% 5162<br>
  99% 5453<br>
  100% 6550 (longest request)

In order to check the amound of memory its apache request requires, run the following via terminal: ps aux | grep apache

Devide the half of the memory of your server with the average memory that its apache request requires.
For example a server that has 2GB of RAM and a average request is 20MB, then 100 is the result.

Edit /usr/local/apache/conf/httpd.conf
For example: nano /usr/local/apache/conf/httpd.conf


&lt;IfModule prefork.c&gt;<br>
  StartServers 20<br>
  MinSpareServers 15<br>
  MaxSpareServers 20<br>
  MaxClients 100<br>
  MaxRequestsPerChild 5000<br>

Initially start 20 httpd processes. (StartServers)
Keep min 15 processes idle to wait for request. (MinSpareServers)
No more than 20 idle processes. (MaxSpareServers)
Never have more than 100 processes (the result we got above from the division). (MaxClients)
When a process exceeds 5000, kill it. (MaxRequestsPerChild)

Also set:

KeepAlive On<br>
  MaxKeepAliveRequests 100<br>
KeepAliveTimeout 12

Set MaxKeepAliveRequests accordingly to your webpages elements
Set KeepAliveTimeout to the double of you longest request (6550 for this demo).

Restart apache (via cPanel).