MaxClients in apache. How to know the size of my proccess?

First, determine the PID of one of your Apache processes.

Then you can do something like this:

cat /proc/PIDHERE/status | grep VmRSS

This will yield the (current) resident-set-size of that particular process, similar to:

VmRSS: 304456 kB

This value is as it sounds, it is the size of the process resident in RAM.

Then normalize your unit of measure (4GB * 1024 * 1024 = 4,194,304 KB). Divide:

4194304 KB / 304456 KB = 13.77 processes

Consider that you probably have other processes running on your system that will consume memory too, and ideally you want to minimize swapping, therefore you would not likely want 13 Apache MaxClients configured (using my numbers), you want some amount less (at your discretion).

This is a crude estimate; the size of your Apache processes may grow over time depending on load.


Predicting the maxClients from test scenarios is a starting point - but to solve the problem properly you need to start measuring how your application is behaving with real traffic.

Assuming your apache is running pre-fork....

Set up a cron job to count the number of httpd processes and the output of 'free'. Note that if your webserver is serving up any content from local files (and in a lot of cases, even when it's not) the amount of memory available for cache/buffers will have a big impact on performance. i.e. if you get to the point of swapping, your web performance is probably horrible!

Once you've got some data, plot it on a chart and do a least squares regression on it - extrapolate to find the number of clients at which you reach your target limit for httpd memory usage. A starting point for memory target would be the lesser of 80% of the physical memory / 80% of the size of the content.

(note if you've got MinSpareServers set to a very high value, results may not be accurate)

#!/bin/bash

LOGFILE='/var/log/httpd/memusage'
PIDS = `ps -ef | grep httpd | grep -v grep | wc -l`
MEM = `free | grep 'buffers/cache'`
DAY = `date '%Y-%m-%d %H:%M:%S'`
echo ${DAY} ${PIDS} ${MEM} >>LOGFILE

In an ideal world, you'd also measure the URL response time in the same log file - but that's getting a lot more complex.