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
@usamamashkoor
Copy link

Hi i could not find the MaxClients 128 in the httpd.conf file in Appache xammp.
also this line to

can you please tell me what i am doing wrong..

@jmanc
Copy link

jmanc commented Mar 16, 2017

Hi, great script. However, you'll need to account for the Header Line in the ps output. I modified your script by adding (NR-1) in the relevant locations. Thank you!

ps -ylC httpd --sort:rss | awk '{ 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:", 6500/(s/(NR-1)/1024) }'

@neetagit
Copy link

how to get maxclient limit

@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