Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running VPS with debian + apache2 + php (as mod_apache) / 786Mb RAM

The problem is I'm constantly running out of memory.

When I run "top" command it shows around 10 of apache2 processes - and each of them takes >50Mb of memory! I thinks that's too much for each process, am I right? What can cause it?

I'm running few websites with around 1000 hits per day and several rarely visited WordPress blogs.

One of my most visited sites has a lot of med-size images - could it be a problem?

UPDATE (I'm adding process table):

   top - 16:19:52 up  1:55,  1 user,  load average: 0.05, 0.51, 0.80
Tasks:  35 total,   2 running,  33 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    786432k total,   786432k used,        0k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      15   0 10308  740  620 S  0.0  0.1   0:00.71 init
 9728 root      18   0 62184 1404  968 S  0.0  0.2   0:00.12 rsyslogd
 9741 root      16   0 48860 1204  704 S  0.0  0.2   0:00.16 sshd
 9763 root      15   0  193m  10m 5856 S  0.0  1.4   0:00.32 apache2
 9773 root      15   0 66948 3376 2448 S  0.0  0.4   0:00.43 sshd
 9776 bind      25   0  118m  12m 2624 S  0.0  1.6   0:00.01 named
 9787 root      15   0 12372  644  460 S  0.0  0.1   0:00.02 dovecot
 9813 root      18   0 71128 3004 2292 S  0.0  0.4   0:00.00 dovecot-auth
10060 Debian-e  15   0 42712  996  604 S  0.0  0.1   0:00.00 exim4
10065 nobody    15   0 21276 1432  696 S  0.0  0.2   0:00.02 memcached
10069 mongodb   18   0  116m  15m 4520 S  0.0  2.0   0:03.37 mongod
10076 dovecot   15   0 14216 2000 1604 S  0.0  0.3   0:00.01 imap-login
10117 root      19   0 17320 1448 1148 S  0.0  0.2   0:00.00 mysqld_safe
10157 mysql     15   0  200m  49m 6316 S  0.0  6.5   0:10.69 mysqld
10158 root      18   0  3776  596  504 S  0.0  0.1   0:00.00 logger
10165 root      15   0 42204 2044 1404 S  0.0  0.3   0:00.10 sftp-server
10235 proftpd   18   0 64224 1556  592 S  0.0  0.2   0:00.00 proftpd
11281 root      18   0 18544  928  712 S  0.0  0.1   0:00.01 cron
13549 root      15   0 66220 3172 2448 S  0.0  0.4   0:00.05 sshd
13551 root      15   0 42080 1888 1400 S  0.0  0.2   0:00.01 sftp-server
13560 www-data  15   0  227m  42m 5572 S  0.0  5.5   0:07.49 apache2
15702 root      15   0 66064 3132 2472 R  0.0  0.4   0:00.22 sshd
15849 root      15   0 17452 1700 1244 S  0.0  0.2   0:00.00 bash
20348 dovecot   15   0 14208 1988 1596 S  0.0  0.3   0:00.00 pop3-login
20468 root      15   0 18820 1196  940 R  0.0  0.2   0:01.56 top
21788 www-data  15   0  236m  51m 4164 S  0.0  6.8   0:06.18 apache2
21972 www-data  15   0  232m  48m 4044 S  0.0  6.3   0:07.14 apache2
21973 www-data  18   0  230m  46m 4672 S  0.0  6.1   0:01.82 apache2
26321 www-data  15   0  227m  43m 4060 S  0.0  5.6   0:00.76 apache2
26335 www-data  15   0  229m  46m 4776 S  0.0  6.0   0:00.44 apache2
26336 www-data  15   0  232m  49m 4844 S  0.0  6.4   0:01.37 apache2
26337 www-data  15   0  227m  43m 4148 S  0.0  5.6   0:00.64 apache2
26340 www-data  15   0  227m  43m 4104 S  0.0  5.6   0:00.46 apache2
26341 www-data  18   0  231m  48m 4596 S  0.0  6.3   0:00.44 apache2
27983 root      15   0  106m 8492 6192 S  0.0  1.1   0:00.10 ispmgr
share|improve this question

migrated from stackoverflow.com Nov 8 '11 at 4:17

This question came from our site for professional and enthusiast programmers.

2  
I'd be more concerned about memory leaks in your PHP code. –  Paul Tomblin Nov 7 '11 at 13:37
    
Voting for migration to webmasters.SE –  vzwick Nov 7 '11 at 13:39
    
I'm afraid it's wordpress killing my VPS even with few visitors per day –  oyatek Nov 7 '11 at 13:40
    
Exactly which column of the output do you worry about? VIRT,RES,SHR, ...? –  VolkerK Nov 7 '11 at 13:50
2  
I'm skeptical you'd resolve this through apache, the php code likely is running a whole bunch of nonsense or storing entire DB tables as hashes or who knows what-- but it's probably something in your PHP code. –  Incognito Nov 7 '11 at 14:02

4 Answers 4

I have added memory_get_peak_usage() to footer of each of my sites and I found that WordPress uses > 37Mb just to show main page of a site.

At the same time, my other site, written by myself without any framework or CMS (very complicated site but with much cleaner code than WordPress) uses just 0.9 Mb of memory.

WordPress is very hungry.

share|improve this answer

Firstly. 786mb is a very small server. I guess that is the hosting services smallest memory footprint, designed to get you going, but aimed to make you run out of memory when you try to do anyhing useful. I guess their marketing model just worked then :)

