Skip to content

Putting Apache on a diet - how to get a lean configuration, Part 1

In this article I'm going to go over some of the details of how Apache works, and uses memory. As you will see, the apache processes that serve requests will grow to include the amount of memory they need for a particular request, and they will still be using that memory, even when they are serving something simple like a .css file or an image.

For this reason, the first limitation you are likely to encounter running Apache is a limitation on memory. I will explore this topic and show you how you can do the same.

The first thing need to determine about Apache is what mode it is running in. If your plan is to use Apache with php via mod_apache, then the prevailing wisdom for many years has been that there may be library extensions in PHP that are not thread safe. For this reason, people have tended to avoid running Apache as a threaded server, for fear that scripts may randomly die producing the dreaded 500 Internal server error pages we all know and love.

This fear may be overstated depending on the nature of your php code, but the defaults for apache packages I've seen, seem almost always to be using the prefork worker.

Prefork vs Worker?

So the first question you might be asking yourself is, which mode is my current apache server running in? There is a simple safe way to determine this -- run the httpd(apache) program with a specific command line switch. There are programs like which and whereis that might help you locate it, if you don't know where it is.


whereis httpd
 


CODE:
httpd: /usr/sbin/httpd.worker /usr/sbin/httpd /usr/sbin/httpd.event /etc/httpd /usr/share/man/man8/httpd.8.gz

So let's run the /usr/sbin/httpd with the -h for help and see what happens:





/usr/sbin/httpd -h
 


CODE:
Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file]                        [-C "directive"] [-c "directive"]                        [-k start|restart|graceful|graceful-stop|stop]                        [-v] [-V] [-h] [-l] [-L] [-t] [-S] Options:   -D name            : define a name for use in <IfDefine name> directives   -d directory       : specify an alternate initial ServerRoot   -f file            : specify an alternate ServerConfigFile   -C "directive"     : process directive before reading config files   -c "directive"     : process directive after reading config files   -e level           : show startup errors of level (see LogLevel)   -E file            : log startup errors to file   -v                 : show version number   -V                 : show compile settings   -h                 : list available command line options (this page)   -l                 : list compiled in modules   -L                 : list available configuration directives   -t -D DUMP_VHOSTS  : show parsed settings (currently only vhost settings)   -S                 : a synonym for -t -D DUMP_VHOSTS   -t -D DUMP_MODULES : show all loaded modules    -M                 : a synonym for -t -D DUMP_MODULES   -t                 : run syntax check for config files

Well this looks promising --- httpd -l should give us a list of modules!



/usr/sbin/httpd -l
 


CODE:
Compiled in modules:   core.c   prefork.c   http_core.c   mod_so.c

So as you can see, there's a small group of core modules compiled into Apache, and in this case the server is running prefork and NOT running worker (aka the threaded server).

What is Prefork?

In unix, "forking" is a way for a parent program to essentially clone a copy of itself as a seperate child program. For this reason when you run ps or top you'll see a number of different httpd processes running.


ps aux | grep httpd
 


