Optimising Apache

Hi I am suspecting that Apache is eating up a lot of my memory, here are the first few entries of ps:

%MEM %CPU RSS VSZ COMMAND

9.2 0.5 46952 102668 /usr/sbin/apache2 -k start

8.8 0.4 45208 101556 /usr/sbin/apache2 -k start

8.7 0.4 44752 101636 /usr/sbin/apache2 -k start

6.2 0.3 31936 87640 /usr/sbin/apache2 -k start

6.2 0.2 31996 87840 /usr/sbin/apache2 -k start

4.7 0.0 24084 77840 /usr/sbin/apache2 -k start

2.8 0.2 14352 133116 /usr/sbin/mysqld

2.1 0.0 10932 15288 /usr/bin/perl /usr/share/webmin/miniserv.pl /etc/webmin/miniserv.conf

1.9 0.0 9812 14056 /usr/bin/perl /usr/share/usermin/miniserv.pl /etc/usermin/miniserv.conf

1.2 0.0 6136 10888 /usr/bin/python /var/lib/mailman/bin/qrunner –runner=OutgoingRunner:0:1 -s

1.1 0.0 6096 10912 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=BounceRunner:0:1 -s

1.1 0.0 6084 10860 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=NewsRunner:0:1 -s

1.1 0.0 6048 10864 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=CommandRunner:0:1 -s

1.1 0.0 6040 10800 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=VirginRunner:0:1 -s

1.1 0.0 6036 10884 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=IncomingRunner:0:1 -s

1.1 0.0 6036 10800 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=RetryRunner:0:1 -s

1.1 0.0 6032 10888 /usr/bin/python /var/lib/mailman/bin/qrunner --runner=ArchRunner:0:1 -s

10.2 0.5 51980 108792 /usr/sbin/apache2 -k start

Can anyone suggest what I should do to optimise apache mem usage?

10 Replies

Run ps aux --sort -rss to give a sorted list of processes by memory usage.

What size is your linode? What's your apache max clients value? You should also disable any apache modules you don't use.

Result (first few lines):

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
www-data  6020  0.4 11.9 115880 61060 ?        S    04:07   0:08 /usr/sbin/apach
www-data  9901  0.7 11.4 112800 58436 ?        S    04:34   0:03 /usr/sbin/apach
www-data  9909  0.5  9.6 104512 48920 ?        S    04:34   0:02 /usr/sbin/apach
www-data  9910  0.7  9.1 102020 46860 ?        S    04:34   0:03 /usr/sbin/apach
www-data 10605  0.4  8.8 100448 45188 ?        S    04:37   0:01 /usr/sbin/apach
www-data  9908  0.6  5.6  84684 28652 ?        S    04:34   0:03 /usr/sbin/apach
root      3513  0.0  4.1  77840 20996 ?        Ss   03:51   0:00 /usr/sbin/apach
mysql     2124  0.2  2.2 132272 11332 ?        Ssl  03:50   0:06 /usr/sbin/mysql
root      3558  0.0  2.1  15288 10916 ?        Ss   03:51   0:00 /usr/bin/perl /
root      3554  0.0  1.9  14056  9804 ?        Ss   03:51   0:00 /usr/bin/perl /
root      3250  0.0  0.8  58492  4092 ?        Ss   03:50   0:00 /usr/bin/php5-f
www-data  3252  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3253  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3254  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3255  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3257  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3258  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3259  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3260  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3261  0.0  0.6  58492  3332 ?        S    03:50   0:00 /usr/bin/php5-f
www-data  3251  0.0  0.6  58492  3328 ?        S    03:50   0:00 /usr/bin/php5-f

Size of my linode is 512mb

Max clients value is 24.

How can I know which modules are running and which I can disable?

Thanks

Are you running php-fpm with apache prefork?

To check your apache modules run apache2ctl -M or httpd -M depending on your distribution.

If you see prefork in the output you're using apache prefork.

