270 lines
9.3 KiB
YAML
270 lines
9.3 KiB
YAML
name: PR Benchmark (SMG Components)
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
paths:
|
|
- "sgl-model-gateway/**"
|
|
pull_request:
|
|
branches: [ main ]
|
|
paths:
|
|
- "sgl-model-gateway/**"
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: pr-benchmark-rust-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
RUSTC_WRAPPER: sccache
|
|
SCCACHE_GHA_ENABLED: "true"
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
issues: write
|
|
|
|
jobs:
|
|
benchmark-compile-check:
|
|
name: Benchmark Compilation Check
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
bash scripts/ci/ci_install_rust.sh
|
|
|
|
- name: Configure sccache
|
|
uses: mozilla-actions/sccache-action@v0.0.9
|
|
with:
|
|
version: "v0.12.0"
|
|
disable_annotations: true
|
|
|
|
- name: Rust cache
|
|
uses: Swatinem/rust-cache@v2
|
|
with:
|
|
workspaces: sgl-model-gateway
|
|
shared-key: "rust-cache"
|
|
save-if: true
|
|
cache-all-crates: true
|
|
cache-on-failure: true
|
|
|
|
- name: Check benchmarks compile
|
|
run: |
|
|
source "$HOME/.cargo/env"
|
|
cd sgl-model-gateway/
|
|
cargo check --benches
|
|
|
|
- name: Show sccache stats
|
|
if: always()
|
|
run: sccache --show-stats
|
|
|
|
benchmark:
|
|
name: Benchmark - ${{ matrix.name }}
|
|
if: |
|
|
github.repository == 'sgl-project/sglang' &&
|
|
(github.event_name == 'push' ||
|
|
github.event_name == 'workflow_dispatch' ||
|
|
(contains(github.event.pull_request.labels.*.name, 'router-benchmark') &&
|
|
contains(github.event.pull_request.labels.*.name, 'run-ci')))
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- name: Request Processing
|
|
bench_name: request_processing
|
|
bench_args: "benchmark_summary --exact"
|
|
runner: ubuntu-latest
|
|
sccache_version: "v0.12.0"
|
|
artifact_name: request-processing-results
|
|
artifact_path: criterion/benchmark_summary/
|
|
- name: Tokenizer
|
|
bench_name: tokenizer_benchmark
|
|
bench_args: ""
|
|
runner: ubuntu-latest
|
|
sccache_version: "v0.12.0"
|
|
artifact_name: tokenizer-results
|
|
artifact_path: criterion/tokenizer*/
|
|
- name: Tool Parser
|
|
bench_name: tool_parser_benchmark
|
|
bench_args: ""
|
|
runner: ubuntu-latest
|
|
sccache_version: "v0.12.0"
|
|
artifact_name: tool-parser-results
|
|
artifact_path: criterion/tool_parser*/
|
|
- name: Tree
|
|
bench_name: tree_benchmark
|
|
bench_args: "benchmark_summary"
|
|
runner: 4-gpu-a10
|
|
sccache_version: "v0.10.0"
|
|
artifact_name: tree-results
|
|
artifact_path: criterion/benchmark_summary*/
|
|
runs-on: ${{ matrix.runner }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 100
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
bash scripts/ci/ci_install_rust.sh
|
|
|
|
- name: Configure sccache
|
|
uses: mozilla-actions/sccache-action@v0.0.9
|
|
with:
|
|
version: ${{ matrix.sccache_version }}
|
|
disable_annotations: true
|
|
|
|
- name: Rust cache
|
|
uses: Swatinem/rust-cache@v2
|
|
with:
|
|
workspaces: sgl-model-gateway
|
|
shared-key: "rust-cache"
|
|
cache-all-crates: true
|
|
cache-on-failure: true
|
|
save-if: true
|
|
|
|
- name: Run benchmark
|
|
timeout-minutes: 30
|
|
run: |
|
|
source "$HOME/.cargo/env"
|
|
cd sgl-model-gateway/
|
|
if command -v sccache &> /dev/null; then
|
|
echo "Testing sccache availability..."
|
|
export RUSTC_WRAPPER=sccache
|
|
export SCCACHE_GHA_ENABLED="true"
|
|
if sccache --start-server 2>/dev/null && sccache --show-stats 2>/dev/null; then
|
|
echo "sccache is working, using it for compilation"
|
|
else
|
|
echo "sccache failed to start, falling back to regular cargo"
|
|
unset RUSTC_WRAPPER
|
|
unset SCCACHE_GHA_ENABLED
|
|
fi
|
|
else
|
|
echo "sccache not available, using regular cargo"
|
|
fi
|
|
cargo bench --bench ${{ matrix.bench_name }} -- ${{ matrix.bench_args }} 2>&1 | tee benchmark_output.txt
|
|
|
|
- name: Upload benchmark results
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ matrix.artifact_name }}-${{ github.sha }}
|
|
path: |
|
|
sgl-model-gateway/target/${{ matrix.artifact_path }}
|
|
sgl-model-gateway/benchmark_output.txt
|
|
retention-days: 30
|
|
|
|
- name: Show sccache stats
|
|
if: always()
|
|
run: sccache --show-stats
|
|
|
|
benchmark-summary:
|
|
name: Benchmark Summary
|
|
needs: [benchmark]
|
|
if: always() && (github.repository == 'sgl-project/sglang' || github.event_name == 'pull_request')
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Download all benchmark results
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: '*-results-${{ github.sha }}'
|
|
path: benchmark-results
|
|
|
|
- name: Generate summary
|
|
run: |
|
|
echo "## 🚀 Benchmark Results Summary" > summary.md
|
|
echo "" >> summary.md
|
|
|
|
echo "### Request Processing" >> summary.md
|
|
REQ_DIR="benchmark-results/request-processing-results-${{ github.sha }}"
|
|
if [ -d "$REQ_DIR" ]; then
|
|
echo "✅ **Completed**" >> summary.md
|
|
if [ -f "$REQ_DIR/benchmark_output.txt" ]; then
|
|
echo "" >> summary.md
|
|
echo "<details>" >> summary.md
|
|
echo "<summary>View Results</summary>" >> summary.md
|
|
echo "" >> summary.md
|
|
echo '```' >> summary.md
|
|
grep -A 100 "SGLang Model Gateway\|Quick Performance\|Performance Insights" "$REQ_DIR/benchmark_output.txt" | head -50 >> summary.md || cat "$REQ_DIR/benchmark_output.txt" | tail -60 >> summary.md
|
|
echo '```' >> summary.md
|
|
echo "</details>" >> summary.md
|
|
fi
|
|
else
|
|
echo "❌ Failed or skipped" >> summary.md
|
|
fi
|
|
echo "" >> summary.md
|
|
|
|
echo "### Tokenizer" >> summary.md
|
|
TOK_DIR="benchmark-results/tokenizer-results-${{ github.sha }}"
|
|
if [ -d "$TOK_DIR" ]; then
|
|
echo "✅ **Completed**" >> summary.md
|
|
if [ -f "$TOK_DIR/benchmark_output.txt" ]; then
|
|
echo "" >> summary.md
|
|
echo "<details>" >> summary.md
|
|
echo "<summary>View Results</summary>" >> summary.md
|
|
echo "" >> summary.md
|
|
echo '```' >> summary.md
|
|
grep -A 200 "TOKENIZER BENCHMARK SUMMARY\|ENCODING THROUGHPUT" "$TOK_DIR/benchmark_output.txt" | head -100 >> summary.md || cat "$TOK_DIR/benchmark_output.txt" | tail -100 >> summary.md
|
|
echo '```' >> summary.md
|
|
echo "</details>" >> summary.md
|
|
fi
|
|
else
|
|
echo "❌ Failed or skipped" >> summary.md
|
|
fi
|
|
echo "" >> summary.md
|
|
|
|
echo "### Tool Parser" >> summary.md
|
|
TOOL_DIR="benchmark-results/tool-parser-results-${{ github.sha }}"
|
|
if [ -d "$TOOL_DIR" ]; then
|
|
echo "✅ **Completed**" >> summary.md
|
|
if [ -f "$TOOL_DIR/benchmark_output.txt" ]; then
|
|
echo "" >> summary.md
|
|
echo "<details>" >> summary.md
|
|
echo "<summary>View Results</summary>" >> summary.md
|
|
echo "" >> summary.md
|
|
echo '```' >> summary.md
|
|
grep -A 200 "TOOL PARSER BENCHMARK SUMMARY\|REGISTRY OPERATIONS\|COMPLETE PARSING" "$TOOL_DIR/benchmark_output.txt" | head -100 >> summary.md || cat "$TOOL_DIR/benchmark_output.txt" | tail -100 >> summary.md
|
|
echo '```' >> summary.md
|
|
echo "</details>" >> summary.md
|
|
fi
|
|
else
|
|
echo "❌ Failed or skipped" >> summary.md
|
|
fi
|
|
echo "" >> summary.md
|
|
|
|
echo "### Radix Tree (Cache-Aware Routing)" >> summary.md
|
|
TREE_DIR="benchmark-results/tree-results-${{ github.sha }}"
|
|
if [ -d "$TREE_DIR" ]; then
|
|
echo "✅ **Completed**" >> summary.md
|
|
if [ -f "$TREE_DIR/benchmark_output.txt" ]; then
|
|
echo "" >> summary.md
|
|
echo "<details>" >> summary.md
|
|
echo "<summary>View Results</summary>" >> summary.md
|
|
echo "" >> summary.md
|
|
echo '```' >> summary.md
|
|
grep -A 50 "RADIX TREE BENCHMARK SUMMARY" "$TREE_DIR/benchmark_output.txt" | head -50 >> summary.md || cat "$TREE_DIR/benchmark_output.txt" | tail -50 >> summary.md
|
|
echo '```' >> summary.md
|
|
echo "</details>" >> summary.md
|
|
fi
|
|
else
|
|
echo "❌ Failed or skipped" >> summary.md
|
|
fi
|
|
|
|
echo "" >> summary.md
|
|
echo "---" >> summary.md
|
|
echo "_Generated at $(date -u '+%Y-%m-%d %H:%M:%S UTC')_" >> summary.md
|
|
|
|
cat summary.md
|
|
cat summary.md >> $GITHUB_STEP_SUMMARY
|
|
|
|
- name: Upload summary
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: benchmark-summary-${{ github.sha }}
|
|
path: summary.md
|
|
retention-days: 30
|