A
A
AstonMartin2010-10-03 19:17:08
Apache HTTP Server
AstonMartin, 2010-10-03 19:17:08

How to reduce Apache's memory consumption?

There is a dedik on CentOS 5.3 i386 2GB RAM. Soft:
2.2.3-43.el5.centos.3
5.2.14-1.el5.remi
php-eaccelerator.i386
mysql.i386 5.1.36-1.el5.remi

In the top, the picture is often like this:
PID USER PR NI Virt Res SHR S% CPU% Mem Time +
Command 29689 Apache 17 0 250m 189m 28m d 34 9.4 0: 12.28
HTTPD 29472 Apache 16 0 240m 175m 23m S 7 8.7 0: 35.23
HTTPD 29473 Apache 16 0 242m 186m 34m S 6 9.2 0: 26.83 httpd

Accordingly, if the load increases, then Apache either stops processing requests in time or the system goes into swap (depending on MaxClients):
Now in the Apache config: Loaded modules: Actually, the question is how to make Apache not consume so much memory per process?

ListenBacklog 1024
StartServers 3
MinSpareServers 3
MaxSpareServers 5
ServerLimit 15
MaxClients 15
MaxRequestsPerChild 500


LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule cache_module modules/mod_cache.so
LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule mime_module modules/mod_mime.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
LoadModule rpaf_module modules/mod_rpaf-2.0.so


Answer the question

In order to leave comments, you need to log in

9 answer(s)
Q
Q2W, 2010-10-03
@Q2W

We had a similar problem in one project. Only we had mod_perl.
Apaches weighed a lot too.
So, we took all the pearl code and loaded it into Apache in advance directly into the root process. By specifying something like PerlRequire /path/to/script/with/all/includes.pl in the Apache config.
And since Apache breeds forks, most of the memory occupied by our pearl application is used only once, and not once per Apache process.
So, if your php application also lives in Apache's memory, dig in this direction.

G
gro, 2010-10-03
@gro

We reduced the memory consumed by Apache by tearing it down and replacing it with nginx

B
bigdogsru, 2010-10-03
@bigdogsru

Nginx on the frontend to return statics already sufficiently reduces Apache's memory consumption (I more than doubled the decrease on the VPS).

S
Sergey, 2010-10-03
@bondbig

Apparently, the code executed by the workers is large and thick. Optimize the web application. Well, do not load unused modules.

A
agh, 2010-10-04
@agh

To begin with, it’s very easy to install nginx as a frontend, really ...
Here is a rather old entry, but it doesn’t change the essence, only nginx itself is fresher from stable, collect from sources
www.odmin4eg.ru/2008/nginx-na-ubuntu-prosto/

P
pwlnw, 2010-10-04
@pwlnw

Find which of the scripts eats so much.
If these are rarely called single scripts, then you can forcibly stop the large Apache at the end of the script by calling the php apache_child_terminate function.
If the scripts are called frequently, redirect nginx to a separate copy of Apache with a reduced number of MaxClients.

V
Vlad Zhivotnev, 2010-10-04
@inkvizitor68sl

Do KeepAlive Off, transfer the statics to nginx a little more than entirely, and leave the maximum number of processes 3-5 for Apache.
On Atom 1.6, such a config gave me 20 random pages from Drupal per second, eating about 400 MB of memory. But here, of course, you need a good percentage - a dedicated core, and not a scrap from OpenVZ or Xen.

S
Sergey, 2010-10-04
@seriyPS

I recommend to remove Apache and use php in fast cgi mode
. Moreover, the latest versions of PHP support php-fpm without modifications.
If rewrite rules are used, then it is not difficult to rewrite under Nginx.

A
AstonMartin, 2010-10-11
@AstonMartin

And if you try to switch to mpm_worker, should there be a gain in memory usage?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question