CODE:
root     11991  0.0  0.3 329024 12616 ?        Ss   Aug23   0:39 /usr/sbin/httpd apache   20023  0.0  1.5 395520 49296 ?        S    Sep04   0:40 /usr/sbin/httpd apache   20053  0.0  1.5 396508 51744 ?        S    Sep04   0:31 /usr/sbin/httpd apache   20066  0.0  1.5 395484 48636 ?        S    Sep04   0:31 /usr/sbin/httpd apache   20071  0.0  1.9 412008 64244 ?        S    Sep04   0:37 /usr/sbin/httpd apache   20103  0.0  1.5 396512 50336 ?        S    Sep04   0:34 /usr/sbin/httpd apache   20105  0.0  1.5 395520 49664 ?        S    Sep04   0:38 /usr/sbin/httpd apache   20106  0.0  1.8 409856 60416 ?        S    Sep04   0:41 /usr/sbin/httpd apache   22282  0.0  1.5 396624 49892 ?        S    Sep04   0:32 /usr/sbin/httpd apache   22283  0.0  1.5 396508 49976 ?        S    Sep04   0:36 /usr/sbin/httpd apache   22286  0.0  1.5 395528 49912 ?        S    Sep04   0:35 /usr/sbin/httpd apache   22287  0.0  1.5 394512 49244 ?        S    Sep04   0:34 /usr/sbin/httpd apache   22288  0.0  1.5 396508 50652 ?        S    Sep04   0:33 /usr/sbin/httpd apache   22289  0.0  1.5 395484 49504 ?        S    Sep04   0:40 /usr/sbin/httpd apache   22295  0.0  1.5 395484 48864 ?        S    Sep04   0:31 /usr/sbin/httpd apache   22296  0.0  1.5 395508 49764 ?        S    Sep04   0:34 /usr/sbin/httpd apache   22297  0.0  1.5 395484 49396 ?        S    Sep04   0:31 /usr/sbin/httpd apache   22298  0.0  1.5 395484 50456 ?        S    Sep04   0:34 /usr/sbin/httpd apache   22299  0.0  2.0 413024 65020 ?        S    Sep04   0:29 /usr/sbin/httpd apache   22322  0.0  1.5 395552 49396 ?        S    Sep04   0:35 /usr/sbin/httpd apache   26265  0.0  1.5 395484 49192 ?        S    Sep04   0:25 /usr/sbin/httpd root     30354  0.0  0.0   6056   652 pts/0    S+   13:15   0:00 grep httpd

There are some interesting things to note about this output. First off we have one httpd running as root. Then we have 20 httpd's running as apache.

On this particular server, if you look in the httpd.conf file which is being loaded when the server starts, you find this configuration section:

CODE:
<IfModule prefork.c> StartServers       8 MinSpareServers    5 MaxSpareServers   20 ServerLimit      256  MaxClients       256 MaxRequestsPerChild  4000 </IfModule>

So as you can see, the MaxSpareServers of 20 matches the number of child processes we have, and this is because this particular server has been running for a while, and has seen some periods where it was receiving enough traffic that apache forked additional child processes, keeping those 20 child servers around. If however, we restart apache, what will we find (assuming there is little to no load when it restarts).

CODE:
root     30498  0.3  0.3 329036 11204 ?        Ss   13:22   0:00 /usr/sbin/httpd apache   30501  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30502  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30503  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30504  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30505  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30506  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30507  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd apache   30508  0.0  0.1 329036  6028 ?        S    13:22   0:00 /usr/sbin/httpd root     30521  0.0  0.0   6056   652 pts/0    S+   13:22   0:00 grep httpd

I'm guessing nobody will be surprised to find that we have exactly 8 child processes thanks to the "StartServers 8" configuration item. Now you might be interested in the other parameters. Take the time to read about them in the apache documentation! I am going to talk about the "MaxRequestsPerChild 4000" parameter.

MaxRequestsPerChild

So you might be wondering at this point if apache ever kills one of its child processes?

The answer is yes! Controlling the killing of child processes is what the MaxRequestsPerChild parameter does. Any child will service 4k HTTP requests before it is killed by the parent, and replaced by a new forked child process.

You also might be wondering why Apache doesn't just keep a child process going forever. One reason, is to return memory back to the operating system.

If we run ps aux | more, so we can see the column headers, we'll find that several of the headers are displaying memory statistics.

CODE:
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND root     11991  0.0  0.3 329024 12616 ?        Ss   Aug23   0:39 /usr/sbin/httpd apache   20023  0.0  1.5 395520 49296 ?        S    Sep04   0:40 /usr/sbin/httpd apache   20053  0.0  1.5 396508 51744 ?        S    Sep04   0:31 /usr/sbin/httpd apache   20066  0.0  1.5 395484 48636 ?        S    Sep04   0:31 /usr/sbin/httpd apache   20071  0.0  1.9 412008 64244 ?        S    Sep04   0:37 /usr/sbin/httpd

With these flags for the ps command, we can now see the VSZ and RSS columns, which display memory usage for the process, are showing a variety of different numbers (all of which are in KB) to indicate the amount of memory the process requires. Or do they?

