Skip to content

Commit

Permalink
bash enhancements
Browse files Browse the repository at this point in the history
added depth_to_xyz experiment
  • Loading branch information
emil916 committed Apr 30, 2024
1 parent bfc8429 commit 7b77918
Show file tree
Hide file tree
Showing 28 changed files with 711 additions and 373 deletions.
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
res
res-*
perf.data
perf.data.old
samples
Expand Down
135 changes: 10 additions & 125 deletions tests/bash_libraries/experiment_globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,20 @@
if [ -n "$__experiment_server_globals_sh__" ]; then return; fi
__experiment_server_globals_sh__=$(date)

# App WASM so files:
declare -r FIBONACCI="fibonacci.wasm.so"
declare -r EKF="gps_ekf.wasm.so"
declare -r CIFAR10="cifar10.wasm.so"
declare -r GOCR="gocr.wasm.so"
declare -r LPD="license_plate_detection.wasm.so"
declare -r RESIZE="resize_image.wasm.so"
declare -r CNN="cnn_face_detection.wasm.so"

# The global configs for the scripts
declare -gr SERVER_LOG_FILE="perf.log"
declare -gr SERVER_HTTP_LOG_FILE="http_perf.log"
declare -gr HEY_OPTS="-disable-compression -disable-keepalive -disable-redirects"

# Globals to fill during run_init in run.sh, to use in base and generate_spec
declare -A ports=()
declare -A repl_periods=()
declare -A max_budgets=()
declare -A wasm_paths=()
declare -A expected_execs=()
declare -A deadlines=()
declare -A resp_content_types=()
declare -A arg_opts_hey=()
declare -A arg_opts_lt=()
declare -A args=()
declare -A concurrencies=()
declare -A rpss=()
declare -a workloads=()
declare -A workload_tids=()
declare -A workload_deadlines=()
declare -A workload_vars=()

