knative-report/benchmark/classic/benchmark.sh

120 lines
5.8 KiB
Bash

#!/usr/bin/env bash
#Configuration variables
functions=(isprime-kubeless-go-sc)
connections=(45)
times=(30s)
kuberhost="node1:31299"
kubeless=true
rps=500
#Climb mode configuration
climb_max=10
climb=1
HEY_INSTALLED=$(command -v hey)
if [[ $HEY_INSTALLED == "" ]]; then
apt update
apt install -y golang
go get -u github.com/rakyll/hey
cp "$HOME"/go/bin/hey /usr/local/bin
fi
LOADTEST_INSTALLED=$(command -v loadtest)
if [[ $LOADTEST_INSTALLED == "" ]]; then
apt update
apt install -y nodejs npm
npm i -g loadtest
fi
echo -e "Benchmarking functions\n"
date '+%Y-%m-%d %H:%M:%S' > ./data/date.txt
for function in "${functions[@]}"; do
function_friendly=$(echo $function | cut - -d'-' -f1)
echo -e "Benchmarking $function\n"
echo -e "Output of $function is:\n"
if $kubeless; then
perl -pi -e 'chomp if eof' "$function_friendly".body
curl --data-binary @"$function_friendly".body --header "Host: $function.kubeless" --header "Content-Type:application/json" http://$kuberhost/"$function"
else
curl --header "Host: $function.default.example.com" http://$kuberhost/
fi
echo -e "\n"
for connection in "${connections[@]}"; do
if [[ $connection -lt $((maxthreads + 1)) ]]; then
threads=$((connection - 1))
else
threads=$maxthreads
fi
echo -e "Threads: $threads Connections $connection\n"
for time in "${times[@]}"; do
datetime=$(date '+%Y-%m-%d-%H-%M-%S')
echo -e "Time: $time\n"
if [[ $* == *"--fire"* ]]; then
echo -e "summary $datetime\n"
if $kubeless; then
if [[ $* == *"--loadtest"* ]]; then
loadtest -k -H "Host: $function.kubeless" --rps $rps -c $connection -t $time -p "$function_firendly".body http://$kuberhost/"$function" >./data/"$function"."$connection"."$time"."$datetime".txt
else
hey -c "$connection" -q $rps -z "$time" -m POST -host "$function.kubeless" -D "$function_firendly".body -T "application/json" http://$kuberhost/"$function" >./data/"$function"."$connection"."$time"."$datetime".txt
fi
else
if [[ $* == *"--loadtest"* ]]; then
loadtest -k -H "Host: $function.default.example.com" --rps $rps -c $connection -t $time http://$kuberhost/ >./data/"$function"."$connection"."$time"."$datetime".txt
else
hey -c "$connection" -q $rps -z "$time" -m POST -host "$function.default.example.com" http://$kuberhost/ >./data/"$function"."$connection"."$time"."$datetime".txt
fi
fi
fi
if [[ $* == *"--csv"* ]]; then
echo -e "hey-csv $datetime\n"
if $kubeless; then
hey -c "$connection" -z "$time" -m POST -host "$function.kubeless" -D "$function_firendly".body -T "application/json" http://$kuberhost/"$function" >./data/"$function"."$connection"."$time"."$datetime".csv
else
hey -c "$connection" -z "$time" -m POST -host "$function.default.example.com" http://$kuberhost/ >./data/"$function"."$connection"."$time"."$datetime".csv
fi
fi
if [[ $* == *"--for"* ]]; then
for num in 1 2 3 4 5 6 7 8 9 10; do
echo -e "for $num\n"
if $kubeless; then
if [[ $* == *"--loadtest"* ]]; then
loadtest -k -H "Host: $function.kubeless" --rps $rps -c $connection -t $time -p "$function_firendly".body http://$kuberhost/"$function" >./data/"$function"."$num".txt
else
hey -c "$connection" -q $rps -z "$time" -m POST -o csv -host "$function.kubeless" -D "$function_friendly".body -T "application/json" http://$kuberhost/"$function" >./data/"$function"."$num".csv
fi
else
if [[ $* == *"--loadtest"* ]]; then
loadtest -k -H "Host: $function.default.example.com" --rps $rps -c $connection -t $time http://$kuberhost/ >./data/"$function"."$num".for.csv
else
hey -c "$connection" -q $rps -z "$time" -m POST -o csv -host "$function.default.example.com" http://$kuberhost/ >./data/"$function"."$num".for.csv
fi
fi
done
fi
done
done
if [[ $* == *"--climb"* ]]; then
while [[ $climb -lt $climb_max ]]; do
climb_rps=$((rps * climb))
echo -e "Rps: $climb_rps"
if $kubeless; then
if [[ $* == *"--loadtest"* ]]; then
loadtest -k -H "Host: $function.kubeless" --rps $climb_rps -c 1 -t $time -p "$function_firendly".body http://$kuberhost/"$function" >./data/"$function"."$climb_rps".climb.txt
else
hey -c $climb -q $rps -z $time -m POST -o csv -host "$function.kubeless" -D "$function_friendly".body -T "application/json" http://$kuberhost/"$function" >./data/"$function"."$climb_rps".climb.csv
fi
else
if [[ $* == *"--loadtest"* ]]; then
loadtest -k -H "Host: $function.default.example.com" --rps $climb_rps -c 1 -t $time http://$kuberhost/ >./data/"$function"."$climb_rps".climb.txt
else
hey -c $climb -q $rps -z $time -m POST -o csv -host "$function.default.example.com" http://$kuberhost/ >./data/"$function"."$climb_rps".climb.csv
fi
fi
climb=$((climb + 1))
done
fi
echo -e "Finished at $datetime"
done
date '+%Y-%m-%d %H:%M:%S' >> ./data/date.txt