0

My apache is starting up with high memory usage right away. After a reboot or a restart I'm seeing these kinds of number

 top - 15:37:59 up 22 min,  1 user,  load average: 0.12, 0.09, 0.12
 Tasks: 101 total,   1 running, 100 sleeping,   0 stopped,   0 zombie
 Cpu(s):  0.3%us,  0.3%sy,  0.0%ni, 88.0%id, 11.3%wa,  0.0%hi,  0.0%si,  0.0%st
 Mem:   3076864k total,  1098872k used,  1977992k free,    75348k buffers
 Swap:  2097148k total,        0k used,  2097148k free,   582912k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  1108 mysql     20   0  859m 185m 8136 S  0.0  6.2   0:08.91 mysqld
  1335 root      20   0  581m 109m  18m S  0.0  3.7   0:00.61 apache2
  2064 www-data  20   0  586m 107m  12m S  0.0  3.6   0:00.16 apache2
  2068 www-data  20   0  586m 107m  11m S  0.0  3.6   0:00.09 apache2
  2083 www-data  20   0  586m 106m  11m S  0.0  3.6   0:00.05 apache2
  2085 www-data  20   0  586m 106m  11m S  0.0  3.6   0:00.03 apache2
  2081 www-data  20   0  589m 101m 7368 S  0.0  3.4   0:00.48 apache2
  2086 www-data  20   0  582m  95m 4036 S  0.0  3.2   0:00.00 apache2

Here is the result of apache2 -V

  Server version: Apache/2.4.12 (Ubuntu)
  Server built:   Feb  4 2015 14:21:10
  Server's Module Magic Number: 20120211:41
  Server loaded:  APR 1.5.1, APR-UTIL 1.5.3
  Compiled using: APR 1.5.1, APR-UTIL 1.5.3
  Architecture:   64-bit
  Server MPM:     prefork
    threaded:     no
      forked:     yes (variable process count)
  Server compiled with....
   -D APR_HAS_SENDFILE
   -D APR_HAS_MMAP
   -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
   -D APR_USE_SYSVSEM_SERIALIZE
   -D APR_USE_PTHREAD_SERIALIZE
   -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
   -D APR_HAS_OTHER_CHILD
   -D AP_HAVE_RELIABLE_PIPED_LOGS
   -D DYNAMIC_MODULE_LIMIT=256
   -D HTTPD_ROOT="/etc/apache2"
   -D SUEXEC_BIN="/usr/lib/apache2/suexec"
   -D DEFAULT_PIDLOG="/var/run/apache2.pid"
   -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
   -D DEFAULT_ERRORLOG="logs/error_log"
   -D AP_TYPES_CONFIG_FILE="mime.types"
   -D SERVER_CONFIG_FILE="apache2.conf"

And finally here's my apache2/mods-enabled/mpm_prefork.conf:
FYI - This is my new config that is currently live. I setup the ServerLimit directive to try to stop it from spawning 100 servers and crashing the system.

 <IfModule mpm_prefork_module>
 StartServers 2
 MinSpareServers 5
 MaxSpareServers 5
 MaxClients  50
 ServerLimit 30
 MaxRequestsPerChild 200
 #       MaxSpareServers          5
 #       MaxRequestWorkers        150
 #       MaxConnectionsPerChild   0
 </IfModule>

I'm runnning another server using a similar config and my top is showing this:

 top - 15:48:32 up 10 days, 14 min,  2 users,  load average: 0.10, 0.06, 0.06
 Tasks: 172 total,   1 running, 171 sleeping,   0 stopped,   0 zombie
 %Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
 KiB Mem:   3078580 total,  2749928 used,   328652 free,   229412 buffers
 KiB Swap:  3141628 total,     1608 used,  3140020 free.  1868332 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  1286 mysql     20   0 1344940 265440   8340 S   0.0  8.6  56:22.39 mysqld
 21176 www-data  20   0  428168  64900  41772 S   0.0  2.1   0:01.24 apache2
 21020 www-data  20   0  429684  58164  36664 S   0.0  1.9   0:01.93 apache2
 21185 www-data  20   0  425460  52332  31952 S   0.0  1.7   0:00.91 apache2
 21199 www-data  20   0  425884  50604  30144 S   0.0  1.6   0:00.26 apache2
 21130 www-data  20   0  423124  48396  30372 S   0.0  1.6   0:00.52 apache2
 21186 www-data  20   0  422796  48296  30584 S   0.0  1.6   0:00.46 apache2
 21205 www-data  20   0  422992  47608  29740 S   0.0  1.5   0:00.18 apache2
 21204 www-data  20   0  422944  43576  25756 S   0.0  1.4   0:00.12 apache2
 21203 www-data  20   0  424220  28016   8896 S   0.0  0.9   0:00.23 apache2
  6095 root      20   0  414748  24100  14424 S   0.0  0.8   0:14.32 apache2

That's after running 10 days... My system was crashing after a couple days and the logs showed that there were like 75 apache processes spawned all with high memory usage. I'm not sure what is going on. I had installed mod_pagespeed around Feb 17th.. it ran fine until around Feb 25th. From Feb 25th on I have noticed all kinds of problems.

Running Ubuntu 12.04 LTS.

Any next steps to figure out this problem would be appreciated.

  • Are you running a web application server such as Passenger (Ruby), Wordpres or other CMS, or is it just 'plain' web hosting? – Bert Mar 2 '15 at 20:59
  • It's really not clear what you're asking about. What specifically in all that output concerns you? Are you asking about physical memory or virtual memory? And which indications do you think are "high" and why? – David Schwartz Mar 2 '15 at 22:20
0

"using a similar config"

I humbly suggest that this is a very different config. The first step in tuning is to remove all the stuff you don't need (in the case of Apache, the shared modules). The next thing to bear in mind is that RSS and VSZ are not good indicators of the memory footprint of any process on Linux, and certainly not a forked process. To find out how much memory your apache processes really use, track the output of 'free' and ps -ef | grep apache2 | wc

Once you've collected some data, you can do a linear regression to calculate what serverlimit should be.

Setting minspareserver to the same value as maxspareservers is not a good idea.

I had installed mod_pagespeed

mod_pagespeed is both memory and cpu hungry, and should never be used without a reverse proxy in front of it.

  • I manage multiple servers and I have them configured all the same. The lower mem one is a little behind in the versions. The lower memory one is running Apache 2.4.10 vs the other at 2.4.12. The lower mem one is running 3.13.0-36-generic #63-Ubuntu SMP vs 3.2.0-60-generic #91-Ubuntu SMP. They have the same apache modules configured. The puzzling part is that the newer version is the one taking up more initial memory. The PHP on the lower mem one: PHP 5.5.17-2+deb.sury.org~precise+1 vs PHP 5.5.22-1+deb.sury.org~precise+1 – Michael Fever Mar 4 '15 at 20:37
  • I solved the problem of the server crashing. Enabled mod_expires, and a PHP job that created PDFs for Oil Analysis reports. It was rerunning the same report over and over and generating numerous temp png's which were inserted into the mySQL database. So problem is solved for that but it does seem to start with more intial memory than I like... it might be ok though. The server runs SSL as well, not sure if that has anything to do with it. – Michael Fever Mar 4 '15 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.