I am currently running a web app that sees several (~15) users logging in once each day, and then leaving the web app open where it automatically refreshes with new content every 5 minutes. Each user tends to have it open for about 15-18 hours.

However at critical mass (~30-40) users everything starts to slow down dramatically and the HTTPD process start to balloon in memory usage. I have added a cron job that restarts apache once an hour, but that only helps somewhat. All the content is dynamically generated and new wach time, so caching pages isn't an option.

I have started to play around with the Timeout,MaxRequest and KeepAlive options, but any guidance would be greatly appreciated, as I have always left these on defaults in the past.

Here's what i have. Any apache geniuses have ideas on how to optimize this config for above scenario? I figured a long timeout is good because the load times can sometimes get VERY high.

# Timeout: The number of seconds before receives and sends time out.

Timeout 200

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.

KeepAlive On

# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.

MaxKeepAliveRequests 100

# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.

KeepAliveTimeout 60

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       16
MinSpareServers    10
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000

(I’ve simplified the numbers for clarifity, especially memory part is well too high)

Your MaxRequestsPerChild is currently 4000, given you are getting 50 users per day which everyone refreshes every 5 minutes for 18 hours, making it 600 requests per hour and 10800 requests per day. For reference, one user uses 218 connections per day.

This means that child processes are restarted 2.7 times at day. If your application uses 50M of memory per reload and manages to free 49M of it 1M per refresh, 50M for 50 users, and 4G for 4000 reloads. And the the child will be killed down.

You should inspect how much memory your application uses, and set those values according those.

If your server has 20G memory, that 1M leakage would work, somewhat, but changing MaxRequestsPerChild to, for example, 1000 would make memory consumption before restart of child four times smaller.

For a note, you may want to reduce MaxClients to something like 100 and ensure that there isn’t actually more users you think. This way accidental problems won’t cause the server go OOMing by too many requests. That KeepAliveTimeout could be something like 15 secs since users do refresh only every 5 minutes.


I think You need to play with MaxRequestsPerChild directive. Restarting apache every hour doesnt sound like an elegant solution to me. MaxRequestsPerChild each process will automagically restart once it serves the set number of requests. Try setting it to 100 ?

Also using a much lighter webserver (such as nginx) to spoonfeed slow clients and serve static media will take away a lot of load from apache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.