Apache Eating my Memory!

Hello. I am running:

Linode 64

Apache/1.3.26 (Unix) Debian GNU/Linux

mysql Ver 11.16 Distrib 3.23.49, for pc-linux-gnu (i686)

PHP Version 4.1.2

I just installed Mambo and it seems any time I try to access my new home page, the system takes a long time to post back in my browser. I looked at my memory usage and it seems that 19MB is a lot of memory for Apache to take up.

Is this abnormal?

What can I do to start tuning the system so this stops?

TOP

22:35:51 up  8:42,  1 user,  load average: 0.00, 0.01, 0.00
61 processes: 60 sleeping, 1 running, 0 zombie, 0 stopped
CPU states:   0.0% user,   1.6% system,   0.0% nice,  98.4% idle
Mem:     59568K total,    57720K used,     1848K free,     2628K buffers
Swap:   263160K total,   131580K used,   131580K free,     6904K cached

  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
 1074 www-data   9   0 25344  19M 19244 S     0.0 32.9   0:26 /usr/sbin/apache
 1478 www-data   9   0  8556 8204  2660 S     0.0 13.7   0:01 /usr/sbin/apache
 1550 www-data   9   0  6724 6380  2496 S     0.0 10.7   0:01 /usr/sbin/apache
 1476 www-data   9   0  6648 6312  2776 S     0.0 10.5   0:00 /usr/sbin/apache
  480 root       9   0 19128 5640  5376 S     0.0  9.4   0:01 spamd child
 1551 www-data   9   0  5928 5580  2432 S     0.0  9.3   0:00 /usr/sbin/apache
  478 root       9   0 19020 4172  4124 S     0.0  7.0   0:01 spamd child
 1072 www-data   9   0  6984 2224  2224 S     0.0  3.7   0:19 /usr/sbin/apache
 1076 www-data   9   0  7508 2212  2208 S     0.0  3.7   0:20 /usr/sbin/apache
  468 mysql      9   0  4712 2160  1908 S     0.0  3.6   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql
  473 mysql      8   0  4712 2160  1908 S     0.0  3.6   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql
  474 mysql      9   0  4712 2160  1908 S     0.0  3.6   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql
  475 mysql      9   0  4712 2160  1908 S     0.0  3.6   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql
 1075 www-data   9   0 24828 2072  2052 S     0.0  3.4   0:30 /usr/sbin/apache
 1477 www-data   9   0  2480 1932  1872 S     0.0  3.2   0:00 /usr/sbin/apache
 1552 www-data   9   0  2424 1840  1664 S     0.0  3.0   0:00 /usr/sbin/apache
 1554 root       9   0  1632 1600  1304 S     0.0  2.6   0:00 /usr/sbin/sshd
  489 root       9   0  2904 1372  1372 S     0.0  2.3   0:00 /usr/bin/perl -wT /usr/sbin/pop-before-smtp --daemon=/var/run/pop-bef
 1556 root       9   0  1252 1252  1020 S     0.0  2.1   0:00 -bash
  618 root       9   0  3768 1096   920 S     0.0  1.8   0:00 /usr/bin/perl /usr/local/webmin-1.160/miniserv.pl /etc/webmin/miniser
 1578 root      14   0   948  948   748 R     1.6  1.5   0:00 top
 1475 postfix    9   0   784  692   680 S     0.0  1.1   0:00 pickup -l -t fifo -u -c
  589 postfix    9   0   760  616   616 S     0.0  1.0   0:00 qmgr -l -t fifo -u -c
  368 root       9   0   760  612   592 S     0.0  1.0   0:00 /usr/sbin/sshd
  401 root       9   0   624  572   568 S     0.0  0.9   0:00 /usr/lib/courier/authlib/authdaemond.plain start
  405 root       9   0   624  560   528 S     0.0  0.9   0:00 /usr/lib/courier/authlib/authdaemond.plain start
  400 root       9   0   624  556   556 S     0.0  0.9   0:00 /usr/lib/courier/authlib/authdaemond.plain start
  605 root       9   0  1564  540   524 S     0.0  0.9   0:00 /usr/sbin/apache
  476 root       9   0 18116  516   516 S     0.0  0.8   0:01 spamd child
  477 root       9   0 18332  516   516 S     0.0  0.8   0:01 spamd child
  479 root       9   0 18292  516   516 S     0.0  0.8   0:01 spamd child
  383 root       9   0   532  500   492 S     0.0  0.8   0:00 /sbin/syslogd
  403 root       9   0   592  492   492 S     0.0  0.8   0:00 /usr/lib/courier/authlib/authdaemond.plain start
  394 root       9   0 17636  488   488 S     0.0  0.8   0:01 /usr/local/bin/spamd -c -d --pidfile=/var/run/spamd.pid
  402 root       9   0   584  484   484 S     0.0  0.8   0:00 /usr/lib/courier/authlib/authdaemond.plain start
  433 root       9   0   656  472   472 S     0.0  0.7   0:00 /bin/sh /usr/bin/safe_mysqld
  419 root      10   0   480  428   412 S     0.0  0.7   0:00 /usr/sbin/couriertcpd -pid=/var/run/courier/pop3d.pid -stderrlogger=/
  422 root       9   0   440  420   420 S     0.0  0.7   0:00 /usr/sbin/courierlogger courierpop3login
    1 root       9   0   456  416   404 S     0.0  0.6   0:00 init [2]  
  412 root       8   0   468  416   408 S     0.0  0.6   0:00 /usr/sbin/couriertcpd -address=0.0.0.0 -stderrlogger=/usr/sbin/courie
  414 root       9   0   440  416   416 S     0.0  0.6   0:00 /usr/sbin/courierlogger imaplogin
  426 root       9   0   452  392   392 S     0.0  0.6   0:00 /usr/sbin/inetd