Secondly, are you SURE each process is using 50mb? Remeber that apache is a forked server, so a lot fo the child processes can look large, but in fact are sharing memory. You might want to brush up on the difference betweem virtual, reserved and shared memory:

http://mugurel.sumanariu.ro/linux/the-difference-among-virt-res-and-shr-in-top-output/

In short, its the "res" column in the output of 'top' that you want to watch, thats the amount of extra physical memory each extra apache proces is taking.

Images are not a problem, apache can serve those up all day without affecting its memory model.

share|improve this answer
    
Thanks for your reply. Yes I'm looking at RES column. Look at my first post - I've added process table. –  oyatek Nov 7 '11 at 14:00
    
No - RES can include COW'ed TXT segments - so it does not give an accurate picture of memory usage. –  symcbean Nov 7 '11 at 15:32
    
what you mean by "COW'ed"?.. –  oyatek Nov 7 '11 at 16:02

and each of them takes >50Mb of memory

no. If only it were that simple. I had a quick google to find some links about memory management on Linux but there's an awful lot of bad information on the internet. While this kind of description is kind of workable (if inaccurate) for a single instance of a process, the picture for a self-forking daemon is very different.

Trying to measure the actual memory usage is long and complicated. It's much simpler to look at the output of 'free' and compare that with the number of httpd processes running - although in your case, with such low traffic, you might want to reconfigure your server to reduce the number of idle httpd processes.

I've had a farm of 1Gb boxes comfortable handling 200+ clients each via Apache/PHP. While a lot will depend on the nature of your application, I certainly wouldn't expect to be running out of memory with 11.

OTOH I wasn't running mongo, exim, dovecot, bind, memcache, mysql and ftp servers on the same box.

share|improve this answer

This is a standard observation on any resource intensive PHP application being run with the Apache PHP5 DSO module interpreter.

An all time world renowned resource hog, Magento is really good at testing out and proving that you need either a Fast-CGI installation to quit converting Apache into a very inefficient PHP interpreter, or better yet move over to LiteSpeed and lsphp5 for speed and efficiency.

Wordpress and Joomla are both in that category that needs to be given enough memory and an efficient server platform that has been optimized beyond the OEM out-of-the-box installation you normally get on cheaper web hosting.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.