Ubuntu – Limit the RAM consumption by Apache

When i am trying to setup a new server, most of the time i just used the default settings of Apache. But sometimes if the server is not equipped with enough RAM, the Apache service may consume all the server resources causing server failure. Here is an example for limited the resource comsumption by Apache.

I have a Rackspace server with only 1GB RAM running Ubuntu 10.04. The following setting is part of the original /etc/apache2/apache2.conf

...
<IfModule mpm_prefork_module>
  StartServers          5
  MinSpareServers       5
  MaxSpareServers      10
  MaxClients          150
  MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_worker_module>
  StartServers          2
  MinSpareThreads      25
  MaxSpareThreads      75
  ThreadLimit          64
  ThreadsPerChild      25
  MaxClients          150
  MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_event_module>
  StartServers          2
  MaxClients          150
  MinSpareThreads      25
  MaxSpareThreads      75
  ThreadLimit          64
  ThreadsPerChild      25
  MaxRequestsPerChild   0
</IfModule>
...

 

Restart the Apache with the following new configuration, it should consume less server resources.

<IfModule mpm_prefork_module>
  StartServers          5
  MinSpareServers       1
  MaxSpareServers       2
  MaxClients           20
  MaxRequestsPerChild 100
</IfModule>
<IfModule mpm_worker_module>
  StartServers          2
  MinSpareThreads      10
  MaxSpareThreads      30
  ThreadLimit          64
  ThreadsPerChild      10
  MaxClients           20
  MaxRequestsPerChild 100
</IfModule>
<IfModule mpm_event_module>
  StartServers          2
  MaxClients           20
  MinSpareThreads      10
  MaxSpareThreads      30
  ThreadLimit          64
  ThreadsPerChild      10
  MaxRequestsPerChild 100
</IfModule>

 

Please note that this is only an example for reference only, it does not guarantee it could optimize the Apache service on your server since performance tuning is always a big question.

Reference: Ubuntu Forums – Apache is running multiple processes and it’s eating RAM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.