Prefork:

Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 actions_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 dav_module (shared)
 dav_fs_module (shared)
 dav_svn_module (shared)
 authz_svn_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 fcgid_module (shared)
 ldap_userdir_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 proxy_module (shared)
 proxy_balancer_module (shared)
 proxy_connect_module (shared)
 proxy_http_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 ruby_module (shared)
 setenvif_module (shared)
 ssl_module (shared)
 status_module (shared)
 suexec_module (shared)
Syntax OK

You have php processes running and a php module in apache, find out which you're using and remove the one you're not.

Unless you're using svn or web dav you can disable the following modules

dav_module (shared)

davfsmodule (shared)

davsvnmodule (shared)

authzsvnmodule (shared)

these are for proxies if you don't use them disable them

proxy_module (shared)

proxybalancermodule (shared)

proxyconnectmodule (shared)

proxyhttpmodule (shared)

You an disable a module with a2dismod

ok that seems to have been successful in freeing up memory. Is there anything else I should do as regards to optimisation?

Using modexpires to set browser cache times for static content (i.e. images) is a good idea it saves requests to your server, also enabling moddeflate to gzip content will speed up page loads for your users.

I am still getting out of memory errors, logging to Lish I can see such problems:

Killed process 17360 (apache2) total-vm:239140kB, anon-rss:90524kB, file-rss:11084kB

Out of memory: Kill process 20387 (apache2) score 174 or sacrifice child

Killed process 20387 (apache2) total-vm:195052kB, anon-rss:80256kB, file-rss:11188kB

Out of memory: Kill process 27927 (apache2) score 193 or sacrifice child

Killed process 27927 (apache2) total-vm:210392kB, anon-rss:71720kB, file-rss:10584kB

Out of memory: Kill process 31105 (apache2) score 314 or sacrifice child

Killed process 31105 (apache2) total-vm:301676kB, anon-rss:96544kB, file-rss:11056kB

Out of memory: Kill process 11698 (apache2) score 194 or sacrifice child

Killed process 11698 (apache2) total-vm:209428kB, anon-rss:57528kB, file-rss:10912kB

Out of memory: Kill process 15455 (apache2) score 178 or sacrifice child

Killed process 15455 (apache2) total-vm:197244kB, anon-rss:67324kB, file-rss:11088kB

Out of memory: Kill process 16286 (apache2) score 170 or sacrifice child

Killed process 16286 (apache2) total-vm:191056kB, anon-rss:81816kB, file-rss:11172kB

Out of memory: Kill process 20750 (apache2) score 176 or sacrifice child

Killed process 20750 (apache2) total-vm:196980kB, anon-rss:51100kB, file-rss:11104kB

Out of memory: Kill process 23842 (apache2) score 106 or sacrifice child

Killed process 23842 (apache2) total-vm:140764kB, anon-rss:36784kB, file-rss:11060kB

Out of memory: Kill process 26947 (apache2) score 177 or sacrifice child

Killed process 26947 (apache2) total-vm:201232kB, anon-rss:85516kB, file-rss:5608kB

Out of memory: Kill process 27700 (apache2) score 198 or sacrifice child

Killed process 27700 (apache2) total-vm:213572kB, anon-rss:87204kB, file-rss:10200kB

Out of memory: Kill process 27690 (apache2) score 189 or sacrifice child

Killed process 27690 (apache2) total-vm:206240kB, anon-rss:85276kB, file-rss:9892kB

Out of memory: Kill process 28459 (apache2) score 184 or sacrifice child

Killed process 28459 (apache2) total-vm:204356kB, anon-rss:27720kB, file-rss:10200kB

Out of memory: Kill process 3762 (apache2) score 72 or sacrifice child

Killed process 3762 (apache2) total-vm:117180kB, anon-rss:31216kB, file-rss:8224kB

Out of memory: Kill process 2868 (apache2) score 64 or sacrifice child

Killed process 2868 (apache2) total-vm:116804kB, anon-rss:16088kB, file-rss:3128kB

Out of memory: Kill process 2124 (mysqld) score 49 or sacrifice child

Killed process 2124 (mysqld) total-vm:143176kB, anon-rss:13476kB, file-rss:0kB

what does ps aux –sort -rss show now? Also install munin it's a great resource tracker.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct