Skip to content

Commit

Permalink
Merge pull request #380 from gwsystems/mt-dbf
Browse files Browse the repository at this point in the history
Merging this since it is mainly bash scripts added for multi tenancy testbed.
  • Loading branch information
emil916 authored Sep 25, 2023
2 parents 5e25580 + ba8818e commit b85e13f
Show file tree
Hide file tree
Showing 28 changed files with 794 additions and 487 deletions.
6 changes: 4 additions & 2 deletions runtime/src/libc/wasi_impl_serverless.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ wasi_context_init(wasi_options_t *options)
}
}

/* Seed Random */
srandom(time(NULL));
/* Seed Random
* Commented out as a temporary fix for the mutex blocking delay srandom causes in libc.
*/
// srandom(time(NULL));

/* TODO: Preopens */

Expand Down
93 changes: 91 additions & 2 deletions tests/bash_libraries/experiment_globals.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# shellcheck shell=bash
# shellcheck disable=SC2034
# shellcheck disable=SC2034,SC2153,SC2154,SC2155
if [ -n "$__experiment_server_globals_sh__" ]; then return; fi
__experiment_server_globals_sh__=$(date)

# The global configs for the scripts
declare -gr SERVER_LOG_FILE="perf.log"
declare -gr SERVER_HTTP_LOG_FILE="http_perf.log"
declare -gr NWORKERS=$(($(nproc)-2))
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)
Expand Down Expand Up @@ -77,3 +95,74 @@ assert_process_server_results_args() {
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
}
6 changes: 5 additions & 1 deletion tests/bash_libraries/generate_gnuplots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ generate_gnuplots() {

shopt -s nullglob
for gnuplot_file in "$experiment_directory"/*.gnuplot; do
gnuplot "$gnuplot_file"
if [ -z "$TENANT_IDS" ]; then
gnuplot "$gnuplot_file"
else
gnuplot -e "tenant_ids='${TENANT_IDS[*]}'" "$gnuplot_file"
fi
done
cd "$experiment_directory" || exit
}
91 changes: 42 additions & 49 deletions tests/bash_libraries/generate_spec_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,54 @@
if [ -n "$__generate_spec_json_sh__" ]; then return; fi
__generate_spec_json_sh__=$(date)


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

for tenant in "${TENANTS[@]}"; do
port=${PORTS[$tenant]}
repl_period=${MTDS_REPLENISH_PERIODS_us[$tenant]}
budget=${MTDS_MAX_BUDGETS_us[$tenant]}
# reservation=${MTDBF_RESERVATIONS_percen[${tenant}]}
route=${ROUTES[$tenant]}
workload="$tenant-$route"
deadline=${DEADLINES_us[$workload]}
expected=${EXPECTED_EXECUTIONS_us[$workload]}
for var in "${VARYING[@]}"; do
for t_idx in "${!TENANT_IDS[@]}"; do
local jq_str
local tenant=$(printf "%s-%03d" "${TENANT_IDS[$t_idx]}" "$var")
local port=${ports[$tenant]}
local repl_period=${repl_periods[$tenant]}
local budget=${max_budgets[$tenant]}

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

local t_routes
IFS=' ' read -r -a t_routes <<< ${ROUTES[$t_idx]}

for index in "${!t_routes[@]}"; do
local route=${t_routes[$index]}
local workload="$tenant-$route"
local wasm_path=${wasm_paths[$workload]}
local resp_content_type=${resp_content_types[$workload]}
local expected=${expected_execs[$workload]}
local deadline=${deadlines[$workload]}

jq_str+=".routes[] + {\
\"route\": \"/$route\",\
\"path\": \"$wasm_path\",\
\"admissions-percentile\": $ESTIMATIONS_PERCENTILE,\
\"expected-execution-us\": $expected,\
\"relative-deadline-us\": $deadline,\
\"http-resp-content-type\": \"$resp_content_type\"}"

if [ "$index" != $((${#t_routes[@]}-1)) ]; then
jq_str+=","
fi
done
jq_str+="]}"

# Generates unique module specs on different ports using the given 'ru's
jq ". + { \
\"name\": \"$tenant\",\
\"port\": $port,\
\"replenishment-period-us\": $repl_period, \
\"max-budget-us\": $budget} | \
(.routes[] = \
.routes[] + { \
\"route\": \"/$route\",\
\"admissions-percentile\": $ESTIMATIONS_PERCENTILE,\
\"expected-execution-us\": $expected,\
\"relative-deadline-us\": $deadline
}) \
" \
< "./template.json" \
> "./result_${tenant}.json"
# \"reservation-percentile\": $reservation, \
jq "$jq_str" < "./template.json" > "./result_${tenant}.json"
done
done

if [ "$CLIENT_TERMINATE_SERVER" == true ]; then
jq ". + { \
\"name\": \"Admin\",\
\"port\": 55555,\
\"replenishment-period-us\": 0, \
\"max-budget-us\": 0} | \
(.routes = [\
.routes[] + { \
\"route\": \"/main\",\
\"admissions-percentile\": 70,\
\"expected-execution-us\": 1000,\
\"relative-deadline-us\": 10000}, \
.routes[] + { \
\"route\": \"/terminator\",\
\"admissions-percentile\": 70,\
\"expected-execution-us\": 1000,\
\"relative-deadline-us\": 10000 }\
]) \
" \
< "./template.json" \
> "./result_admin.json"
fi
jq_admin_spec

# Merges all of the multiple specs for a single module
jq -s '. | sort_by(.name)' ./result_*.json > "./spec.json"
Expand Down
74 changes: 74 additions & 0 deletions tests/bash_libraries/install_tools_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/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
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-get update
apt-get install -y gnuplot
else
sudo apt-get update
sudo apt-get 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
48 changes: 48 additions & 0 deletions tests/bash_libraries/install_tools_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

if ! command -v gnuplot > /dev/null; then
if [[ $(whoami) == "root" ]]; then
apt-get update
apt-get install -y gnuplot
else
sudo apt-get update
sudo apt-get 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
Loading

0 comments on commit b85e13f

Please sign in to comment.