As it turns out these numbers give you a general idea of what the process would require in a vacuum, but doesn't really give you accurate information. This is because substantial amounts of memory use needed for the code segments of the program are in shared libraries which can be shared by all the processes that need them, without having to make a seperate copy of the code (hence the explanation for the word "shared" in the name). We need a better utility to look at the real memory usage.

We can use pmap to look at a specific child process by passing in it's process id:


pmap -d 30548
 



[root@penny conf]# pmap -d 30548
30548: /usr/sbin/httpd
Address Kbytes Mode Offset Device Mapping
00002b937f999000 312 r-x-- 0000000000000000 0fd:00002 httpd
00002b937f9e7000 100 rw-s- 0000000000000000 000:0007c [ anon ]
00002b937fa41000 1340 rw--- 00002b937fa41000 000:00000 [ anon ]
00002b937fbe6000 16 rw--- 000000000004d000 0fd:00002 httpd
00002b937fbea000 12 rw--- 00002b937fbea000 000:00000 [ anon ]
00002b937fbed000 112 r-x-- 0000000000000000 0fd:00002 ld-2.5.so
00002b937fc09000 1032 rw--- 00002b937fc09000 000:00000 [ anon ]
00002b937fd0b000 88 rw-s- 0000000000000000 000:0007c [ anon ]
00002b937fe09000 4 r---- 000000000001c000 0fd:00002 ld-2.5.so
00002b937fe0a000 4 rw--- 000000000001d000 0fd:00002 ld-2.5.so
00002b937fe0b000 520 r-x-- 0000000000000000 0fd:00002 libm-2.5.so
00002b937fe8d000 2044 ----- 0000000000082000 0fd:00002 libm-2.5.so
00002b938008c000 4 r---- 0000000000081000 0fd:00002 libm-2.5.so
00002b938008d000 4 rw--- 0000000000082000 0fd:00002 libm-2.5.so
00002b938008e000 120 r-x-- 0000000000000000 0fd:00002 libpcre.so.0.0.1
00002b93800ac000 2048 ----- 000000000001e000 0fd:00002 libpcre.so.0.0.1
00002b93802ac000 4 rw--- 000000000001e000 0fd:00002 libpcre.so.0.0.1
00002b93802ad000 84 r-x-- 0000000000000000 0fd:00002 libselinux.so.1
00002b93802c2000 2048 ----- 0000000000015000 0fd:00002 libselinux.so.1
00002b93804c2000 8 rw--- 0000000000015000 0fd:00002 libselinux.so.1
00002b93804c4000 8 rw--- 00002b93804c4000 000:00000 [ anon ]
00002b93804c6000 100 r-x-- 0000000000000000 0fd:00002 libaprutil-1.so.0.2.7
00002b93804df000 2048 ----- 0000000000019000 0fd:00002 libaprutil-1.so.0.2.7
00002b93806df000 4 rw--- 0000000000019000 0fd:00002 libaprutil-1.so.0.2.7
00002b93806e0000 36 r-x-- 0000000000000000 0fd:00002 libcrypt-2.5.so
00002b93806e9000 2044 ----- 0000000000009000 0fd:00002 libcrypt-2.5.so
00002b93808e8000 4 r---- 0000000000008000 0fd:00002 libcrypt-2.5.so
00002b93808e9000 4 rw--- 0000000000009000 0fd:00002 libcrypt-2.5.so
00002b93808ea000 184 rw--- 00002b93808ea000 000:00000 [ anon ]
00002b9380918000 228 r-x-- 0000000000000000 0fd:00002 libldap-2.3.so.0.2.31
00002b9380951000 2048 ----- 0000000000039000 0fd:00002 libldap-2.3.so.0.2.31
00002b9380b51000 8 rw--- 0000000000039000 0fd:00002 libldap-2.3.so.0.2.31
...
00002b9383942000 8 r-x-- 0000000000000000 0fd:00002 mod_auth_basic.so
00002b9383944000 2044 ----- 0000000000002000 0fd:00002 mod_auth_basic.so
00002b9383b43000 8 rw--- 0000000000001000 0fd:00002 mod_auth_basic.so
00002b9383b45000 24 r-x-- 0000000000000000 0fd:00002 mod_auth_digest.so
00002b9383b4b000 2044 ----- 0000000000006000 0fd:00002 mod_auth_digest.so
00002b9383d4a000 8 rw--- 0000000000005000 0fd:00002 mod_auth_digest.so
00002b9383d4c000 8 r-x-- 0000000000000000 0fd:00002 mod_authn_file.so
00002b9383d4e000 2044 ----- 0000000000002000 0fd:00002 mod_authn_file.so
00002b9383f4d000 8 rw--- 0000000000001000 0fd:00002 mod_authn_file.so
00002b9383f4f000 8 r-x-- 0000000000000000 0fd:00002 mod_authn_alias.so
00002b9383f51000 2044 ----- 0000000000002000 0fd:00002 mod_authn_alias.so
00002b9384150000 8 rw--- 0000000000001000 0fd:00002 mod_authn_alias.so
00002b9384152000 4 r-x-- 0000000000000000 0fd:00002 mod_authn_anon.so
00002b9384153000 2048 ----- 0000000000001000 0fd:00002 mod_authn_anon.so
00002b9384353000 8 rw--- 0000000000001000 0fd:00002 mod_authn_anon.so
00002b9384355000 4 r-x-- 0000000000000000 0fd:00002 mod_authn_dbm.so
00002b9384356000 2048 ----- 0000000000001000 0fd:00002 mod_authn_dbm.so
00002b9384556000 8 rw--- 0000000000001000 0fd:00002 mod_authn_dbm.so
00002b9384558000 4 r-x-- 0000000000000000 0fd:00002 mod_authn_default.so
00002b9384559000 2044 ----- 0000000000001000 0fd:00002 mod_authn_default.so
00002b9384758000 8 rw--- 0000000000000000 0fd:00002 mod_authn_default.so
00002b938475a000 8 r-x-- 0000000000000000 0fd:00002 mod_authz_host.so
00002b938475c000 2044 ----- 0000000000002000 0fd:00002 mod_authz_host.so
00002b938495b000 8 rw--- 0000000000001000 0fd:00002 mod_authz_host.so
00002b938495d000 4 r-x-- 0000000000000000 0fd:00002 mod_authz_user.so
00002b938495e000 2044 ----- 0000000000001000 0fd:00002 mod_authz_user.so
00002b9384b5d000 8 rw--- 0000000000000000 0fd:00002 mod_authz_user.so
00002b9384b5f000 8 r-x-- 0000000000000000 0fd:00002 mod_authz_owner.so
00002b9384b61000 2044 ----- 0000000000002000 0fd:00002 mod_authz_owner.so
00002b9384d60000 8 rw--- 0000000000001000 0fd:00002 mod_authz_owner.so
00002b9384d62000 8 r-x-- 0000000000000000 0fd:00002 mod_authz_groupfile.so
00002b9384d64000 2044 ----- 0000000000002000 0fd:00002 mod_authz_groupfile.so
00002b9384f63000 8 rw--- 0000000000001000 0fd:00002 mod_authz_groupfile.so
00002b9384f65000 8 r-x-- 0000000000000000 0fd:00002 mod_authz_dbm.so
00002b9384f67000 2044 ----- 0000000000002000 0fd:00002 mod_authz_dbm.so
00002b9385166000 8 rw--- 0000000000001000 0fd:00002 mod_authz_dbm.so
00002b9385168000 4 r-x-- 0000000000000000 0fd:00002 mod_authz_default.so
00002b9385169000 2044 ----- 0000000000001000 0fd:00002 mod_authz_default.so
00002b9385368000 8 rw--- 0000000000000000 0fd:00002 mod_authz_default.so
00002b938536a000 48 r-x-- 0000000000000000 0fd:00002 mod_ldap.so
00002b9385376000 2044 ----- 000000000000c000 0fd:00002 mod_ldap.so
00002b9385575000 8 rw--- 000000000000b000 0fd:00002 mod_ldap.so
00002b9385577000 24 r-x-- 0000000000000000 0fd:00002 mod_authnz_ldap.so
00002b938557d000 2048 ----- 0000000000006000 0fd:00002 mod_authnz_ldap.so
00002b938577d000 8 rw--- 0000000000006000 0fd:00002 mod_authnz_ldap.so
00002b938577f000 36 r-x-- 0000000000000000 0fd:00002 mod_include.so
00002b9385788000 2048 ----- 0000000000009000 0fd:00002 mod_include.so
00002b9385988000 8 rw--- 0000000000009000 0fd:00002 mod_include.so
00002b938598a000 20 r-x-- 0000000000000000 0fd:00002 mod_log_config.so
00002b938598f000 2044 ----- 0000000000005000 0fd:00002 mod_log_config.so
00002b9385b8e000 8 rw--- 0000000000004000 0fd:00002 mod_log_config.so
00002b9385b90000 8 r-x-- 0000000000000000 0fd:00002 mod_logio.so
00002b9385b92000 2044 ----- 0000000000002000 0fd:00002 mod_logio.so
00002b9385d91000 8 rw--- 0000000000001000 0fd:00002 mod_logio.so
00002b9385d93000 4 r-x-- 0000000000000000 0fd:00002 mod_env.so
00002b9385d94000 2048 ----- 0000000000001000 0fd:00002 mod_env.so
00002b9385f94000 8 rw--- 0000000000001000 0fd:00002 mod_env.so
00002b9385f96000 16 r-x-- 0000000000000000 0fd:00002 mod_ext_filter.so
00002b9385f9a000 2044 ----- 0000000000004000 0fd:00002 mod_ext_filter.so
00002b9386199000 8 rw--- 0000000000003000 0fd:00002 mod_ext_filter.so
00002b938619b000 20 r-x-- 0000000000000000 0fd:00002 mod_mime_magic.so
00002b93861a0000 2044 ----- 0000000000005000 0fd:00002 mod_mime_magic.so
00002b938639f000 8 rw--- 0000000000004000 0fd:00002 mod_mime_magic.so
00002b93863a1000 8 r-x-- 0000000000000000 0fd:00002 mod_expires.so
00002b93863a3000 2044 ----- 0000000000002000 0fd:00002 mod_expires.so
00002b93865a2000 8 rw--- 0000000000001000 0fd:00002 mod_expires.so
00002b93865a4000 20 r-x-- 0000000000000000 0fd:00002 mod_deflate.so
00002b93865a9000 2044 ----- 0000000000005000 0fd:00002 mod_deflate.so
00002b93867a8000 8 rw--- 0000000000004000 0fd:00002 mod_deflate.so
00002b93867aa000 12 r-x-- 0000000000000000 0fd:00002 mod_headers.so
00002b93867ad000 2048 ----- 0000000000003000 0fd:00002 mod_headers.so
00002b93869ad000 8 rw--- 0000000000003000 0fd:00002 mod_headers.so
00002b93869af000 8 r-x-- 0000000000000000 0fd:00002 mod_usertrack.so
00002b93869b1000 2048 ----- 0000000000002000 0fd:00002 mod_usertrack.so
00002b9386bb1000 8 rw--- 0000000000002000 0fd:00002 mod_usertrack.so
00002b9386bb3000 8 r-x-- 0000000000000000 0fd:00002 mod_setenvif.so
00002b9386bb5000 2048 ----- 0000000000002000 0fd:00002 mod_setenvif.so
00002b9386db5000 8 rw--- 0000000000002000 0fd:00002 mod_setenvif.so
00002b9386db7000 16 r-x-- 0000000000000000 0fd:00002 mod_mime.so
00002b9386dbb000 2044 ----- 0000000000004000 0fd:00002 mod_mime.so
00002b9386fba000 8 rw--- 0000000000003000 0fd:00002 mod_mime.so
00002b9386fbc000 84 r-x-- 0000000000000000 0fd:00002 mod_dav.so
00002b9386fd1000 2044 ----- 0000000000015000 0fd:00002 mod_dav.so
00002b93871d0000 8 rw--- 0000000000014000 0fd:00002 mod_dav.so
00002b93871d2000 16 r-x-- 0000000000000000 0fd:00002 mod_status.so
00002b93871d6000 2044 ----- 0000000000004000 0fd:00002 mod_status.so
00002b93873d5000 8 rw--- 0000000000003000 0fd:00002 mod_status.so
00002b93873d7000 32 r-x-- 0000000000000000 0fd:00002 mod_autoindex.so
00002b93873df000 2044 ----- 0000000000008000 0fd:00002 mod_autoindex.so
00002b93875de000 8 rw--- 0000000000007000 0fd:00002 mod_autoindex.so
00002b93875e0000 16 r-x-- 0000000000000000 0fd:00002 mod_info.so
00002b93875e4000 2044 ----- 0000000000004000 0fd:00002 mod_info.so
00002b93877e3000 8 rw--- 0000000000003000 0fd:00002 mod_info.so
00002b93877e5000 44 r-x-- 0000000000000000 0fd:00002 mod_dav_fs.so
00002b93877f0000 2044 ----- 000000000000b000 0fd:00002 mod_dav_fs.so
00002b93879ef000 8 rw--- 000000000000a000 0fd:00002 mod_dav_fs.so
00002b93879f1000 8 r-x-- 0000000000000000 0fd:00002 mod_vhost_alias.so
00002b93879f3000 2044 ----- 0000000000002000 0fd:00002 mod_vhost_alias.so
00002b9387bf2000 8 rw--- 0000000000001000 0fd:00002 mod_vhost_alias.so
00002b9387bf4000 28 r-x-- 0000000000000000 0fd:00002 mod_negotiation.so
00002b9387bfb000 2044 ----- 0000000000007000 0fd:00002 mod_negotiation.so
00002b9387dfa000 8 rw--- 0000000000006000 0fd:00002 mod_negotiation.so
00002b9387dfc000 8 r-x-- 0000000000000000 0fd:00002 mod_dir.so
00002b9387dfe000 2044 ----- 0000000000002000 0fd:00002 mod_dir.so
00002b9387ffd000 8 rw--- 0000000000001000 0fd:00002 mod_dir.so
00002b9387fff000 8 r-x-- 0000000000000000 0fd:00002 mod_actions.so
00002b9388001000 2044 ----- 0000000000002000 0fd:00002 mod_actions.so
00002b9388200000 8 rw--- 0000000000001000 0fd:00002 mod_actions.so
00002b9388202000 8 r-x-- 0000000000000000 0fd:00002 mod_speling.so
00002b9388204000 2048 ----- 0000000000002000 0fd:00002 mod_speling.so
00002b9388404000 8 rw--- 0000000000002000 0fd:00002 mod_speling.so
00002b9388406000 8 r-x-- 0000000000000000 0fd:00002 mod_userdir.so
00002b9388408000 2044 ----- 0000000000002000 0fd:00002 mod_userdir.so
00002b9388607000 8 rw--- 0000000000001000 0fd:00002 mod_userdir.so
00002b9388609000 12 r-x-- 0000000000000000 0fd:00002 mod_alias.so
00002b938860c000 2044 ----- 0000000000003000 0fd:00002 mod_alias.so
00002b938880b000 8 rw--- 0000000000002000 0fd:00002 mod_alias.so
00002b938880d000 56 r-x-- 0000000000000000 0fd:00002 mod_rewrite.so
00002b938881b000 2044 ----- 000000000000e000 0fd:00002 mod_rewrite.so
00002b9388a1a000 8 rw--- 000000000000d000 0fd:00002 mod_rewrite.so
00002b9388a1c000 76 r-x-- 0000000000000000 0fd:00002 mod_proxy.so
00002b9388a2f000 2044 ----- 0000000000013000 0fd:00002 mod_proxy.so
00002b9388c2e000 8 rw--- 0000000000012000 0fd:00002 mod_proxy.so
00002b9388c30000 20 r-x-- 0000000000000000 0fd:00002 mod_proxy_balancer.so
00002b9388c35000 2048 ----- 0000000000005000 0fd:00002 mod_proxy_balancer.so
00002b9388e35000 8 rw--- 0000000000005000 0fd:00002 mod_proxy_balancer.so
00002b9388e37000 28 r-x-- 0000000000000000 0fd:00002 mod_proxy_ftp.so
00002b9388e3e000 2044 ----- 0000000000007000 0fd:00002 mod_proxy_ftp.so
00002b938903d000 8 rw--- 0000000000006000 0fd:00002 mod_proxy_ftp.so
00002b938903f000 28 r-x-- 0000000000000000 0fd:00002 mod_proxy_http.so
00002b9389046000 2048 ----- 0000000000007000 0fd:00002 mod_proxy_http.so
00002b9389246000 8 rw--- 0000000000007000 0fd:00002 mod_proxy_http.so
00002b9389248000 8 r-x-- 0000000000000000 0fd:00002 mod_proxy_connect.so
00002b938924a000 2044 ----- 0000000000002000 0fd:00002 mod_proxy_connect.so
00002b9389449000 8 rw--- 0000000000001000 0fd:00002 mod_proxy_connect.so
...
0002b938cf4e000 508 r-x-- 0000000000000000 0fd:00002 libfreetype.so.6.3.10
00002b938cfcd000 2048 ----- 000000000007f000 0fd:00002 libfreetype.so.6.3.10
00002b938d1cd000 20 rw--- 000000000007f000 0fd:00002 libfreetype.so.6.3.10
00002b938d1d2000 1044 r-x-- 0000000000000000 0fd:00002 libX11.so.6.2.0
00002b938d2d7000 2048 ----- 0000000000105000 0fd:00002 libX11.so.6.2.0
00002b938d4d7000 28 rw--- 0000000000105000 0fd:00002 libX11.so.6.2.0
00002b938d4de000 64 r-x-- 0000000000000000 0fd:00002 libXpm.so.4.11.0
00002b938d4ee000 2048 ----- 0000000000010000 0fd:00002 libXpm.so.4.11.0
00002b938d6ee000 4 rw--- 0000000000010000 0fd:00002 libXpm.so.4.11.0
00002b938d6ef000 140 r-x-- 0000000000000000 0fd:00002 libpng12.so.0.10.0
00002b938d712000 2048 ----- 0000000000023000 0fd:00002 libpng12.so.0.10.0
00002b938d912000 4 rw--- 0000000000023000 0fd:00002 libpng12.so.0.10.0
00002b938d913000 132 r-x-- 0000000000000000 0fd:00002 libjpeg.so.62.0.0
00002b938d934000 2044 ----- 0000000000021000 0fd:00002 libjpeg.so.62.0.0
00002b938db33000 4 rw--- 0000000000020000 0fd:00002 libjpeg.so.62.0.0
00002b938db34000 8 r-x-- 0000000000000000 0fd:00002 libXau.so.6.0.0
00002b938db36000 2044 ----- 0000000000002000 0fd:00002 libXau.so.6.0.0
00002b938dd35000 4 rw--- 0000000000001000 0fd:00002 libXau.so.6.0.0
00002b938dd36000 20 r-x-- 0000000000000000 0fd:00002 libXdmcp.so.6.0.0
00002b938dd3b000 2044 ----- 0000000000005000 0fd:00002 libXdmcp.so.6.0.0
00002b938df3a000 4 rw--- 0000000000004000 0fd:00002 libXdmcp.so.6.0.0
00002b938df3b000 32 r-x-- 0000000000000000 0fd:00002 json.so
00002b938df43000 2044 ----- 0000000000008000 0fd:00002 json.so
00002b938e142000 4 rw--- 0000000000007000 0fd:00002 json.so
00002b938e143000 2052 r-x-- 0000000000000000 0fd:00002 mbstring.so
00002b938e344000 2044 ----- 0000000000201000 0fd:00002 mbstring.so
00002b938e543000 48 rw--- 0000000000200000 0fd:00002 mbstring.so
00002b938e54f000 44 r-x-- 0000000000000000 0fd:00002 mysql.so
00002b938e55a000 2048 ----- 000000000000b000 0fd:00002 mysql.so
00002b938e75a000 8 rw--- 000000000000b000 0fd:00002 mysql.so
00002b938e766000 2384 r-x-- 0000000000000000 0fd:00002 libmysqlclient.so.18.0.0
00002b938e9ba000 2044 ----- 0000000000254000 0fd:00002 libmysqlclient.so.18.0.0
00002b938ebb9000 516 rw--- 0000000000253000 0fd:00002 libmysqlclient.so.18.0.0
00002b938ec3a000 20 rw--- 00002b938ec3a000 000:00000 [ anon ]
...
0002b939116f000 80 r-x-- 0000000000000000 0fd:00002 zip.so
00002b9391183000 2044 ----- 0000000000014000 0fd:00002 zip.so
00002b9391382000 12 rw--- 0000000000013000 0fd:00002 zip.so
00002b9391385000 1024 rw--- 00002b9391385000 000:00000 [ anon ]
00002b9391485000 32768 rw-s- 0000000000000000 000:0007c [ anon ]
00002b9393485000 4 ----- 00002b9393485000 000:00000 [ anon ]
00002b9393486000 12288 rw--- 00002b9393486000 000:00000 [ anon ]
00002b9394086000 55136 r---- 0000000000000000 0fd:00002 locale-archive
00002b939765e000 2048 rw--- 00002b939765e000 000:00000 [ anon ]
00002b939785e000 28 r--s- 0000000000000000 0fd:00002 gconv-modules.cache
00002b9397868000 16 r-x-- 0000000000000000 0fd:00002 libnss_dns-2.5.so
...
00007fff63676000 84 rw--- 00007ffffffe9000 000:00000 [ stack ]
00007fff637fb000 12 r-x-- 00007fff637fb000 000:00000 [ anon ]
ffffffffff600000 8192 ----- 0000000000000000 000:00000 [ anon ]
mapped: 401636K writeable/private: 23188K shared: 32984K