# Sandbox Perf Log Globals:
declare -ga SANDBOX_METRICS=(total queued uninitialized allocated initialized runnable interrupted preempted running_sys running_user asleep returned complete error)
declare -gA SANDBOX_METRICS_FIELDS=(
Expand All @@ -48,6 +39,7 @@ declare -gr SANDBOX_TENANT_NAME_FIELD=2
declare -gr SANDBOX_ROUTE_FIELD=3
declare -gr SANDBOX_CPU_FREQ_FIELD=20
declare -gr SANDBOX_RESPONSE_CODE_FIELD=21
declare -gr SANDBOX_GUARANTEE_TYPE_FIELD=22

# HTTP Session Perf Log Globals:
declare -ga HTTP_METRICS=(http_receive http_sent http_total)
Expand All @@ -59,110 +51,3 @@ declare -gA HTTP_METRICS_FIELDS=(
declare -gr HTTP_TENANT_NAME_FIELD=1
declare -gr HTTP_ROUTE_FIELD=2
declare -gr HTTP_CPU_FREQ_FIELD=9

assert_run_experiments_args() {
if (($# != 3)); then
panic "invalid number of arguments \"$#\""
return 1
elif [[ -z "$1" ]]; then
panic "hostname \"$1\" was empty"
return 1
elif [[ ! -d "$2" ]]; then
panic "directory \"$2\" does not exist"
return 1
elif [[ -z "$3" ]]; then
panic "load gen \"$3\" was empty"
return 1
fi
}

assert_process_client_results_args() {
if (($# != 1)); then
error_msg "invalid number of arguments ($#, expected 1)"
return 1
elif ! [[ -d "$1" ]]; then
error_msg "directory $1 does not exist"
return 1
fi
}

assert_process_server_results_args() {
if (($# != 1)); then
panic "invalid number of arguments \"$#\""
return 1
elif [[ ! -d "$1" ]]; then
panic "directory \"$1\" does not exist"
return 1
fi
}

load_value() {
local result=$1
if [ "$result" = "?" ]; then
result=$2
fi
echo "$result"
}

run_init() {
for var in "${VARYING[@]}"; do
for t_idx in "${!TENANT_IDS[@]}"; do
local tenant_id=${TENANT_IDS[$t_idx]}
local tenant=$(printf "%s-%03d" "$tenant_id" "$var")
local port=$((INIT_PORTS[t_idx]+var))
local repl_period=$(load_value ${MTDS_REPL_PERIODS_us[$t_idx]} $var)
local budget=$(load_value ${MTDS_MAX_BUDGETS_us[$t_idx]} $var)

# TENANTS+=("$tenant")
ports+=([$tenant]=$port)
repl_periods+=([$tenant]=$repl_period)
max_budgets+=([$tenant]=$budget)

local t_routes r_expected_execs r_deadlines r_arg_opts_hey r_arg_opts_lt r_args r_loads

IFS=' ' read -r -a t_routes <<< "${ROUTES[$t_idx]}"
IFS=' ' read -r -a r_wasm_paths <<< "${WASM_PATHS[$t_idx]}"
IFS=' ' read -r -a r_expected_execs <<< "${EXPECTED_EXEC_TIMES_us[$t_idx]}"
IFS=' ' read -r -a r_deadlines <<< "${DEADLINES_us[$t_idx]}"
IFS=' ' read -r -a r_resp_content_types <<< "${RESP_CONTENT_TYPES[$t_idx]}"

IFS=' ' read -r -a r_arg_opts_hey <<< "${ARG_OPTS_HEY[$t_idx]}"
IFS=' ' read -r -a r_arg_opts_lt <<< "${ARG_OPTS_LT[$t_idx]}"
IFS=' ' read -r -a r_args <<< "${ARGS[$t_idx]}"
IFS=' ' read -r -a r_loads <<< "${LOADS[$t_idx]}"

for r_idx in "${!t_routes[@]}"; do
local route=${t_routes[$r_idx]}
local wasm_path=${r_wasm_paths[$r_idx]}
local expected=${r_expected_execs[$r_idx]}
local deadline=${r_deadlines[$r_idx]}
local resp_content_type=${r_resp_content_types[$r_idx]}
local arg_opt_hey=${r_arg_opts_hey[$r_idx]}
local arg_opt_lt=${r_arg_opts_lt[$r_idx]}
local arg=${r_args[$r_idx]}
local load=$(load_value ${r_loads[$r_idx]} $var)

local workload="$tenant-$route"

# Divide as float, cast the result to int (Loadtest is okay floats, HEY is not)
local con=$(echo "x = $NWORKERS * $deadline / $expected * $load / 100; x/1" | bc)
local rps=$((1000000 * con / deadline))
# local rps=$(echo "x = 1000000 * $con / $deadline; x/1" | bc)

wasm_paths+=([$workload]=$wasm_path)
expected_execs+=([$workload]=$expected)
deadlines+=([$workload]=$deadline)
resp_content_types+=([$workload]=$resp_content_type)
arg_opts_hey+=([$workload]=$arg_opt_hey)
arg_opts_lt+=([$workload]=$arg_opt_lt)
args+=([$workload]=$arg)
concurrencies+=([$workload]=$con)
rpss+=([$workload]=$rps)
workloads+=("$workload")
workload_tids+=([$workload]=$tenant_id)
workload_deadlines+=([$workload]=$deadline)
workload_vars+=([$workload]=$var)
done
done
done
}
15 changes: 9 additions & 6 deletions tests/bash_libraries/framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ __framework_sh__parse_arguments() {
;;
-n=* | --name=*)
echo "Set experiment name to ${i#*=}"
__framework_sh__experiment_name="${i#*=}"
__framework_sh__experiment_name+=" ${i#*=}"
shift
;;
-e=* | --envfile=*)
Expand All @@ -190,6 +190,9 @@ __framework_sh__parse_arguments() {
__framework_sh__usage
exit 0
;;
nuclio | Nuclio)
echo "Running for Nuclio"
;;
*)
echo "$1 is a not a valid option"
__framework_sh__usage
Expand All @@ -199,7 +202,7 @@ __framework_sh__parse_arguments() {
done

if [[ -z "$__framework_sh__envfile" ]]; then
if [[ -d "$__framework_sh__application_directory/res/$__framework_sh__experiment_name/" ]]; then
if [[ -d "$__framework_sh__application_directory/res-$__framework_sh__role/$__framework_sh__experiment_name/" ]]; then
echo "Experiment $__framework_sh__experiment_name already exists. Pick a unique name!"
exit 1
fi
Expand All @@ -209,8 +212,8 @@ __framework_sh__parse_arguments() {
exit 1
fi
short_name="$(basename "${__framework_sh__envfile/.env/}")"
echo "$__framework_sh__application_directory/res/$__framework_sh__experiment_name/$short_name/"
if [[ -d "$__framework_sh__application_directory/res/$__framework_sh__experiment_name/$short_name/" ]]; then
echo "$__framework_sh__application_directory/res-$__framework_sh__role/$__framework_sh__experiment_name/$short_name/"
if [[ -d "$__framework_sh__application_directory/res-$__framework_sh__role/$__framework_sh__experiment_name/$short_name/" ]]; then
echo "Variant $short_name was already run in experiment ${__framework_sh__experiment_name}."
exit 1
fi
Expand Down Expand Up @@ -469,8 +472,8 @@ __framework_sh__run_both() {
__framework_sh__create_and_export_results_directory() {
local -r subdirectory=${1:-""}

local dir="$__framework_sh__application_directory/res/$__framework_sh__experiment_name"
# local dir="$__framework_sh__application_directory/res/$__framework_sh__experiment_name/$subdirectory"
local dir="$__framework_sh__application_directory/res-$__framework_sh__role/$__framework_sh__experiment_name"
# local dir="$__framework_sh__application_directory/res-$__framework_sh__role/$__framework_sh__experiment_name/$subdirectory"

mkdir -p "$dir" || {
panic "mkdir -p $dir"
Expand Down
26 changes: 25 additions & 1 deletion tests/bash_libraries/generate_spec_json.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# shellcheck shell=bash
# shellcheck disable=SC2154
# shellcheck disable=SC2154,SC2155
if [ -n "$__generate_spec_json_sh__" ]; then return; fi
__generate_spec_json_sh__=$(date)

jq_admin_spec() {
jq ". + {\
\"name\": \"Admin\",\
\"port\": 55555,\
\"replenishment-period-us\": 0,\
\"max-budget-us\": 0,\
\"reservation-percentile\": 0,\
\"routes\": [\
.routes[] + {\
\"route\": \"/admin\",\
\"admissions-percentile\": 50,\
\"expected-execution-us\": 1000,\
\"relative-deadline-us\": 10000},\
.routes[] + {\
\"route\": \"/terminator\",\
\"admissions-percentile\": 50,\
\"expected-execution-us\": 1000,\
\"relative-deadline-us\": 10000}\
]\
}" < "./template.json" > "./result_admin.json"
}

generate_spec_json() {
printf "Generating 'spec.json'\n"

Expand All @@ -13,12 +35,14 @@ generate_spec_json() {
local port=${ports[$tenant]}
local repl_period=${repl_periods[$tenant]}
local budget=${max_budgets[$tenant]}
local reservation=${reservations[$tenant]}

jq_str=". + {
\"name\": \"$tenant\",\
\"port\": $port,\
\"replenishment-period-us\": $repl_period,\
\"max-budget-us\": $budget,\
\"reservation-percentile\": $reservation,\
\"routes\": ["

local t_routes
Expand Down
113 changes: 113 additions & 0 deletions tests/bash_libraries/install_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash

if ! command -v http > /dev/null; then
if [[ $(whoami) == "root" ]]; then
apt update
apt install -y httpie
else
sudo apt update
sudo apt install -y httpie
fi
fi

if ! command -v hey > /dev/null; then
HEY_URL=https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
wget $HEY_URL -O hey
chmod +x hey

if [[ $(whoami) == "root" ]]; then
mv hey /usr/bin/hey
else
sudo mv hey /usr/bin/hey
fi
fi

if ! command -v loadtest > /dev/null; then
if ! command -v npm > /dev/null; then
# if [[ $(whoami) == "root" ]]; then
# apt update
# apt install -y npm
# else
# sudo apt update
# sudo apt install -y npm
# fi
# installs NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# download and install Node.js
nvm install 14
# verifies the right Node.js version is in the environment
node -v # should print `v14.21.3`
# verifies the right NPM version is in the environment
npm -v # should print `6.14.18`
fi

# Try pulling Emil's version of loadtest to support post binary files
# if [[ $(whoami) == "root" ]]; then
# npm install -y -g loadtest
# else
# sudo npm install -y -g loadtest
# fi

pushd ~
git clone https://github.com/emil916/loadtest.git
pushd loadtest
# if [[ $(whoami) == "root" ]]; then
npm install -g
# else
# sudo npm install -g
# fi
popd
popd
fi

if ! command -v gnuplot > /dev/null; then
if [[ $(whoami) == "root" ]]; then
apt update
apt install -y gnuplot
else
sudo apt update
sudo apt install -y gnuplot
fi
fi


if ! command -v jq > /dev/null; then
if [[ $(whoami) == "root" ]]; then
apt update
apt install -y jq
else
sudo apt update
sudo apt install -y jq
fi
fi

if ! command -v htop > /dev/null; then
if [[ $(whoami) == "root" ]]; then
apt update
apt install -y htop
else
sudo apt update
sudo apt install -y htop
fi
fi

# For SOD:
# if ! command -v imagemagick > /dev/null; then
# if [ "$(whoami)" == "root" ]; then
# apt-get install -y imagemagick
# else
# sudo apt-get install -y imagemagick
# fi
# fi

# For GOCR, too many to check one-by-one, so uncomment below to install:
# if [[ "$(whoami)" == "root" ]]; then
# apt-get install -y netpbm pango1.0-tools wamerican fonts-roboto fonts-cascadia-code fonts-dejavu
# else
# sudo apt-get install -y netpbm pango1.0-tools wamerican fonts-roboto fonts-cascadia-code fonts-dejavu
# fi

source ~/.bashrc
Loading

0 comments on commit 7b77918

Please sign in to comment.