2

I am currently working on a site which uses Apache running on the prefork memory model. The following is the configuration from httpd.conf

<IfModule prefork.c> 
  StartServers            30
  MinSpareServers         15
  MaxSpareServers         30
  MaxClients              96 
  ServerLimit             512
  MaxRequestsPerChild     0
</IfModule>

The following is a sample line from top

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           
29261 apache    15   0 1003m 231m  53m S 16.3  2.9   1:47.68 httpd              

The following are the loaded apache modules

core prefork http_core mod_so mod_auth_basic mod_authn_file 
mod_authz_host mod_authz_user mod_include mod_log_config 
mod_logio mod_env mod_ext_filter mod_mime_magic mod_expires 
mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime 
mod_status mod_autoindex mod_info mod_vhost_alias mod_negotiation 
mod_dir mod_actions mod_alias mod_rewrite mod_cgi mod_version 
mod_realip2 mod_php5 mod_ssl

I am not sure if all of these modules are used.

The following are the php extensions loaded

date, libxml, openssl, pcre, zlib, bz2, calendar, ctype, 
curl, hash, filter, ftp, gettext, gmp, session, iconv, 
posix, Reflection, standard, shmop, SimpleXML, SPL, sockets, 
exif, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xml, 
apache2handler, memcache, uploadprogress, dbase, dom, 
eAccelerator, gd, json, mbstring, mcrypt, memcached, mongo, 
mysql, mysqli, newrelic, PDO, pdo_mysql, pdo_sqlite, xmlreader, 
xmlwriter, xsl, zip

Why would apache be using so much memory per process? Is ti because of these modules? If so are there memoryhogs in there which I can start looking at to see if they are being used? Or could it be because of the php extensions? Any memoryhogs in there?

The php memory limit is set to 256MB.

Eaccelerator is configured with 512MB memory.

The server is not able to handle even slightly above average loads as swap usage starts as soon as traffic increases making the system unresponsive. The server has a total of 8GB of RAM and it is a dedicated quad core server.

Thanks in advance for any help in solving this problem.

3
  • 1
    Bad designed application?!
    – mailq
    Oct 8, 2011 at 23:46
  • 4
    You are looking at the wrong field; pay attention to the RES field, not VIRT.
    – psusi
    Oct 9, 2011 at 1:06
  • But both would be indicative of the memory usages right? My concern was that I see the usages way lower than this in other servers.
    – anoopjohn
    Oct 9, 2011 at 22:32

2 Answers 2

3

First, about determining the memory usage. The VSS/VSIZE/VIRT is not the actual usage of RAM by the process (as @psusi noted as well). There are some tools that can calculate the actual usage, one is a very helpful tool by Peter Willis from Yahoo!:

http://psydev.syw4e.info/new/misc/meminfo.pl

Two important notes about your config. It is usually not a good idea to use:

MaxRequestsPerChild     0

Unless you wrote the application yourself. It is pretty common to have memory leaks so after several hundred (or thousands) of requests the memory usage of the child will grow and eventually exceed a reasonable level. You should probably set this to ~200 and see how much memory they use after 200 requests. This has to be weighed with the amount of time server spawning takes. If it takes several seconds and lots of resources to fork new children you want to increase the value (or even decrease it if it is lightweight).

Secondly, unless you are specifically using thread-unsafe modules prefork isn't really preferred as it uses more memory:

http://httpd.apache.org/docs/2.0/misc/perf-tuning.html#compiletime

The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory.

Lastly, you'll probably want to go through and eliminate unneeded modules. As far as I know there is no custom module to help do this and you usually end up trying to remove as many as possible and verify that the system still works. This is basically guess-and-check but is worth the hour or two of time it will take to do.

2
  • Thank you for the response. I set MaxRequestsPerChild to 1000. The memory usage per thread has gone down to 800/150 (VIRT/RES). I will play with that and see what works best. We had issues with fcgid when we had tried that in the past. Have not tried worker yet. I will try out the unneeded modules issue and see if I can eliminate anything. Were there any specific memory hogs in the modules list that I should focus on first?
    – anoopjohn
    Oct 9, 2011 at 22:23
  • Yes, mod_php and not using fastcgi: fastcgi.com/drupal/node/5?q=node/10
    – polynomial
    Oct 10, 2011 at 1:38
2

There is also a reason why ps says every process is like that.. it's not every process is using that much memory.. see the following for a good read about ps and memory

http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html

You must log in to answer this question.

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