Skip to content

Instantly share code, notes, and snippets.

@tbjers
Last active April 6, 2023 18:25
Show Gist options
  • Save tbjers/4496984 to your computer and use it in GitHub Desktop.
Save tbjers/4496984 to your computer and use it in GitHub Desktop.
Script to determine Apache ServerLimit and MaxClients.
#!/bin/sh
available=$(free --mega -tw | grep "Total:" | awk '{print $4}')
ps -ylC httpd --sort:rss | awk -v avail="$available" '{ s += $8; } END { print "Average Size:", s/(NR-1)/1024, "MB,", NR-1, "Processes, Total usage:", (s/(NR-1)/1024)*(NR-1), "MB, Max Servers:", avail/(s/(NR-1)/1024) }'
<IfModule prefork.c>
StartServers 10
MinSpareServers 10
MaxSpareServers 25
ServerLimit 128
MaxClients 128
MaxRequestsPerChild 0
</IfModule>
$ free -m
total used free shared buffers cached
Mem: 7454 1405 6049 0 142 401
-/+ buffers/cache: 860 6594
Swap: 1023 0 1023
$ ./check-apache-instances.sh
Average Size: 26.043 MB, 37 servers, Total usage: 963.59 MB, Max Servers: 249.588
@neetagit
Copy link

I have 65 gb ram so what should be the maxclient ? i have already set maxclient to 900 but at some point it exceeds that value.

@jtorral
Copy link

jtorral commented Apr 6, 2023

Thanks for the idea and script. I modified it a little to accept the actual free resources from the output of free -tw

#!/bin/sh
available=$(free --mega -tw | grep "Total:" | awk '{print $4}')
ps -ylC httpd --sort:rss | awk -v avail="$available" '{ s += $8; } END { print "Average Size:", s/(NR-1)/1024, "MB,", NR-1, "Processes, Total usage:", (s/(NR-1)/1024)*(NR-1), "MB, Max Servers:", avail/(s/(NR-1)/1024) }'

@tbjers
Copy link
Author

tbjers commented Apr 6, 2023

Thanks for the idea and script. I modified it a little to accept the actual free resources from the output of free -tw

#!/bin/sh
available=$(free --mega -tw | grep "Total:" | awk '{print $4}')
ps -ylC httpd --sort:rss | awk -v avail="$available" '{ s += $8; } END { print "Average Size:", s/(NR-1)/1024, "MB,", NR-1, "Processes, Total usage:", (s/(NR-1)/1024)*(NR-1), "MB, Max Servers:", avail/(s/(NR-1)/1024) }'

Thank you for this! I have updated the original script with your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment