Skip to content

Commit

Permalink
ci: change to pass script to run benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Jul 3, 2024
1 parent 04326b2 commit 6e453d2
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 3 deletions.
92 changes: 92 additions & 0 deletions .github/scripts/run-bench-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
set -euo pipefail

# benchmark over ssh
#
# MagicOnion Client
# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 [email protected] 'bash -s -- --args "-u http://${BENCHMARK_SERVER_NAME}:5000 -s streaminghub --channels 1 --streams 1"' < ./scripts/run-benchmark.sh
# $ echo $?

function usage {
echo "usage: $(basename $0) --args <string> [options]"
echo "Required:"
echo " --args string Arguments to pass when running the built binary (default: \"\")"
echo "Options:"
echo " --help Show this help message"
}

while [ $# -gt 0 ]; do
case $1 in
# required
--args) _ARGS=$2; shift 2; ;;
# optional
--help) usage; exit 1; ;;
*) shift ;;
esac
done

function print() {
echo ""
echo "$*"
}

# parameter setup
repo="MagicOnion"
args="${_ARGS:=""}"
build_csproj="perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj"
env_settings=""

binary_name=$(basename "$(dirname "$build_csproj")")
publish_dir="artifacts/$binary_name"
clone_path="$HOME/github/$repo"
output_dir="$clone_path/$publish_dir"
full_process_path="$output_dir/$binary_name"

# show machine name
print "MACHINE_NAME: $(hostname)"

# is dotnet installed?
print "# Show installed dotnet sdk versions"
echo "dotnet sdk versions (list): $(dotnet --list-sdks)"
echo "dotnet sdk version (default): $(dotnet --version)"

# setup env
print "# Setup environment"
IFS=';' read -ra env_array <<< "$env_settings"
for item in "${env_array[@]}"; do
if [ -n "$item" ]; then
export "$item"
fi
done

# dotnet publish
print "# dotnet publish $build_csproj"
pushd "$clone_path"
print " ## list current files under $(pwd)"
ls -l

print " ## dotnet publish $build_csproj"
dotnet publish -c "$build_config" -p:PublishSingleFile=true --runtime linux-x64 --self-contained false "$build_csproj" -o "$publish_dir"

print " ## list published files under $publish_dir"
ls "$publish_dir"

print " ## add +x permission to published file $full_process_path"
chmod +x "$full_process_path"
popd

# process check
print "# Checking process $binary_name already runnning, kill if exists"
ps -eo pid,cmd | while read -r pid cmd; do
if echo "$cmd" | grep -E "^./$binary_name" >/dev/null 2>&1; then
echo "Found & killing process $pid ($cmd)"
kill "$pid"
fi
done

# run dotnet app
print "# Run $full_process_path"
pushd "$output_dir"
# run foreground
"./$binary_name" $args
popd
87 changes: 87 additions & 0 deletions .github/scripts/run-bench-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
set -euo pipefail

# benchmark over ssh
#
# MagicOnion Server
# ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 [email protected] 'bash -s -- ' < ./scripts/run-server
# $ echo $?

function usage {
echo "usage: $(basename $0) [options]"
echo "Options:"
echo " --help Show this help message"
}

while [ $# -gt 0 ]; do
case $1 in
--help) usage; exit 1; ;;
*) shift ;;
esac
done

function print() {
echo ""
echo "$*"
}

# parameter setup
repo="MagicOnion"
build_config="Release"
build_csproj="perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj"
env_settings=""

binary_name=$(basename "$(dirname "$build_csproj")")
publish_dir="artifacts/$binary_name"
clone_path="$HOME/github/$repo"
output_dir="$clone_path/$publish_dir"
full_process_path="$output_dir/$binary_name"

# show machine name
print "MACHINE_NAME: $(hostname)"

# is dotnet installed?
print "# Show installed dotnet sdk versions"
echo "dotnet sdk versions (list): $(dotnet --list-sdks)"
echo "dotnet sdk version (default): $(dotnet --version)"

# setup env
print "# Setup environment"
IFS=';' read -ra env_array <<< "$env_settings"
for item in "${env_array[@]}"; do
if [ -n "$item" ]; then
export "$item"
fi
done

# process check
print "# Checking process $binary_name already runnning, kill if exists"
ps -eo pid,cmd | while read -r pid cmd; do
if echo "$cmd" | grep -E "^./$binary_name" >/dev/null 2>&1; then
echo "Found & killing process $pid ($cmd)"
kill "$pid"
fi
done

# dotnet publish
print "# dotnet publish $build_csproj"
pushd "$clone_path"
print " ## list current files under $(pwd)"
ls -l

print " ## dotnet publish $build_csproj"
dotnet publish -c "$build_config" -p:PublishSingleFile=true --runtime linux-x64 --self-contained false "$build_csproj" -o "$publish_dir"

print " ## list published files under $publish_dir"
ls "$publish_dir"

print " ## add +x permission to published file $full_process_path"
chmod +x "$full_process_path"
popd

# run dotnet app
print "# Run $full_process_path"
pushd "$output_dir"
# run background
"./$binary_name" &
popd
7 changes: 4 additions & 3 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
branch: ${{ needs.prepare.outputs.branch }}
dotnet-version: "8.0"
environment: benchmark
client-args-format: "-u http://{0}:5000 -s streaminghub --channels 1 --streams 1" # {0} will be replaced with server address
client-csproj: "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj"
server-csproj: "perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj"
client-benchmark-script-path: ".github/scripts/run-bench-client.sh"
client-benchmark-script-args: "--args \"-u http://${BENCHMARK_SERVER_NAME}:5000 -s streaminghub --channels 1 --streams 1\""
server-benchmark-script-path: ".github/scripts/run-bench-server.sh"
server-benchmark-script-args: ""
secrets: inherit

0 comments on commit 6e453d2

Please sign in to comment.