Out of Memory (how to prevent?) server crash!

janton

Verified User
Joined
Sep 17, 2009
Messages
145
I run a a simple VPS with 1GB RAM and 2GM SWAP (XEN)

A few days ago my site was down, also i could't connect with the server (SSH). I needed to login to my external VPS panel to do a HARD reboot(plug and unplug), reboot also didn't work.. SO my server needed a total unplug an plug.

After looking in the logs i noticed my website AND server crashed because a bot visited my drupal site on none cashed webpages. This caused a lott of RAM, because it tried many connections in one time.

Except from the fact i need to install mod security.. how could i prevent the server from crashing? I got a top report from Directadmin "Warning: The system load average is 11.56" that shows +/-25 Apache threads. Is there a way i can limit this? Is this called Childeren in the http config? That way my server won't crash...
 
My guess is this is called "MaxClients" only i don't know where to change this?
I found httpd.conf that Include conf/extra/httpd-mpm.conf

in httpd-mpm.conf i see:
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 0
</IfModule>

But in httpd i tells me i can't change this because the files are written by directadmin:
# Do not change anything in included files, because they are rewritten by DirectAdmin #
 
ok the question where to change this still stays? (because directadmin tells me in the conf that i can't change it?)

but i found a nice tutorial explaining how to determine the right settings, please check if i do this correct?:

Total memory:
-bash-3.2# free -m
total used free shared buffers cached
Mem: 1024 986 37 0 17 246
-/+ buffers/cache: 723 300
Swap: 2047 0 2047

MYSQL MEMORY
-bash-3.2# ps aux | grep 'mysql' | awk '{print $6}'
1288
47324
600

APACHE PROCESS SIZE
-bash-3.2# ps aux | grep 'httpd' | awk '{print $6}'
56192
62044
53988
60224
62252
60384
6492
9680
6496
600
60672
62972

Total: 501996 = 490 MB / 12 = ±42MB


In this case the server has 1024Mb of memory allocated, xx used by the OS itself, 48Mb used by mySQL, and each Apache thread averages about 42Mb.

MaxClients = (1024 - 48) / 42 therefore MaxClients = 23

so something like this would be ok:

<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 3
MaxSpareServers 3
ServerLimit 23
MaxClients 23
MaxRequestsPerChild 1000
</IfModule>
 
Hello,

Nobody knows but you. Note you've just limited to 23 simultaneous downloads from your server. I don't know what sites you host there, but with these settings, only 23 concurrent processes are allowed. Would it be enough for your not nobody can say without getting into details of your server.

I'd recommend you in these case using Apache (back-end) + NGINX (fron-end) scheme of organizing the things.
 
or MaxRequestsPerChild 3000
Need to find out what the right settings for that..
 
Hello,

Nobody knows but you. Note you've just limited to 23 simultaneous downloads from your server. I don't know what sites you host there, but with these settings, only 23 concurrent processes are allowed. Would it be enough for your not nobody can say without getting into details of your server.

I'd recommend you in these case using Apache (back-end) + NGINX (fron-end) scheme of organizing the things.

I host 1 site, and it's not that bussy.. it's used for downloading 1 software and/or buying the software. But where can i add this settings.. as i written above the httpd.conf says "Do not change anything in included files, because they are rewritten by DirectAdmin"

should i just add these settings in httpd.conf in the bottom?
 
But where can i add this settings..

Check /etc/httpd/conf/extra/ and /etc/httpd/conf/extra/httpd-includes.conf
Search the forums in order to learn how to protect your settings against being overwritten (g httpd-includes.conf site:directadmin.com).
 
Back
Top