-1

I have a big problem with my apache2. I am on LAMP with debian 6, 64bit.

Here a screen after 24h of running, ordered by %MEM:

you can see VIRT for apache2 is 186mb.

That's not good at all. What Can I do?

Consider this apache servs only a couple of virtual host, and PHP pages doenst' require more than 3MB of memory.

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    ServerLimit      1250
    MaxClients            1250
    MaxRequestsPerChild   1500
</IfModule>

Thanks

Glorfindel
  • 1,213
  • 3
  • 15
  • 22
dynamic
  • 730
  • 6
  • 17
  • 31

4 Answers4

4

Is it that big of a problem?

The VIRT field that you are using is the total amount of memory the process could use. The next column is closer to the amount it is using. Even then some of this will be shared between processes. I would recommend reading up how Linux manages virtual memory if you are going to be doing Linux admin.

Looking at the other stats you still have a 1Gb of spare RAM so the box has not even tried to fill it's disk caches so it looks like there is plenty of RAM to spare.

Mahnsc is correct though, removing unused modules will help both memory and security.

Having said all that it does look a little large. Have they grown large? Does a restart reset to a smaller memory usage? If it is growing then that may be a problem but if it is mostly static then it may be okay.

Choffee
  • 175
  • 3
  • I asked this becease 2 days ago apaches2 process ate up all the momery + swap memory.. and i had to restart the server (after 20-25 days of up) – dynamic Mar 09 '11 at 14:44
  • Ah. Then that is not right! Sounds like a nasty memory leak. I assume you have all the latest updates installed. Might be a memory leak somewhere. Some useful info on php diagnostics: http://www.ibm.com/developerworks/opensource/library/os-php-v521/ You may also want to look into something like FastCGI for running php as it may give you more control and allow you to isolate the problems. – Choffee Mar 09 '11 at 15:14
  • this damn apache2 :@! anyway it's not related to php since on the previous server same php code didn't give any problem, and memory_limit is only at 16M – dynamic Mar 09 '11 at 15:32
  • The `ServerLimit` is to high. – Mircea Vutcovici Mar 09 '11 at 18:55
  • RAM usage is growing again :(. Now constantly at 50%. The more time passes the more RAM usage grows :( it's like apache2 processes size grows over time for a reason i can't get :( – dynamic Mar 12 '11 at 17:14
0

Unload any modules that you are not using or intending to use. If you're using php and don't need the mod_proxy or mod_jk support, unload them. That should help reduce the footprint of each child. You can unload most of the mod_auth_* and mod_authn_* modules as well if you aren't doing any kind of authentication by apache.

mahnsc
  • 1,776
  • 13
  • 11
0

If you want to measure the actual memory footprint of apache, then the way to do it is to compare the output of 'free' with the number of httpd processes.

As mahnsc says - you should strip out the stuff you don't need from the httpd (you could strip the symblols too - but its not that big a saving).

only a couple of virtual host, and PHP pages

Maybe - it depends on what the code is actually doing. You might consider switching to fastCGI (it doesn't help the memory usage - but it allows you to see whether the problem is with apache or PHP).

Regardless there's little evidence that its actually affecting performance.

symcbean
  • 19,931
  • 1
  • 29
  • 49
0

The server limit is too big. Should be, depending on your application, something like 10x number of CPU cores. Run a load test with JMetter for the traffic you are expecting during high load. and then set the ServerLimit accordingly. I would start with 2 * #CPU cores and increase linearly until the performance during the load test starts to degrade.

Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80
  • serverlimit infulences the loaded %mem of single apache process? – dynamic Mar 09 '11 at 17:09
  • Nope, only the loaded modules and the PHP scripts used by your application. Virtual memory (VIRT) is the memory requests by apache and resident set size (Res) is the memory actually allocated from physical memory. See `man ps` for details – Mircea Vutcovici Mar 09 '11 at 17:48
  • considering serverlimit doenst' influences memory usage as you said it's useless to lower it – dynamic Mar 09 '11 at 17:51
  • It will lower the overall memory usage. Not the usage of each process. So it is not useless. Just try a load test and see how your server is behaving. – Mircea Vutcovici Mar 09 '11 at 18:45
  • For load testing you can use `ab` or `JMeter`. See: http://httpd.apache.org/docs/2.0/programs/ab.html and http://jakarta.apache.org/jmeter/ – Mircea Vutcovici Mar 09 '11 at 18:51
  • Having a lot of processes will not increase the throughput because if all of them would run, the CPU will spend more time in context switching. The best way to find the proper value is to load test your environment. – Mircea Vutcovici Mar 09 '11 at 18:53
  • For your environment, the `ServerLimit` should be under 230. – Mircea Vutcovici Mar 09 '11 at 18:59
  • i had it to 2000 with anotehr server with 2GB – dynamic Mar 09 '11 at 19:58