I have 2 LAMP web servers that are routinely running out of swap space (see attached top screenshot).
Apache's settings are as follows:
<IfModule prefork.c> StartServers 64 MinSpareServers 64 MaxSpareServers 128 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4096 </IfModule>
The resource limits on PHP are:
max_execution_time = 30 max_input_time = 30 memory_limit = 80M
I'm new to server admin stuff like this (I'm a developer); What can I adjust so that I can prevent swapping?
Here is a screenshot of top on one of the servers when crashing:
Best Answer
You're running out of swap because you're using all your RAM and then some. You have a serious problem that you need to rectify right now.
You have two choices: ignore cause and just add more RAM, or target the problem of what's actually munching on your memory.
Adding RAM is fairly cheap and fairly easy if it's your server but it's a temporary fix and if it's a VPS or a rented server, it's not so cheap. Let's have a go at fixing the root problem instead. What's sucking in that much memory? Here are a few tips:
.htaccess
files but you can hard-code in their functionality.In terms of just getting swap items back into real RAM, you can do that by:
But don't try then when you've got less free memory than you have things in swap. It'll crash your server.