apache calculate MaxClients count

To get a rough idea of how to set the MaxClients directive, it is best to find out how much memory the largest apache thread is using. Then stop apache, check the free memory and divide that amount by the size of the apache thread found earlier. It usually work only for mod_php mode:

#!/bin/bash
echo “This is intended as a guideline only!”
if [ -e /etc/debian_version ]; then
APACHE=”apache2″
elif [ -e /etc/redhat-release ]; then
APACHE=”httpd”
fi
RSS=$(ps -aylC $APACHE |grep “$APACHE” |awk ‘{print $8’} |sort -n |tail -n 1)
RSS=$(expr $RSS / 1024)
echo “Stopping $APACHE to calculate free memory”
/etc/init.d/$APACHE stop &> /dev/null
MEM=$(free -m |head -n 2 |tail -n 1 |awk ‘{free=($4); print free}’)
echo “Starting $APACHE again”
/etc/init.d/$APACHE start &> /dev/null
echo “MaxClients should be around” $(expr $MEM / $RSS)

Leave a Reply

Your email address will not be published. Required fields are marked *