/proc/iostatus > iocount=824433 iorate=3 iotokens=400000 tokenrefill=512 tokenmax=400000

/proc/meminfo

        total:    used:    free:  shared: buffers:  cached:
Mem:  60997632 57008128  3989504        0  3010560 33435648
Swap: 269475840 134135808 135340032
MemTotal:        59568 kB
MemFree:          3896 kB
MemShared:           0 kB
Buffers:          2940 kB
Cached:           7368 kB
SwapCached:      25284 kB
Active:          26452 kB
Inactive:        23564 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:        59568 kB
LowFree:          3896 kB
SwapTotal:      263160 kB
SwapFree:       132168 

9 Replies

From the looks of the output, it looks like it may have more to do with the number of modules apache has loaded than the amount of servers running. You may want to see what modules you don't need and comment them out in the configuration.

As a side note, you're running some pretty old versions of both PHP and Apache. You may want to look into upgrading those.

Putting those aside, I would be more worried about spamd than apache, it's using up 2-3 times more than apache. A lot of people have noticed that you need to restart spamd every so often to keep the memory usage down.

Try switching to a 32-bit distro and reduce Apache MaxClients to 35 for noticeable performance increase. Raise MaxClients as needed, based upon demand.

I know that this thread is old. I am a newbie and Apache + MySQL are eating up my mem like crazy. I have to restart apache every hour. I have followed most of the tutorial here but no luck. I only have 2 sites and both sites are not online.

Ubuntu 10.04.1 LTS

free -m

total used free shared buffers cached

Mem: 493 313 179 0 11 69

-/+ buffers/cache: 232 260

Swap: 255 22 233

1 [ 0.0%] Tasks: 35 total, 1 running

2 [ 0.0%] Load average: 0.07 0.02 0.00

3 [|| 0.7%] Uptime: 2 days, 07:59:26

4 [ 0.0%]

Mem[||||||||||||||||||||||||||||||||||||||| 232/493MB]

Swp[|||||| 22/255MB]

PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command

1 root 20 0 23636 828 468 S 0.0 0.2 0:00.66 /sbin/init

8667 root 20 0 172M 9176 4320 S 0.0 1.8 0:00.04 `- /usr/sbin/apache2 -k start

8673 www-data 20 0 172M 5280 420 S 0.0 1.0 0:00.00 | `- /usr/sbin/apache2 -k start

8672 www-data 20 0 228M 65564 3320 S 0.0 13.0 0:00.70 | `- /usr/sbin/apache2 -k start

8671 www-data 20 0 228M 65564 3320 S 0.0 13.0 0:00.73 | `- /usr/sbin/apache2 -k start

8670 www-data 20 0 228M 65564 3320 S 0.0 13.0 0:00.75 | `- /usr/sbin/apache2 -k start

2329 ntp 20 0 25848 648 520 S 0.0 0.1 0:11.12 `- /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 102:104

2188 root 20 0 49308 408 300 S 0.0 0.1 0:00.72 `- /usr/sbin/sshd

8456 root 20 0 70660 3200 2472 S 0.0 0.6 0:00.04 | `- sshd: abc [priv]

8468 abc 20 0 70660 1788 1032 S 0.0 0.4 0:00.14 | `- sshd: abc@pts/0

8469 abc 20 0 18068 1984 1352 S 0.0 0.4 0:00.03 | `- -bash

8680 abc 20 0 19668 1504 1096 R 0.0 0.3 0:00.09 | `- htop

2165 root 20 0 6604 552 428 S 0.0 0.1 0:00.00 `- dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dh