Notice here at the very bottom of the pmap, is a summary breaking down memory use into mapped, private and shared memory.

If we key in on the writeable/private number, we come away with an understanding that this particular process is using about 23mb of memory. If we assume that most of the other apache processes will be in the same range, then our total memory use for 20 processes, is going to be about 500mb+. While not completely accurate, it's closer to the truth than if we just looked at what ps was telling us and added those numbers up.

The other thing that should be obvious in scanning through the pmap, is that there are a lot of different libraries being used, and also a lot of apache modules. This is a place where you can start looking at the list, and asking some questions about what those modules do, and whether or not they are appropriate for your site.

I'll suggest if you want to explore memory utilization further, that you locate a copy of this amazing python memory use script written by Pádraig Brady, who was an engineer for Redhat and now works for Facebook.

It reports the total memory use by a process -- in essence summarizing the use by all the forked children. Give it a try.

Armed with this information you now have a way of determining how to configure your apache server conf file, to make the most efficient use of available server memory, as well as gain insight into whether you have enough resources to serve the amount of traffic you expect and encounter.


Notice from the map how many modules there are in memory, and start going through your list of apache modules, investigating whether you even want or need many of the modules that are part of the default. The more you disable, the more memory you will save.


Defined tags for this entry: , , ,

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

James Cantando on :

*So, in reading this I come up with the question "Would it be a good idea then to set a high max child and a low MaxRequests to allow serving under load but locking memory up for as short a time as possible? Let's say values of 100 and 10, respectively.

David Rolston on :

*There is a significant cost to creating a new process, so trying to force process recycling isn't going to solve any problems. The best thing to do is to go through the list of apache modules and remove those that aren't required by your site. Typically there are numerous apache modules that you don't need.

Add Comment

Pavatar, Gravatar, Favatar, MyBlogLog, Pavatar author images supported.
BBCode format allowed
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
Form options