From 9ec84882a70ff0112cb79194885d0fd85c46effb Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:00:19 +0900 Subject: [PATCH 01/17] chore: configure perf server listen url --- .../PerformanceTest.Server/Properties/launchSettings.json | 3 ++- perf/BenchmarkApp/PerformanceTest.Server/appsettings.json | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/perf/BenchmarkApp/PerformanceTest.Server/Properties/launchSettings.json b/perf/BenchmarkApp/PerformanceTest.Server/Properties/launchSettings.json index 2151c9d5c..0d2e73873 100644 --- a/perf/BenchmarkApp/PerformanceTest.Server/Properties/launchSettings.json +++ b/perf/BenchmarkApp/PerformanceTest.Server/Properties/launchSettings.json @@ -6,7 +6,8 @@ "launchBrowser": false, "applicationUrl": "http://localhost:5000;https://localhost:5001", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "Kestrel__Endpoints__Grpc__Url": "http://localhost:5000" } } } diff --git a/perf/BenchmarkApp/PerformanceTest.Server/appsettings.json b/perf/BenchmarkApp/PerformanceTest.Server/appsettings.json index 1aef5074f..02b5fa21c 100644 --- a/perf/BenchmarkApp/PerformanceTest.Server/appsettings.json +++ b/perf/BenchmarkApp/PerformanceTest.Server/appsettings.json @@ -9,6 +9,12 @@ "Kestrel": { "EndpointDefaults": { "Protocols": "Http2" + }, + "Endpoints": { + "Grpc": { + "Url": "http://+:5000", + "Protocols": "Http2" + } } } } From 70384307d6e3413693522aa93cad6bdcbb295c80 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:57:41 +0900 Subject: [PATCH 02/17] ci: add benchmark --- .github/workflows/benchmark.yml | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/benchmark.yml diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 000000000..3352b324e --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,37 @@ +name: Benchmark + +on: + push: + branches: + - feature/perf + +env: + BUILD_CONFIG: Release + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - uses: Cysharp/Actions/.github/actions/setup-dotnet@main + # build + - name: Build Client + run: dotnet publish -c ${{ env.BUILD_CONFIG }} --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj -o ./perf/artifacts/PerformanceTest.Client + - name: Build Server + run: dotnet publish -c ${{ env.BUILD_CONFIG }} --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj -o ./perf/artifacts/PerformanceTest.Server + # upload + - uses: Cysharp/Actions/.github/actions/upload-artifact@main + with: + name: artifacts + path: ./perf/artifacts + if-no-files-found: error + retention-days: 1 + + run: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + # run + # get result From b4cc11ab656f2119d44d58678d927d30b914bd5d Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:23:58 +0900 Subject: [PATCH 03/17] ci: publish single file --- .github/workflows/benchmark.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3352b324e..6bc3686e9 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -17,9 +17,9 @@ jobs: - uses: Cysharp/Actions/.github/actions/setup-dotnet@main # build - name: Build Client - run: dotnet publish -c ${{ env.BUILD_CONFIG }} --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj -o ./perf/artifacts/PerformanceTest.Client + run: dotnet publish -c ${{ env.BUILD_CONFIG }} -p:PublishSingleFile=true --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj -o ./perf/artifacts/PerformanceTest.Client - name: Build Server - run: dotnet publish -c ${{ env.BUILD_CONFIG }} --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj -o ./perf/artifacts/PerformanceTest.Server + run: dotnet publish -c ${{ env.BUILD_CONFIG }} -p:PublishSingleFile=true --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj -o ./perf/artifacts/PerformanceTest.Server # upload - uses: Cysharp/Actions/.github/actions/upload-artifact@main with: From 7d2cdced9666a3570d3987d98fb6e333c42350e8 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:25:45 +0900 Subject: [PATCH 04/17] ci: comment out [skip ci] --- .github/workflows/benchmark.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 6bc3686e9..2c11ea4ed 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -28,10 +28,11 @@ jobs: if-no-files-found: error retention-days: 1 - run: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v4 - # run - # get result +# run: +# needs: [build] +# runs-on: ubuntu-latest +# timeout-minutes: 10 +# steps: +# - uses: actions/checkout@v4 +# # run +# # get result From 249746f97b2561cc1064165abf10cf45257aa2b1 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 26 Jun 2024 19:15:22 +0900 Subject: [PATCH 05/17] ci: run benchmark on GitHub Actions --- .github/scripts/dotnet_install.sh | 56 +++++++++++++ .github/scripts/run_benchmark.sh | 133 ++++++++++++++++++++++++++++++ .github/workflows/benchmark.yml | 82 ++++++++++++------ 3 files changed, 248 insertions(+), 23 deletions(-) create mode 100644 .github/scripts/dotnet_install.sh create mode 100644 .github/scripts/run_benchmark.sh diff --git a/.github/scripts/dotnet_install.sh b/.github/scripts/dotnet_install.sh new file mode 100644 index 000000000..606479da2 --- /dev/null +++ b/.github/scripts/dotnet_install.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -euo pipefail + +# Install .NET SDK over ssh +# +# Sample usage: +# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.7.19 'bash -s -- --dotnet-version 8.0' < ./scripts/dotnet_install.sh +# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.1.54 'bash -s -- --dotnet-version 8.0' < ./scripts/dotnet_install.sh +# $ echo $? +# + +function usage { + echo "usage: $(basename $0) [options]" + echo "Options:" + echo " --dotnet-version string Version of dotnet sdk to install (default: 8.0)" + echo " --help Show this help message" + echo "" + echo "Examples:" + echo " 1. Install dotnet sdk version 8.0 over ssh" + echo " ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@255.255.255.255 'bash -s -- --dotnet-version 8.0' < ./scripts/$(basename $0).sh" + echo ' echo $? # use $? to get the exit code of the remote command' +} + +while [ $# -gt 0 ]; do + case $1 in + # optional + --dotnet-version) _DOTNET_VERSION=$2; shift 2; ;; + --help) usage; exit 1; ;; + *) shift ;; + esac +done + +function print() { + echo "" + echo "$*" +} + +dotnet_version="${_DOTNET_VERSION:="8.0"}" + +# show machine name +print "MACHINE_NAME: $(hostname)" + +# install dotnet (dotnet-install.sh must be downloaded before running script) +print "# Install dotnet sdk version: ${dotnet_version}" +sudo bash /opt/dotnet-install.sh --channel "${dotnet_version}" --install-dir /usr/share/dotnet + +# link dotnet to /usr/local/bin +print "# Link to /usr/local/bin/dotnet" +if [[ ! -h "/usr/local/bin/dotnet" ]]; then + sudo ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet +fi + +# show dotnet verison +print "# Show installed dotnet sdk versions" +echo "dotnet sdk versions (list): $(dotnet --list-sdks)" +echo "dotnet sdk version (default): $(dotnet --version)" diff --git a/.github/scripts/run_benchmark.sh b/.github/scripts/run_benchmark.sh new file mode 100644 index 000000000..d30d6c3a9 --- /dev/null +++ b/.github/scripts/run_benchmark.sh @@ -0,0 +1,133 @@ +#!/bin/bash +set -euo pipefail + +# git clone and run benchmark over ssh +# +# MagicOnion Server +# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.7.19 'bash -s -- --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj" --env-settings "Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh +# $ echo $? +# +# MagicOnion Client +# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.1.54 'bash -s -- --args "-u http://benchmark-server-vm:5000 -s streaminghub --channels 1 --streams 1" --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh +# $ echo $? + +function usage { + echo "usage: $(basename $0) --build-csproj --repo [options]" + echo "Required:" + echo " --build-csproj string Path to the csproj file to build" + echo " --repo string Repository name to clone" + echo "Options:" + echo " --args string Arguments to pass when running the built binary (default: \"\")" + echo " --branch string Branch name to checkout (default: main)" + echo " --build-config string Build configuration (default: Release)" + echo " --env-settings string Environment settings to set before running the binary, use ; to delinate multiple environments (default: \"\")" + echo " --owner string Repository owner (default: Cysharp)" + echo " --help Show this help message" + echo "" + echo "Examples:" + echo " 1. Run MagicOnion Benchmark Server over ssh" + echo " ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@255.255.255.255 'bash -s -- --branch main --build-csproj 'perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj' --env-settings \"Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;\" --owner Cysharp --repo MagicOnion' < ./scripts/$(basename $0).sh" + echo ' echo $? # use $? to get the exit code of the remote command' + echo "" + echo " 2. Run MagicOnion Benchmark Client over ssh" + echo " ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@255.255.255.255 'bash -s -- --args \"-u http://benchmark-server-vm:5000 -s streaminghub --channels 1 --streams 1\" --branch main --build-csproj 'perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj' --owner Cysharp --repo MagicOnion' < ./scripts/$(basename $0).sh" + echo ' echo $? # use $? to get the exit code of the remote command' +} + +while [ $# -gt 0 ]; do + case $1 in + # required + --build-csproj) _BUILD_CSPROJ=$2; shift 2; ;; + --repo) _REPO=$2; shift 2; ;; + # optional + --args) _ARGS=$2; shift 2; ;; + --branch) _BRANCH=$2; shift 2; ;; + --build-config) _BUILD_CONFIG=$2; shift 2; ;; + --env-settings) _ENV_SETTINGS=$2; shift 2; ;; + --owner) _OWNER=$2; shift 2; ;; + --help) usage; exit 1; ;; + *) shift ;; + esac +done + +function print() { + echo "" + echo "$*" +} + +# parameter setup +args="${_ARGS:=""}" +owner="${_OWNER:="Cysharp"}" +repo="${_REPO}" +branch="${_BRANCH:="main"}" +env_settings="${_ENV_SETTINGS:=""}" +build_config="${_BUILD_CONFIG:="Release"}" +build_csproj="${_BUILD_CSPROJ}" + +binary_name=$(basename "$(dirname "$build_csproj")") +publish_dir="artifacts/$binary_name" +clone_path="$HOME/github/$repo" +full_process_path="$clone_path/$publish_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 +export + +# git clone cysharp repo +print "# git clone $owner/$repo" +mkdir -p "$(dirname "$clone_path")" +if [[ ! -d "$clone_path" ]]; then + git clone "https://github.com/$owner/$repo" "$clone_path" +fi + +# list files +print "# List cloned files" +ls "$clone_path" + +# git pull +print "# git pull $branch" +pushd "$clone_path" + git switch "$branch" + git pull + git reset --hard HEAD +popd + +# 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" +if pgrep -f "$full_process_path"; then + pkill -f "$full_process_path" || true +fi + +# run dotnet app +print "# Run $full_process_path" +"$full_process_path" $args diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 2c11ea4ed..7b2e753fe 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -3,36 +3,72 @@ name: Benchmark on: push: branches: - - feature/perf + - benchmark env: BUILD_CONFIG: Release +permissions: + contents: read + id-token: write + jobs: - build: + benchmark: runs-on: ubuntu-latest timeout-minutes: 10 steps: - uses: actions/checkout@v4 - - uses: Cysharp/Actions/.github/actions/setup-dotnet@main - # build - - name: Build Client - run: dotnet publish -c ${{ env.BUILD_CONFIG }} -p:PublishSingleFile=true --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj -o ./perf/artifacts/PerformanceTest.Client - - name: Build Server - run: dotnet publish -c ${{ env.BUILD_CONFIG }} -p:PublishSingleFile=true --runtime linux-x64 --self-contained true ./perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj -o ./perf/artifacts/PerformanceTest.Server - # upload - - uses: Cysharp/Actions/.github/actions/upload-artifact@main + - name: Load secret + id: op-load-secret + uses: 1password/load-secrets-action@v2 with: - name: artifacts - path: ./perf/artifacts - if-no-files-found: error - retention-days: 1 - -# run: -# needs: [build] -# runs-on: ubuntu-latest -# timeout-minutes: 10 -# steps: -# - uses: actions/checkout@v4 -# # run -# # get result + export-env: false + env: + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }} + SSH_KEY: "op://GitHubActionsPublic/BENCHMARK_VM_SSH/private key" + AZURE_OIDC_CLIENTID: "op://GitHubActionsPublic/BENCHMARK_AZURE_OIDC/clientId" + AZURE_OIDC_TENANTID: "op://GitHubActionsPublic/BENCHMARK_AZURE_OIDC/tenantId" + AZURE_OIDC_SUBSCRIPTIONID: "op://GitHubActionsPublic/BENCHMARK_AZURE_OIDC/subscriptionId" + - name: Output SSH Key + run: | + mkdir -p ~/.ssh + echo "${{ steps.op-load-secret.outputs.SSH_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + - uses: azure/login@v2 + with: + client-id: ${{ steps.op-load-secret.outputs.AZURE_OIDC_CLIENTID }} + tenant-id: ${{ steps.op-load-secret.outputs.AZURE_OIDC_TENANTID }} + subscription-id: ${{ steps.op-load-secret.outputs.AZURE_OIDC_SUBSCRIPTIONID }} + - name: Start Benchmark VM + run: | + for vm in $(az vm list -d -g BenchmarkTest --query "[?powerState!='VM running'].name" -o tsv); do + az vm start --name $vm --resource-group BenchmarkTest + done + - name: Setup .NET on Benchmark VM + run: | + for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running'].publicIps" -o tsv); do + echo "::group::Install on $ip" + ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --dotnet-version 8.0' < ./scripts/dotnet_install.sh + echo "::endgroup::" + done + working-directory: ./.github + - name: Run Benchmark Server + run: | + for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='benchmark-server-vm'].publicIps" -o tsv); do + ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj" --env-settings "Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh & + done + # wait until server started + sleep 120s + working-directory: ./.github + - name: Run Benchmark Client + run: | + for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='benchmark-client-vm'].publicIps" -o tsv); do + ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --args "-u http://benchmark-server-vm:5000 -s streaminghub --channels 1 --streams 1" --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh + done + working-directory: ./.github + - name: Stop (Deallocate) Benchmark VM + if: always() + run: | + for vm in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running'].name" -o tsv); do + az vm deallocate --name $vm --resource-group BenchmarkTest --no-wait + done From 4abead838b2ab845cfe9a0bde0fe6c0d0730ef50 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:07:11 +0900 Subject: [PATCH 06/17] ci: use environment base OIDC --- .github/workflows/benchmark.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 7b2e753fe..20f6e311d 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,12 +1,15 @@ name: Benchmark on: - push: - branches: - - benchmark + workflow_dispatch: +# push: +# branches: +# - benchmark env: BUILD_CONFIG: Release + BENCHMARK_SERVER_NAME: benchmark-server-vm + BENCHMARK_CLIENT_NAME: benchmark-client-vm permissions: contents: read @@ -14,6 +17,7 @@ permissions: jobs: benchmark: + environment: benchmark # required for Azure login runs-on: ubuntu-latest timeout-minutes: 10 steps: @@ -54,7 +58,7 @@ jobs: working-directory: ./.github - name: Run Benchmark Server run: | - for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='benchmark-server-vm'].publicIps" -o tsv); do + for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='${{ env.BENCHMARK_SERVER_NAME }}'].publicIps" -o tsv); do ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj" --env-settings "Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh & done # wait until server started @@ -62,8 +66,8 @@ jobs: working-directory: ./.github - name: Run Benchmark Client run: | - for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='benchmark-client-vm'].publicIps" -o tsv); do - ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --args "-u http://benchmark-server-vm:5000 -s streaminghub --channels 1 --streams 1" --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh + for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='${{ env.BENCHMARK_CLIENT_NAME }}'].publicIps" -o tsv); do + ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --args "-u http://${{ env.BENCHMARK_SERVER_NAME }}:5000 -s streaminghub --channels 1 --streams 1" --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh done working-directory: ./.github - name: Stop (Deallocate) Benchmark VM From 713be8d596dc87eaa7d045002f79c0257afca015 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:50:53 +0900 Subject: [PATCH 07/17] ci: use reusable benchmark yaml --- .github/scripts/dotnet_install.sh | 56 ------------- .github/scripts/run_benchmark.sh | 133 ------------------------------ .github/workflows/benchmark.yml | 92 +++++++-------------- 3 files changed, 28 insertions(+), 253 deletions(-) delete mode 100644 .github/scripts/dotnet_install.sh delete mode 100644 .github/scripts/run_benchmark.sh diff --git a/.github/scripts/dotnet_install.sh b/.github/scripts/dotnet_install.sh deleted file mode 100644 index 606479da2..000000000 --- a/.github/scripts/dotnet_install.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# Install .NET SDK over ssh -# -# Sample usage: -# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.7.19 'bash -s -- --dotnet-version 8.0' < ./scripts/dotnet_install.sh -# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.1.54 'bash -s -- --dotnet-version 8.0' < ./scripts/dotnet_install.sh -# $ echo $? -# - -function usage { - echo "usage: $(basename $0) [options]" - echo "Options:" - echo " --dotnet-version string Version of dotnet sdk to install (default: 8.0)" - echo " --help Show this help message" - echo "" - echo "Examples:" - echo " 1. Install dotnet sdk version 8.0 over ssh" - echo " ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@255.255.255.255 'bash -s -- --dotnet-version 8.0' < ./scripts/$(basename $0).sh" - echo ' echo $? # use $? to get the exit code of the remote command' -} - -while [ $# -gt 0 ]; do - case $1 in - # optional - --dotnet-version) _DOTNET_VERSION=$2; shift 2; ;; - --help) usage; exit 1; ;; - *) shift ;; - esac -done - -function print() { - echo "" - echo "$*" -} - -dotnet_version="${_DOTNET_VERSION:="8.0"}" - -# show machine name -print "MACHINE_NAME: $(hostname)" - -# install dotnet (dotnet-install.sh must be downloaded before running script) -print "# Install dotnet sdk version: ${dotnet_version}" -sudo bash /opt/dotnet-install.sh --channel "${dotnet_version}" --install-dir /usr/share/dotnet - -# link dotnet to /usr/local/bin -print "# Link to /usr/local/bin/dotnet" -if [[ ! -h "/usr/local/bin/dotnet" ]]; then - sudo ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet -fi - -# show dotnet verison -print "# Show installed dotnet sdk versions" -echo "dotnet sdk versions (list): $(dotnet --list-sdks)" -echo "dotnet sdk version (default): $(dotnet --version)" diff --git a/.github/scripts/run_benchmark.sh b/.github/scripts/run_benchmark.sh deleted file mode 100644 index d30d6c3a9..000000000 --- a/.github/scripts/run_benchmark.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# git clone and run benchmark over ssh -# -# MagicOnion Server -# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.7.19 'bash -s -- --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj" --env-settings "Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh -# $ echo $? -# -# MagicOnion Client -# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@20.188.1.54 'bash -s -- --args "-u http://benchmark-server-vm:5000 -s streaminghub --channels 1 --streams 1" --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh -# $ echo $? - -function usage { - echo "usage: $(basename $0) --build-csproj --repo [options]" - echo "Required:" - echo " --build-csproj string Path to the csproj file to build" - echo " --repo string Repository name to clone" - echo "Options:" - echo " --args string Arguments to pass when running the built binary (default: \"\")" - echo " --branch string Branch name to checkout (default: main)" - echo " --build-config string Build configuration (default: Release)" - echo " --env-settings string Environment settings to set before running the binary, use ; to delinate multiple environments (default: \"\")" - echo " --owner string Repository owner (default: Cysharp)" - echo " --help Show this help message" - echo "" - echo "Examples:" - echo " 1. Run MagicOnion Benchmark Server over ssh" - echo " ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@255.255.255.255 'bash -s -- --branch main --build-csproj 'perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj' --env-settings \"Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;\" --owner Cysharp --repo MagicOnion' < ./scripts/$(basename $0).sh" - echo ' echo $? # use $? to get the exit code of the remote command' - echo "" - echo " 2. Run MagicOnion Benchmark Client over ssh" - echo " ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@255.255.255.255 'bash -s -- --args \"-u http://benchmark-server-vm:5000 -s streaminghub --channels 1 --streams 1\" --branch main --build-csproj 'perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj' --owner Cysharp --repo MagicOnion' < ./scripts/$(basename $0).sh" - echo ' echo $? # use $? to get the exit code of the remote command' -} - -while [ $# -gt 0 ]; do - case $1 in - # required - --build-csproj) _BUILD_CSPROJ=$2; shift 2; ;; - --repo) _REPO=$2; shift 2; ;; - # optional - --args) _ARGS=$2; shift 2; ;; - --branch) _BRANCH=$2; shift 2; ;; - --build-config) _BUILD_CONFIG=$2; shift 2; ;; - --env-settings) _ENV_SETTINGS=$2; shift 2; ;; - --owner) _OWNER=$2; shift 2; ;; - --help) usage; exit 1; ;; - *) shift ;; - esac -done - -function print() { - echo "" - echo "$*" -} - -# parameter setup -args="${_ARGS:=""}" -owner="${_OWNER:="Cysharp"}" -repo="${_REPO}" -branch="${_BRANCH:="main"}" -env_settings="${_ENV_SETTINGS:=""}" -build_config="${_BUILD_CONFIG:="Release"}" -build_csproj="${_BUILD_CSPROJ}" - -binary_name=$(basename "$(dirname "$build_csproj")") -publish_dir="artifacts/$binary_name" -clone_path="$HOME/github/$repo" -full_process_path="$clone_path/$publish_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 -export - -# git clone cysharp repo -print "# git clone $owner/$repo" -mkdir -p "$(dirname "$clone_path")" -if [[ ! -d "$clone_path" ]]; then - git clone "https://github.com/$owner/$repo" "$clone_path" -fi - -# list files -print "# List cloned files" -ls "$clone_path" - -# git pull -print "# git pull $branch" -pushd "$clone_path" - git switch "$branch" - git pull - git reset --hard HEAD -popd - -# 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" -if pgrep -f "$full_process_path"; then - pkill -f "$full_process_path" || true -fi - -# run dotnet app -print "# Run $full_process_path" -"$full_process_path" $args diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 20f6e311d..8883e248b 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,78 +1,42 @@ name: Benchmark on: + issue_comment: + types: [created] workflow_dispatch: -# push: -# branches: -# - benchmark - -env: - BUILD_CONFIG: Release - BENCHMARK_SERVER_NAME: benchmark-server-vm - BENCHMARK_CLIENT_NAME: benchmark-client-vm permissions: contents: read id-token: write jobs: - benchmark: - environment: benchmark # required for Azure login + prepare: + outputs: + branch: ${{ steps.get-branch.outputs.name }} runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 5 steps: - uses: actions/checkout@v4 - - name: Load secret - id: op-load-secret - uses: 1password/load-secrets-action@v2 - with: - export-env: false - env: - OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }} - SSH_KEY: "op://GitHubActionsPublic/BENCHMARK_VM_SSH/private key" - AZURE_OIDC_CLIENTID: "op://GitHubActionsPublic/BENCHMARK_AZURE_OIDC/clientId" - AZURE_OIDC_TENANTID: "op://GitHubActionsPublic/BENCHMARK_AZURE_OIDC/tenantId" - AZURE_OIDC_SUBSCRIPTIONID: "op://GitHubActionsPublic/BENCHMARK_AZURE_OIDC/subscriptionId" - - name: Output SSH Key - run: | - mkdir -p ~/.ssh - echo "${{ steps.op-load-secret.outputs.SSH_KEY }}" > ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - - uses: azure/login@v2 - with: - client-id: ${{ steps.op-load-secret.outputs.AZURE_OIDC_CLIENTID }} - tenant-id: ${{ steps.op-load-secret.outputs.AZURE_OIDC_TENANTID }} - subscription-id: ${{ steps.op-load-secret.outputs.AZURE_OIDC_SUBSCRIPTIONID }} - - name: Start Benchmark VM - run: | - for vm in $(az vm list -d -g BenchmarkTest --query "[?powerState!='VM running'].name" -o tsv); do - az vm start --name $vm --resource-group BenchmarkTest - done - - name: Setup .NET on Benchmark VM - run: | - for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running'].publicIps" -o tsv); do - echo "::group::Install on $ip" - ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --dotnet-version 8.0' < ./scripts/dotnet_install.sh - echo "::endgroup::" - done - working-directory: ./.github - - name: Run Benchmark Server + - name: Get branch name + id: get-branch run: | - for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='${{ env.BENCHMARK_SERVER_NAME }}'].publicIps" -o tsv); do - ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Server/PerformanceTest.Server.csproj" --env-settings "Kestrel__EndpointDefaults__Protocols=Http2;Kestrel__Endpoints__Grpc__Url=http://+:5000;" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh & - done - # wait until server started - sleep 120s - working-directory: ./.github - - name: Run Benchmark Client - run: | - for ip in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running' && name=='${{ env.BENCHMARK_CLIENT_NAME }}'].publicIps" -o tsv); do - ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@$ip 'bash -s -- --args "-u http://${{ env.BENCHMARK_SERVER_NAME }}:5000 -s streaminghub --channels 1 --streams 1" --branch main --build-csproj "perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" --owner Cysharp --repo MagicOnion' < ./scripts/run_benchmark.sh - done - working-directory: ./.github - - name: Stop (Deallocate) Benchmark VM - if: always() - run: | - for vm in $(az vm list -d -g BenchmarkTest --query "[?powerState=='VM running'].name" -o tsv); do - az vm deallocate --name $vm --resource-group BenchmarkTest --no-wait - done + if [[ "${{ github.event_name}}" == "issue_comment" && "${{ github.event.issue.pull_request.html_url }}" != "" ]]; then + # issue_comment (pull_request) + branch=$(gh pr view "${{ github.event.issue.pull_request.html_url }}" --json headRefName | jq -r ".headRefName") + echo "name=${branch}" | tee -a "$GITHUB_OUTPUT" + else + # workflow_dispatch or issue comment (issue) + echo "name=${{ github.ref_name }}" | tee -a "$GITHUB_OUTPUT" + fi + + # run benchmark + benchmark: + needs: [prepare] + uses: Cysharp/Actions/.github/workflows/benchmark.yaml@main + with: + 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" From 1749134cc34bc1f86b51eb042edb36e59a78bd03 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:09:06 +0900 Subject: [PATCH 08/17] tmp: trigger push to benchmark branch --- .github/workflows/benchmark.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 8883e248b..ce736e99f 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -4,6 +4,9 @@ on: issue_comment: types: [created] workflow_dispatch: + push: + branches: + - benchmark permissions: contents: read From e33636554896f6b39c06e4312149f69445df23c3 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:14:40 +0900 Subject: [PATCH 09/17] ci: inherit --- .github/workflows/benchmark.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index ce736e99f..b712b912c 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -43,3 +43,4 @@ jobs: 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" + secrets: inherit From 8d0e08705b09d60afc18dabe02ae45e124508688 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:17:10 +0900 Subject: [PATCH 10/17] ci: use string, not number --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index b712b912c..d2f6d7184 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -38,7 +38,7 @@ jobs: uses: Cysharp/Actions/.github/workflows/benchmark.yaml@main with: branch: ${{ needs.prepare.outputs.branch }} - dotnet-version: 8.0 + 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" From 04326b27bb2f6e31a86cadd8f2b2629746d8700f Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:07:36 +0900 Subject: [PATCH 11/17] chore: remove push trigger --- .github/workflows/benchmark.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index d2f6d7184..ee4b3a941 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -4,9 +4,6 @@ on: issue_comment: types: [created] workflow_dispatch: - push: - branches: - - benchmark permissions: contents: read @@ -28,7 +25,7 @@ jobs: branch=$(gh pr view "${{ github.event.issue.pull_request.html_url }}" --json headRefName | jq -r ".headRefName") echo "name=${branch}" | tee -a "$GITHUB_OUTPUT" else - # workflow_dispatch or issue comment (issue) + # workflow_dispatch or issue_comment (issue) echo "name=${{ github.ref_name }}" | tee -a "$GITHUB_OUTPUT" fi From 6e453d2b5e05da2dbf63fd7d845dbf6490c7b314 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:53:51 +0900 Subject: [PATCH 12/17] ci: change to pass script to run benchmark --- .github/scripts/run-bench-client.sh | 92 +++++++++++++++++++++++++++++ .github/scripts/run-bench-server.sh | 87 +++++++++++++++++++++++++++ .github/workflows/benchmark.yml | 7 ++- 3 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/run-bench-client.sh create mode 100644 .github/scripts/run-bench-server.sh diff --git a/.github/scripts/run-bench-client.sh b/.github/scripts/run-bench-client.sh new file mode 100644 index 000000000..a481f95bd --- /dev/null +++ b/.github/scripts/run-bench-client.sh @@ -0,0 +1,92 @@ +#!/bin/bash +set -euo pipefail + +# benchmark over ssh +# +# MagicOnion Client +# $ ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@4.215.237.255 '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 [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 diff --git a/.github/scripts/run-bench-server.sh b/.github/scripts/run-bench-server.sh new file mode 100644 index 000000000..9a30d0eae --- /dev/null +++ b/.github/scripts/run-bench-server.sh @@ -0,0 +1,87 @@ +#!/bin/bash +set -euo pipefail + +# benchmark over ssh +# +# MagicOnion Server +# ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/id_ed25519 azure-user@4.215.238.2 '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 diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index ee4b3a941..dd5fc013e 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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 From a2c25518f44861943a5ace477e99e8f6d60401ba Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:54:37 +0900 Subject: [PATCH 13/17] tmp: run benchmark --- .github/workflows/benchmark.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index dd5fc013e..bf7940256 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -4,6 +4,9 @@ on: issue_comment: types: [created] workflow_dispatch: + push: + branches: + - benchmark permissions: contents: read From e6db8e8ee99d8bf909491eaf614508ca431ec232 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 20:56:23 +0900 Subject: [PATCH 14/17] chore: server error detection --- .github/scripts/run-bench-client.sh | 1 + .github/scripts/run-bench-server.sh | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/scripts/run-bench-client.sh b/.github/scripts/run-bench-client.sh index a481f95bd..47f25038b 100644 --- a/.github/scripts/run-bench-client.sh +++ b/.github/scripts/run-bench-client.sh @@ -32,6 +32,7 @@ function print() { # parameter setup repo="MagicOnion" +build_config="Release" args="${_ARGS:=""}" build_csproj="perf/BenchmarkApp/PerformanceTest.Client/PerformanceTest.Client.csproj" env_settings="" diff --git a/.github/scripts/run-bench-server.sh b/.github/scripts/run-bench-server.sh index 9a30d0eae..170760ee3 100644 --- a/.github/scripts/run-bench-server.sh +++ b/.github/scripts/run-bench-server.sh @@ -37,6 +37,9 @@ clone_path="$HOME/github/$repo" output_dir="$clone_path/$publish_dir" full_process_path="$output_dir/$binary_name" +stdoutfile="stdout.log" +stderrfile="stderr.log" + # show machine name print "MACHINE_NAME: $(hostname)" @@ -82,6 +85,19 @@ popd # run dotnet app print "# Run $full_process_path" pushd "$output_dir" - # run background - "./$binary_name" & + # run background https://stackoverflow.com/questions/29142/getting-ssh-to-execute-a-command-in-the-background-on-target-machine + nohup "./$binary_name" > "${stdoutfile}" 2> "${stderrfile}" < /dev/null & + + # wait 10s will be enough to start the server or not + sleep 10s + + # output stdout + cat "${stdoutfile}" + + # output stderr + if [[ "$(stat -c%s "$stdoutFile")" -ne "0" ]]; then + echo "Error found when running the server." + cat "${stderrfile}" + exit 1 + fi popd From 4efeecf2b3e0be40a47a32e939c2cd7645866ddf Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:00:29 +0900 Subject: [PATCH 15/17] ci: fix typo --- .github/scripts/run-bench-server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/run-bench-server.sh b/.github/scripts/run-bench-server.sh index 170760ee3..271388b7b 100644 --- a/.github/scripts/run-bench-server.sh +++ b/.github/scripts/run-bench-server.sh @@ -95,7 +95,7 @@ pushd "$output_dir" cat "${stdoutfile}" # output stderr - if [[ "$(stat -c%s "$stdoutFile")" -ne "0" ]]; then + if [[ "$(stat -c%s "$stderrfile")" -ne "0" ]]; then echo "Error found when running the server." cat "${stderrfile}" exit 1 From 0fd913349b99e70137f5452b7f76b5422fac41d9 Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:54:37 +0900 Subject: [PATCH 16/17] Revert "tmp: run benchmark" This reverts commit a2c25518f44861943a5ace477e99e8f6d60401ba. --- .github/workflows/benchmark.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index bf7940256..dd5fc013e 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -4,9 +4,6 @@ on: issue_comment: types: [created] workflow_dispatch: - push: - branches: - - benchmark permissions: contents: read From ea2daef5339f7bc950060f8aaba77f2c7089168c Mon Sep 17 00:00:00 2001 From: Ikiru Yoshizaki <3856350+guitarrapc@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:04:34 +0900 Subject: [PATCH 17/17] ci: rename script --- .../scripts/{run-bench-client.sh => run-benchmark-client.sh} | 2 +- .../scripts/{run-bench-server.sh => run-benchmark-server.sh} | 0 .github/workflows/benchmark.yml | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename .github/scripts/{run-bench-client.sh => run-benchmark-client.sh} (98%) rename .github/scripts/{run-bench-server.sh => run-benchmark-server.sh} (100%) diff --git a/.github/scripts/run-bench-client.sh b/.github/scripts/run-benchmark-client.sh similarity index 98% rename from .github/scripts/run-bench-client.sh rename to .github/scripts/run-benchmark-client.sh index 47f25038b..d0d4dace0 100644 --- a/.github/scripts/run-bench-client.sh +++ b/.github/scripts/run-benchmark-client.sh @@ -86,7 +86,7 @@ ps -eo pid,cmd | while read -r pid cmd; do done # run dotnet app -print "# Run $full_process_path" +print "# Run $full_process_path $args" pushd "$output_dir" # run foreground "./$binary_name" $args diff --git a/.github/scripts/run-bench-server.sh b/.github/scripts/run-benchmark-server.sh similarity index 100% rename from .github/scripts/run-bench-server.sh rename to .github/scripts/run-benchmark-server.sh diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index dd5fc013e..ef00c6be7 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -37,8 +37,8 @@ jobs: branch: ${{ needs.prepare.outputs.branch }} dotnet-version: "8.0" environment: benchmark - client-benchmark-script-path: ".github/scripts/run-bench-client.sh" + client-benchmark-script-path: ".github/scripts/run-benchmark-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-path: ".github/scripts/run-benchmark-server.sh" server-benchmark-script-args: "" secrets: inherit