Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've looked around and couldn't find an answer for this, tried quite a few of other people's solutions over the months, but nothing fixes this.

I run 12.04 on a good VPS, but I've been having some load/memory issues with Apache2.2 over the last month or two, but it's always been a bit of a problem so I upgraded to 2Gb VPS with 2Gb Swap. But some parts of the day the server goes slow, monit sends me alerts that it's > 97% memory, and I look and it's always loads of Apache processes, although MySQL is a big second.

I assumed it was load, but using netstat e.g. netstat -nt | awk '/TIME_WAIT/ {split($5,a,":"); print a[1]}' | sort | uniq -c | sort -n | tail which apparently shows the connections over 5 minutes, a large part of them are my own IP - currently 32, but it goes upto >100 sometimes. Also I've done a complete reinstall recently, caused by a failed restore after it got suspended for a load issue. Again, Apache went up and up - but on a few occasions it's gone <20 loadavg o.O Thankfully not doing that atm but it's hovering around 1-2-3 for all which is more than usual.

So is there a way to find out what local programs are hammering/spawning Apache processes? Any ideas of what could be hammering this? I tried stopping services and watching top and htop - with no MySQL and Apache Mem usage is around 40Mb, MySQL is goes up to 180Mb, and then Apache 2Gb (!!!). Also tried stopping ones that might be causing issues, like Dropbox, Spam Assassin, (I've stopped using ClamAV because that was hammering the load), etc. but doesn't seem to make a difference in the Netstat or Memory?

And yes the web server is sluggish during this - not surprised, as there's no overhead to serve pages! Static is fast though (I run mostly blogs on Wordpress, PHP 5.3.10-1ubuntu3.11 with Suhosin-Patch, Zend engine installed - I did have XCache but took it off, it caused problems with W3TotalCache - which I don't use on much of my sites now, as I was suspecting it for the load issue.).

I've tweaked apache.conf til the cows come home too, currently it's on:

Timeout 15
KeepAlive On

<IfModule mpm_prefork_module>
StartServers       1
MinSpareServers    1
MaxSpareServers    10
MaxClients        50
ServerLimit       50
MaxRequestsPerChild  4000
ListenBacklog        100

<IfModule mpm_worker_module>
StartServers       8
MinSpareThreads    5
MaxSpareThreads    4
    ThreadLimit         64
    ThreadsPerChild     25
MaxClients       50
    MaxRequestsPerChild  0
</IfModule>


<IfModule mpm_event_module>
StartServers       2
MinSpareThreads    25
MaxSpareThreads    75
    ThreadLimit          64
    ThreadsPerChild      25
MaxClients        150
    MaxRequestsPerChild   500
</IfModule>

(I've experimented with low and high values for the PreFork and Worker MPM over the last year or so, it seems totally arbitrary - it was on StartServers 2 MinSpareServers 5 before, the rest pretty much the same, and doesn't fix it even after a restart. I guess I could go higher than these - and did before, MaxClients was 500 I think - but the load scare meant I went down to smaller values.

Here's the output of free -m:

             total       used       free     shared    buffers     cached
Mem:          2048       2046          1          0          0         10
-/+ buffers/cache:       2036         11
Swap:         2048       1546        501

Vmstat 2 10:

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0 1594992   1872      0  13536 3363 3619    46    23    0 1718  7  2 90  0
 0  0 1594992   1472      0  14536  248  248     2     6    0  357  4  0 96  0
 0  0 1594980   1496      0  14504 1024 1018     0   708    0  713  0  0 99  1
 0  0 1596116   2700      0  14208  164  732     0     0    0  206  2  0 98  0
 0  0 1599956   1648      0  13588  194 2144     2   100    0  617 18  1 80  0
 0  0 1602388   1500      0  15352 1128 2392    34    10    0 1487 20  2 78  0
 0  0 1602384   1516      0  15328  190  188     0   274    0  209  0  0 100  0
 1  0 1595856   2320      0   8052 18266 15038   114     2    0 9611 13  3 81  0
 0  0 1593316   4208      0   3608 10534 9268     0     4    0 5558  4  1 94  0
 0  0 1593296   3132      0   4684   10    0     0    66    0   94  0  0 100  0

I do have a screengrab of my Top but can't post it here cos I don't have enough reputation sigh.

Any ideas?

EDIT: I thought I might have too low a MaxClients / ServerLimit so increased that and it made a great difference - until MySQL kept falling over about a minute later. :-( Currently have that on 150 (I read somewhere that it's your memory / average apache process = Maxclients, so 2GB / 3.5 = 571 - but 500 got very unstable...

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.