High apache load but zero traffic

Adie asked:

I have a problem with new server.. I use VPS Centos with 1GB of ram and I use wordpress CMS.

The traffic <100 visitor/hour, but the apache have high load and make the server hang with zero free of ram and can’t connect through ssh. I should reboot the vps to make it works

here is the load on Apache looks like

Tasks:  66 total,   1 running,  65 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.6%us, 12.3%sy,  0.0%ni, 48.1%id, 23.0%wa,  4.8%hi, 10.2%si,  0.0%
Mem:   1018776k total,   116620k used,   902156k free,     1236k buffers
Swap:  1048568k total,    1013052k used,  35516k free,    26628k cached
2949 apache    20   0  459m  42m 3732 D  3.0  4.2   0:09.23 httpd           
2959 apache    20   0  460m  29m 3744 D  2.0  3.0   0:02.72 httpd           
2968 apache    20   0  460m  26m 3808 D  2.0  2.6   0:02.27 httpd            
2972 apache    20   0  460m  24m 3784 D  2.0  2.5   0:02.44 httpd           
2986 apache    20   0  460m  29m 3784 R  2.0  2.9   0:02.40 httpd            
2969 apache    20   0  458m  29m 3864 D  1.6  3.0   0:02.63 httpd           
2974 apache    20   0  460m  25m 3820 D  1.6  2.6   0:02.43 httpd            
2990 apache    20   0  460m  23m 3920 D  1.6  2.4   0:02.36 httpd           
2994 apache    20   0  460m  31m 3756 D  1.6  3.2   0:02.62 httpd            
2956 apache    20   0  460m  26m 3740 D  1.3  2.7   0:02.73 httpd           
2957 apache    20   0  465m  22m 3644 D  1.3  2.3   0:02.80 httpd            
2967 apache    20   0  458m  24m 3764 D  1.3  2.5   0:02.60 httpd           
2970 apache    20   0  463m  25m 3764 D  1.3  2.6   0:03.07 httpd            
2971 apache    20   0  451m  22m 3792 D  1.3  2.3   0:02.47 httpd           
2973 apache    20   0  458m  25m 3768 D  1.3  2.6   0:02.52 httpd            
2987 apache    20   0  465m  20m 3772 D  1.3  2.1   0:03.02 httpd  

But sometimes the server have uptime more than 5-10hrs but after that the problems start

My answer:


Congratulations, you’ve managed to use nearly all of your swap space.

The first obvious problem here is that you went very deep into swap. This is probably what’s causing the system to thrash so hard (lots of time spent in system, I/O wait and software interrupts). It looks like you killed some processes before this top output, though, so some memory was freed up.

First thing to do is to reduce the number of Apache processes that are running. You don’t need that many for a small site, and it’s just going to throw you deep into swap and kill your performance…which is what already happened. I would recommend you start very small and increase when it becomes necessary. An example:

StartServers            4
MinSpareServers         4
MaxSpareServers        10
MaxClients             25

This limits you to only serving 25 simultaneous requests (everyone else has to wait in line). But you are very unlikely to hit that unless your blog suddenly winds up on the front page of reddit or something. And if you expect that to happen on a regular basis, you need a bigger server and a professional sysadmin on call.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.