This commit is contained in:
2019-10-02 18:27:25 +02:00
parent d6dd233e83
commit 14cb4ae908
45 changed files with 1333 additions and 0 deletions

115
benchmark/benchmark.sh Normal file
View File

@ -0,0 +1,115 @@
#!/usr/bin/env bash
#Requirements:
#<function name without dashes>.wrk descriptor file for wrk
#<function name without dashes>.body (even if you don't need it)
#Configuration variables
functions=(isprime-scale isprime-scale-py isprime-scale-js hello-scale hello-scale-py hello-scale-js hello hello-js hello-py isprime isprime-js isprime-py)
connections=(1000)
times=(1m)
kuberhost="node1:30765"
maxthreads=40
#Wave mode configuration
wave_connection=40
wave_max_conn=160
wave_min_conn=40
wave_time="1m"
wave_loop_max=2
WRK_INSTALLED=$(command -v wrk)
if [[ $WRK_INSTALLED = "" ]]
then
apt update
apt install build-essential libssl-dev git -y
git clone https://github.com/wg/wrk.git wrk
cd wrk || exit
cores=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)
make -j $((cores + 1))
cp wrk /usr/local/bin
fi
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
echo -e "Benchmarking functions\n"
for function in "${functions[@]}"
do
function_friendly=$(echo $function | cut - -d'-' -f1)
echo -e "Benchmarking $function\n"
echo -e "Output of $function is:\n"
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"
echo -e "\n"
if [[ $* = *"--wave"* ]]
then
wave_loop=1
wave_dir_up=true
while [[ $wave_loop -lt $wave_loop_max ]]; do
now=$(date '+%Y-%m-%d-%H-%M')
echo -e "Connections: $wave_connection"
echo -e "Running"
hey -c $wave_connection -z $wave_time -m POST -o csv -host "$function.kubeless" -D "$function_friendly".body -T "application/json" http://$kuberhost/"$function" > ./data/"$function"."$wave_connection"."$now".wave.csv
if $wave_dir_up
then
if [[ $wave_connection -lt $wave_max_conn ]]
then
echo -e "Stepping up"
wave_connection=$((wave_connection * 5))
else
echo -e "Not stepping"
wave_dir_up=false
fi
else
if [[ $wave_connection -gt $wave_min_conn ]]
then
echo -e "Stepping down"
wave_connection=$((wave_connection / 5))
else
echo -e "Not stepping"
wave_dir_up=true
wave_loop=$((wave_loop + 1))
fi
fi
done
else
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 [[ $* = *"--wrk"* ]]
then
echo -e "wrk $datetime\n"
wrk -t$threads -c"$connection" -d"$time" -s"$function_friendly".wrk -H"Host: $function.kubeless" -H"Content-Type:application/json" --latency http://$kuberhost/"$function" > ./data/"$function"."$connection"."$time"."$datetime".wrk.txt 2>&1
fi
if [[ $* = *"--hey"* ]]
then
echo -e "hey-summary $datetime\n"
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".hey.txt
fi
if [[ $* = *"--csv"* ]]
then
echo -e "hey-csv $datetime\n"
hey -c "$connection" -z "$time" -m POST -o csv -host "$function.kubeless" -D "$function_friendly".body -T "application/json" http://$kuberhost/"$function" > ./data/"$function"."$connection"."$time"."$datetime".csv
fi
echo -e "Finished at $datetime"
done
done
fi
done
python3 ./data/process.py > ./data/processed.txt

61
benchmark/data/process.py Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3
import csv
import os
from pprint import pprint
import numpy as np
import matplotlib.pyplot as plt
#Returns array of csv files in current directory
def getFiles():
files = [f for f in os.listdir('.') if os.path.isfile(f)]
return[ f for f in files if f.endswith('.csv') ]
def processFile(fname):
with open(fname,'r') as f:
lines=[]
data=csv.reader(f)
fields=next(data)
responseCodes={}
responsePerSec={}
responseTimes=[]
for row in data:
items=zip(fields,row)
item={}
for(name,value) in items:
item[name]=value.strip()
sec=int(item['offset'].split('.')[0])
if sec not in responsePerSec:
responsePerSec[sec]=[]
else:
responsePerSec[sec].append(item['response-time'])
code=item['status-code']
if code not in responseCodes:
responseCodes[code]=1
else:
responseCodes[code]=responseCodes[code]+1
responseTimes.append(item['response-time'])
if len(responseTimes)!=0:
maxResponse=max(responseTimes)
minResponse=min(responseTimes)
print("Maximum response time was ",maxResponse)
print("Minimum response time was ",minResponse)
else:
print("csv is empty")
pprint(responseCodes)
for sec in responsePerSec:
if len(responsePerSec[sec])!=0:
print(sec, ":")
print(" Maximum:", max(responsePerSec[sec]))
print(" Minimum:", min(responsePerSec[sec]))
print(" Num of responses:", len(responsePerSec[sec]))
else:
print(" empty")
def processAllFiles():
files=getFiles()
for f in files:
print("Processing ", f)
processFile(f)
if __name__ == "__main__":
processAllFiles()

View File

@ -0,0 +1,2 @@
numpy
matplotlib

1
benchmark/hello.body Normal file
View File

@ -0,0 +1 @@

1
benchmark/hello.wrk Normal file
View File

@ -0,0 +1 @@
wrk.method = "GET"

1
benchmark/isprime.body Normal file
View File

@ -0,0 +1 @@
107107

26
benchmark/isprime.wrk Normal file
View File

@ -0,0 +1,26 @@
wrk.method = "POST"
wrk.body = "107107"
done = function(summary, latency, requests)
-- open output file
f = io.open("result.csv", "a+")
-- write below results to file
-- minimum latency
-- max latency
-- mean of latency
-- standard deviation of latency
-- 50percentile latency
-- 90percentile latency
-- 99percentile latency
-- 99.999percentile latency
-- duration of the benchmark
-- total requests during the benchmark
-- total received bytes during the benchmark
f:write(string.format("%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d\n",
latency.min, latency.max, latency.mean, latency.stdev, latency:percentile(50),
latency:percentile(90), latency:percentile(99), latency:percentile(99.999),
summary["duration"], summary["requests"], summary["bytes"]))
f:close()
end

24
benchmark/report.lua Normal file
View File

@ -0,0 +1,24 @@
done = function(summary, latency, requests)
-- open output file
f = io.open("result.csv", "a+")
-- write below results to file
-- minimum latency
-- max latency
-- mean of latency
-- standard deviation of latency
-- 50percentile latency
-- 90percentile latency
-- 99percentile latency
-- 99.999percentile latency
-- duration of the benchmark
-- total requests during the benchmark
-- total received bytes during the benchmark
f:write(string.format("%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d\n",
latency.min, latency.max, latency.mean, latency.stdev, latency:percentile(50),
latency:percentile(90), latency:percentile(99), latency:percentile(99.999),
summary["duration"], summary["requests"], summary["bytes"]))
f:close()
end