2126 root 20 0 6128 180 176 S 0.0 0.0 0:00.00 `- /sbin/getty -8 38400 hvc0

2066 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:00.40 `- /usr/sbin/mysqld

2899 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:07.00 | `- /usr/sbin/mysqld

2898 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:06.65 | `- /usr/sbin/mysqld

2721 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:08.92 | `- /usr/sbin/mysqld

2720 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:08.46 | `- /usr/sbin/mysqld

2128 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:14.34 | `- /usr/sbin/mysqld

2113 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:00.23 | `- /usr/sbin/mysqld

2112 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:00.00 | `- /usr/sbin/mysqld

2111 mysql 20 0 212M 22724 2076 S 0.0 4.5 0:26.01 | `- /usr/sbin/mysqld

Any ideas?

Thank you,

Mark

@mgoltra:

Mem[||||||||||||||||||||||||||||||||||||||| 232/493MB]

You're using less than half of your memory. What's the problem? (Don't trust the VIRT column, it's very misleading.)

The very first suggestion I'd give is to get rid of Apache and replace with Nginx. That alone will save you TONS of memory.

@Vito Botta:

The very first suggestion I'd give is to get rid of Apache and replace with Nginx. That alone will save you TONS of memory.
Not necessarily, depending on the fraction of requests that need to use the PHP interpreter, which is likely a large part of the apache working set too.

– David

@Vito Botta:

The very first suggestion I'd give is to get rid of Apache and replace with Nginx. That alone will save you TONS of memory.
I find it annoying when I see people give advice like this.

Switching to some other software is a huge job, which will take a lot of time and cause a lot of downtime and isn't actually addressing the cause of the problem, which in most cases is a simple fix. By starting from scratch with other software, you might fix your problem but introduce a dozen other small problems which all need to be fixed (and which may all need just as much troubleshooting time). You are at least moving to a new and unfamiliar platform and needing to learn new technologies. It should be the very last resort, if anything.

@mgoltra:

I know that this thread is old. I am a newbie and Apache + MySQL are eating up my mem like crazy. I have to restart apache every hour.

mgoltra, the stats you gave show plenty of spare memory. So I'm going to assume you just ran those commands at a time when the problem was not occurring and everything was running nicely - which unfortunately doesn't help us all that much.

If the problem is indeed due to Apache starting up too many memory-hungry processes at some stage, then you need to adjust MaxClients. There's plenty of resources around to help. In this case, a number as low as 5 might even be good since you don't have much RAM and each process is taking up a lot of memory.

@AceStar:

@Vito Botta:

The very first suggestion I'd give is to get rid of Apache and replace with Nginx. That alone will save you TONS of memory.
I find it annoying when I see people give advice like this.

Annoying? Really? It's just an advice like any other, and since the topic is about "Apache eating memory", it's IMHO a valid advice and I am surprised somebody could find it annoying in any way…

> Switching to some other software is a huge job, which will take a lot of time and cause a lot of downtime and isn't actually addressing the cause of the problem, which in most cases is a simple fix.

Setting up Nginx only takes minutes, the configuration can easily be prepared while Apache is still running and when everything is ready you'd just switch one off and the other on…. and start seeing lighter use of the resources right away. Unless we are talking about many servers and very complex configurations etc etc, I don't see how a switch like this could require a lot of downtime.

I do agree though on the fact that if there is a problem at application level or anyway not caused by something related to Apache, just switching to another web server won't help figure out the cause of the problem.

However it can at least by time to investigate the issue, as the box would likely be able to handle the same load more easily :)

> By starting from scratch with other software, you might fix your problem but introduce a dozen other small problems which all need to be fixed (and which may all need just as much troubleshooting time). You are at least moving to a new and unfamiliar platform and needing to learn new technologies. It should be the very last resort, if anything.

Again, it was just a suggestion on something that could help, together with other changes, to solve the problem / improve the situation. I really can't see what's wrong with suggesting to switch to another web server if there could be some advantages.

If someone were to post "I'm trying to open my front door with my lawnmower", and you replied "Ditch the lawnmower and try your door key," you would be right.

What's happening, however, is that people are saying "I'm trying to make my breakfast by putting apples in my oatmeal." And you're responding with "Epic fail! Apples suck, you need to use strawberries."

The difference is that in the first scenario, the tool being used is clearly the incorrect tool for the job. However, in the second scenario, the tool being used is completely valid, but is different from your preferred tool.

In context, if I start a thread titled "Maximizing my apache performance", I don't want advice like "Switch to lighttpd". I, for whatever reason, have defined my sandbox as "A server running apache," and am looking for advice within that sandbox. Apache is just as valid a web server as any other. If you don't believe me, check out http://www.linode.com/forums/viewtopic.php?t=6150

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct