-
-
Save centminmod/93c893957cbcbe00160b to your computer and use it in GitHub Desktop.
phpbench.sh for Centmin Mod PHP-FPM usage https://community.centminmod.com/threads/php-5-7-phpng-support-testing-for-centmin-mod-betas.892/page-2#post-4033
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 | |
###################################################### | |
# written by George Liu (eva2000) vbtechsupport.com | |
###################################################### | |
# variables | |
############# | |
DT=`date +"%d%m%y-%H%M%S"` | |
SHOWPHPSTATS='n' | |
# Print output in a forum friendly [CODE] tag format | |
BBCODE='y' | |
# how many runs to do for bench.php & micro_bench.php | |
# the results will be averaged over that many runs | |
RUNS='2' | |
# change PHPVER to versions download at /svr-setup/php-PHPVER | |
# directory. The PHP version directory must already exist | |
# centmin.sh menu option 5 run with specified PHP Version | |
# will download the correct PHPVER for you | |
PHPVER='5.7.0' | |
###################################################### | |
# DO NOT EDIT BELOW THIS LINE | |
###################################################### | |
DIR_TMP='/svr-setup' | |
PHPBENCHLOGDIR='/home/phpbench_logs' | |
PHPBENCHLOGFILE="bench_${DT}.log" | |
PHPMICROBENCHLOGFILE="bench_micro_${DT}.log" | |
PHPBENCHLOG="${PHPBENCHLOGDIR}/${PHPBENCHLOGFILE}" | |
PHPMICROBENCHLOG="${PHPBENCHLOGDIR}/${PHPMICROBENCHLOGFILE}" | |
CLIENTIP=$(echo "${SSH_CLIENT%% *}") | |
SERVERIP=$(ip addr show | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -v 127.0.0.1) | |
HOSTNAME=$(hostname) | |
PROCESSNAME='php-fpm' | |
###################################################### | |
if [ ! -d "$PHPBENCHLOGDIR" ]; then | |
mkdir -p $PHPBENCHLOGDIR | |
fi | |
###################################################### | |
# functions | |
############# | |
bbcodestart() { | |
if [[ "$BBCODE" = [yY] ]]; then | |
echo "[CODE]" | |
fi | |
} | |
bbcodeend() { | |
if [[ "$BBCODE" = [yY] ]]; then | |
echo "[/CODE]" | |
fi | |
} | |
cleanmem() { | |
if [ ! -f /proc/user_beancounters ]; then | |
sync && echo 3 > /proc/sys/vm/drop_caches > /dev/null | |
fi | |
} | |
phpmem() { | |
if [[ "$SHOWPHPSTATS" = [yY] ]]; then | |
bbcodestart | |
p=${PROCESSNAME} | |
ps -C $p -O rss | gawk '{ count ++; sum += $2 }; END {count --; print "[php stats]: Number of processes =",count; print "[php stats]: Memory usage per process =",sum/1024/count, "MB"; print "[php stats]: TOTAL memory usage =", sum/1024, "MB" ;};' | |
bbcodeend | |
fi | |
} | |
restartphp() { | |
service php-fpm restart 2>&1 >/dev/null | |
cleanmem | |
sleep 4 | |
} | |
phpi() { | |
{ | |
bbcodestart | |
echo "----------------------------------------------" | |
CPUNAME=$(cat /proc/cpuinfo | grep "model name" | cut -d ":" -f2 | tr -s " " | head -n 1) | |
CPUCOUNT=$(cat /proc/cpuinfo | grep "model name" | cut -d ":" -f2 | wc -l) | |
echo "CPU: $CPUCOUNT x$CPUNAME" | |
cat /etc/redhat-release && uname -m | |
echo "Centmin Mod $(cat /etc/centminmod-release)" | |
free -m | |
bbcodeend | |
bbcodestart | |
echo "----------------------------------------------" | |
php -v | |
bbcodeend | |
bbcodestart | |
echo "----------------------------------------------" | |
php --ini | |
bbcodeend | |
bbcodestart | |
echo "----------------------------------------------" | |
php -m | |
bbcodeend | |
bbcodestart | |
echo "----------------------------------------------" | |
php -i | |
bbcodeend | |
} 2>&1 > ${PHPBENCHLOGDIR}/bench_phpinfo_${DT}.log | |
sed -i "s/$CLIENTIP/ipaddress/g" ${PHPBENCHLOGDIR}/bench_phpinfo_${DT}.log | |
sed -i "s/$SERVERIP/serverip/g" ${PHPBENCHLOGDIR}/bench_phpinfo_${DT}.log | |
sed -i "s/$HOSTNAME/hostname/g" ${PHPBENCHLOGDIR}/bench_phpinfo_${DT}.log | |
} | |
changedir() { | |
cd ${DIR_TMP}/php-${PHPVER} | |
} | |
fbench() { | |
changedir | |
touch $PHPBENCHLOG | |
echo -e "\n$(date)" >> $PHPBENCHLOG | |
for ((i = 0 ; i < $RUNS ; i++)); do | |
{ | |
echo | |
bbcodestart | |
/usr/bin/time --format='real: %es user: %Us sys: %Ss cpu: %P maxmem: %M KB cswaits: %w' php Zend/bench.php | |
bbcodeend | |
phpmem | |
} 2>&1 | tee -a $PHPBENCHLOG | |
done | |
TOTAL=$(awk '/Total/ {print $2}' $PHPBENCHLOG) | |
AVG=$(awk '/Total/ {print $2}' $PHPBENCHLOG | awk '{ sum += $1 } END { if (NR > 0) printf "%.4f\n", sum / NR }') | |
TIMEREAL=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPBENCHLOG | awk '{ sum += $2 } END { if (NR > 0) printf "%.2f\n", sum / NR }') | |
TIMEUSER=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPBENCHLOG | awk '{ sum += $4 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
TIMESYS=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPBENCHLOG | awk '{ sum += $6 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
TIMECPU=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPBENCHLOG | awk '{ sum += $8 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
TIMEMEM=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPBENCHLOG | awk '{ sum += $10 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
TIMECS=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPBENCHLOG | awk '{ sum += $13 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
echo | |
bbcodestart | |
echo -e "bench.php results from $RUNS runs\n$TOTAL" | |
echo | |
echo "bench.php avg: $AVG" | |
echo "Avg: real: ${TIMEREAL}s user: ${TIMEUSER}s sys: ${TIMESYS}s cpu: ${TIMECPU}% maxmem: ${TIMEMEM}KB cswaits: ${TIMECS}" | |
echo "created results log at $PHPBENCHLOG" | |
echo "server PHP info log at ${PHPBENCHLOGDIR}/bench_phpinfo_${DT}.log" | |
bbcodeend | |
echo | |
} | |
fmicrobench() { | |
changedir | |
touch $PHPMICROBENCHLOG | |
echo -e "\n$(date)" >> $PHPMICROBENCHLOG | |
for ((i = 0 ; i < $RUNS ; i++)); do | |
{ | |
echo | |
bbcodestart | |
/usr/bin/time --format='real: %es user: %Us sys: %Ss cpu: %P maxmem: %M KB cswaits: %w' php Zend/micro_bench.php | |
bbcodeend | |
phpmem | |
} 2>&1 | tee -a $PHPMICROBENCHLOG | |
done | |
MTOTAL=$(awk '/Total/ {print $2}' $PHPMICROBENCHLOG) | |
MAVG=$(awk '/Total/ {print $2}' $PHPMICROBENCHLOG | awk '{ sum += $1 } END { if (NR > 0) printf "%.4f\n", sum / NR }') | |
MTIMEREAL=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPMICROBENCHLOG | awk '{ sum += $2 } END { if (NR > 0) printf "%.2f\n", sum / NR }') | |
MTIMEUSER=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPMICROBENCHLOG | awk '{ sum += $4 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
MTIMESYS=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPMICROBENCHLOG | awk '{ sum += $6 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
MTIMECPU=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPMICROBENCHLOG | awk '{ sum += $8 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
MTIMEMEM=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPMICROBENCHLOG | awk '{ sum += $10 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
MTIMECS=$(echo $TOTAL | awk '/maxmem:/ {print $0}' $PHPMICROBENCHLOG | awk '{ sum += $13 } END { if (NR > 0) printf "%.2f\n", sum / NR }' ) | |
echo | |
bbcodestart | |
echo -e "micro_bench.php results from $RUNS runs\n$MTOTAL" | |
echo | |
echo "micro_bench.php avg: $MAVG" | |
echo "Avg: real: ${MTIMEREAL}s user: ${MTIMEUSER}s sys: ${MTIMESYS}s cpu: ${MTIMECPU}% maxmem: ${MTIMEMEM}KB cswaits: ${MTIMECS}" | |
echo "created results log at $PHPMICROBENCHLOG" | |
echo "server PHP info log at ${PHPBENCHLOGDIR}/bench_phpinfo_${DT}.log" | |
bbcodeend | |
echo | |
} | |
###################################################### | |
case "$1" in | |
bench) | |
echo "bench.php test starting..." | |
phpi | |
restartphp | |
fbench | |
restartphp | |
echo | |
echo "php benchmarks completed..." | |
;; | |
microbench) | |
echo "micro_bench.php test starting..." | |
phpi | |
restartphp | |
fmicrobench | |
restartphp | |
echo | |
echo "php benchmarks completed..." | |
;; | |
chart) | |
;; | |
*) | |
echo "$0 {bench|microbench|chart}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment