Reputation: 35
I have a server Intel(R) Xeon(R) CPU X3440 with 8GB RAM.
From what I see that the Apache using all the RAM and make the server unresponsive.
Here is my Apache Configuration:
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 1000
MaxClients 1000
MaxRequestsPerChild 4000
</IfModule>
And this is my free -m:
total used free shared buffers cached
Mem: 7859 7725 134 0 189 1566
-/+ buffers/cache: 5969 1889
Swap: 4095 61 4034
And this is my TOP :
top - 10:19:57 up 23 min, 1 user, load average: 8.08, 6.50, 3.90
Tasks: 1124 total, 1 running, 1123 sleeping, 0 stopped, 0 zombie
Cpu(s): 9.8%us, 3.2%sy, 0.1%ni, 60.0%id, 26.2%wa, 0.0%hi, 0.6%si, 0.0%st
Mem: 8048096k total, 7924168k used, 123928k free, 207920k buffers
Swap: 4194300k total, 79820k used, 4114480k free, 1460356k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1921 mysql 20 0 1653m 39m 3428 S 62.7 0.5 6:26.24 mysqld
7944 apache 20 0 399m 29m 4236 S 6.6 0.4 0:10.13 httpd
3201 apache 20 0 382m 11m 3880 S 2.3 0.1 0:00.50 httpd
8030 apache 20 0 382m 10m 3872 S 2.0 0.1 0:00.39 httpd
2837 apache 20 0 384m 13m 3916 S 1.3 0.2 0:00.37 httpd
3160 apache 20 0 383m 11m 3908 S 1.3 0.2 0:00.55 httpd
10555 apache 20 0 382m 11m 3884 S 1.3 0.1 0:00.48 httpd
13626 apache 20 0 381m 10m 3828 S 1.3 0.1 0:00.05 httpd
13668 apache 20 0 382m 11m 3760 S 1.3 0.1 0:00.16 httpd
14284 apache 20 0 381m 10m 3712 S 1.3 0.1 0:00.06 httpd
2848 apache 20 0 382m 11m 3876 S 1.0 0.2 0:00.49 httpd
5254 apache 20 0 382m 11m 3852 S 1.0 0.1 0:00.25 httpd
6085 apache 20 0 382m 10m 3768 S 1.0 0.1 0:00.26 httpd
6257 apache 20 0 382m 11m 3876 S 1.0 0.1 0:00.50 httpd
8067 apache 20 0 380m 9.8m 3732 S 1.0 0.1 0:00.18 httpd
14314 apache 20 0 382m 10m 3768 S 1.0 0.1 0:00.09 httpd
14328 apache 20 0 380m 9288 3800 S 1.0 0.1 0:00.16 httpd
So what is the recommends to solve this problem?
Upvotes: 2
Views: 4234
Reputation: 380
I just answered a similar question Check this link. Here's what I suggested:
I had a similar problem with an instance in EC2 and here's what I did and would suggest:
If you are using prefork, make sure that the module is loaded by typing these two commands
httpd -l
and sudo httpd -M
If you can see the prefork module loaded in the results of either of these two commands then up to the next step. Otherwise, make sure to load it first or else you would be changing the configurations for nothing.
Run this command to find the average memory each httpd process is using ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB";}'
Call that value x
Restart your apache server by using sudo service httpd restart
and take a note of how much free memory you have. What I did was subtract an extra 200MB-500MB
cushion from that free memory to be used later. Call that value y
Divide the value of free memory y
over the amount of memory used per process x
and that would be the value of MaxRequestWorkers = y/x
As for the value of MaxConnectionsPerChild
then you can tweak it till you get the right configuration. It you make it too big, then the process will keep using more and more memory before being killed. If you make it too small, then the processes will die too quickly and that will present an overhead on your system. I usually keep it somewhere between 4000
and 10000
.
Some of these steps have been taken from the accepted answer in the following link: StackExchange: httpd memory usage where one solution also suggested disabling some of the modules if you don't need them.
Make sure to check the access logs. May be someone is trying to attack your website!
I would suggest you do steps 1-5 first and see if that solves your problem!
Good luck!
Upvotes: 3