Last active
October 9, 2018 19:02
-
-
Save matteomattei/d2335a3ee5d13d0d1acb285806624ea9 to your computer and use it in GitHub Desktop.
This script calculates the MaxClients directive in Apache MPM_prefork module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TOTAL_MEMORY=$(grep "^MemTotal:" /proc/meminfo | awk '{print $2}') | |
MYSQL_MEMORY=$(ps aux | grep mysql | grep -v "grep" | grep "^mysql" | awk '{print $6}' | sort | head -n 1) | |
APACHE_MEMORY_PROCESSES=$(ps aux | grep 'apache' | grep -v "grep" | awk '{print $6}' | sort) | |
APACHE_INSTANCES=0 | |
APACHE_TOTAL_MEMORY=0 | |
for i in ${APACHE_MEMORY_PROCESSES} | |
do | |
APACHE_TOTAL_MEMORY=$(( ${APACHE_TOTAL_MEMORY} + ${i} )) | |
APACHE_INSTANCES=$(( ${APACHE_INSTANCES} + 1 )) | |
done | |
APACHE_MEMORY=$(( ${APACHE_TOTAL_MEMORY} / ${APACHE_INSTANCES} )) | |
TOTAL_MEMORY_MB=$(( ${TOTAL_MEMORY} / 1024 )) | |
MYSQL_MEMORY_MB=$(( ${MYSQL_MEMORY} / 1024 )) | |
APACHE_MEMORY_MB=$(( ${APACHE_MEMORY} / 1024 )) | |
LEFT_MEMORY=$(( ${TOTAL_MEMORY_MB} - ${MYSQL_MEMORY_MB} - 50 )) | |
MAX_CLIENT=$(( ${LEFT_MEMORY} / ${APACHE_MEMORY_MB} )) | |
echo "MaxClients=${MAX_CLIENT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, fixed! ;-)