Skip to main content

Running out of swap space on web servers, what to do? [Resolved]

I have 2 LAMP web servers that are routinely running out of swap space (see attached top screenshot).

Apache's settings are as follows:


StartServers       64
MinSpareServers    64
MaxSpareServers    128
ServerLimit        256
MaxClients         256
MaxRequestsPerChild  4096

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: screenshot


Question Credit: mmattax
Question Reference
Asked October 6, 2019
Posted Under: Network
18 views
3 Answers

For a quick change do:

"MaxRequestsPerChild 4096" to something like: 700 will help. The longer an apache process lives the more resident memory it's going to consume due to mod_php and the like. Also, enable keepalive and place aggresive timeout settings for it:

KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 5

This will allow each client page request to use one apache process to handle all it's requests where it would otherwise use multiple apache processes. This will cut down on the amount of apache processes running at any given time.

For optimal memory and requests per sec:

Move away from mod_php and use fastcgi, or another app server, instead. Apache processes consume a negligible amount of memory when php pages are served by fastcgi. Not to mention fastcgi can keep persisten connections to your dbase server amongst other things.


credit: CarpeNoctem
Answered October 6, 2019

how about shifting serving of static content to better suited server?


credit: Community
Answered October 6, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA