I've run into a problem and I just can't seem to figure out how to solve it; I have a regular Ubuntu 12.04 Server with apache 2.2 running a website. Every now and then the server overloads and starts becoming unresponsive, simple commands takes ages to execute until the server is restart or apache/mysql is restarted. (And the website itself shuts down complety)

Looking in the error log I see a simple

[error] server reached MaxClients setting, consider raising the MaxClients setting

Followed by a bunch of mysqli being unable to connect

One would simply assume that I would need to increase the MaxClients but I've already done this a couple of times and I worry that I will overload the server myself by setting it too high, below is how the mpm prefork is currently set:

<IfModule mpm_prefork_module>
    StartServers          20
    MinSpareServers       10
    MaxSpareServers      20
    MaxClients          150
    MaxRequestsPerChild 90

On a normal day we have roughly 1700 Users/Visitors (During 24 hours).

Server details:

  • Memory: 3GB
  • CPU: 1 - 3300MHz
  • OS: Ubuntu 12.04
  • Apache: 2.2 with php 5.3.10 & Mysql 5.5.41

Couple of pictures I got with glances, here you can see apache swallowing quiet a lot of CPU before they drop down again: (This is with only a coupe of users on the webserver (5 to 20) )

high load 1 high load 2

How do I avoid my server crashing / overloading? ( I am open to any solution, even changing to nginx or something else if that could handle the load better).

Also, I'm not concerned about RAM usage / consumption since I can add a lot more RAM, it's the CPU I'm concerned about.

  • 2
    Actually unresponsive server is a tip to check your iowait load. I believe you have bottle neck in your database. Check mysql slow log, check innodb buffer pool, check memory usage by mysql. And you should start collect statistic from your server. At start memoury usage/cpu usage/disk usage.
    – Navern
    Commented Apr 21, 2015 at 9:15
  • Max workers reached is only consequence of your iowait load. You reqquests can't be finished fast enough by web-server.
    – Navern
    Commented Apr 21, 2015 at 9:19
  • You should enable mysql slow log in your my.cnf or in runtime. Current path to mysql slow log(mysql 5.6): select @@slow_query_log_file; You should set variable slow_launch_time approprietely. Also you can try to use pt-query-digest tool from percona tools.
    – Navern
    Commented Apr 21, 2015 at 9:29
  • Found it and have enabled it.
    – Epodax
    Commented Apr 21, 2015 at 9:41
  • @Navern - What should I watch for with the Innodb buffer pool?
    – Epodax
    Commented Apr 21, 2015 at 9:56

1 Answer 1


Below is link to a great article that will help determine the right settings for the mpm_prefork_module.

The idea is to run a script that will show you how much memory is consumed by each Apache process, then using that information to configure the settings.


Script: http://cloudinservice.com/wp-content/uploads/2011/03/ap.sh.zip

MaxClients & ServerLimit.

unzip ap.sh.zip

sh ap.sh

The output will be something like that:

Apache Memory Usage (MB): 1372.6 Average Proccess Size (MB): 54.9041

Try to execute it several times to compare the numbers; good results will be shown when server is under a heavy load. Now when you know average amount of memory consumed by Apache and total amount of memory of your server, it is possible to calculate value to be used for MaxClients setting.

For example, if in average one your Apache process consumes 50MB RAM and server RAM is 2GB, and you want to leave 512MB for the rest processes, then: MaxClients = (2GB – 512MB)/50MB = 30.72 ~ 30.

ServerLimit is, as I understand, the same thing, but while MaxClient setting can be changed on the go without a need to restart Apache, for new ServerLimit value to take effect Apache restart is required.

MaxClients should always be <= ServerLimit. To make it easy, I set ServerLimit = MaxClients calculated by above formula.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .