-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[ci] add router benchmark script and CI #7498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| name: PR Benchmark (Rust Router) | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| paths: | ||
| - "sgl-router/**" | ||
| pull_request: | ||
| branches: [ main ] | ||
| paths: | ||
| - "sgl-router/**" | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: pr-benchmark-rust-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| issues: write | ||
| jobs: | ||
| benchmark-router: | ||
| if: github.repository == 'sgl-project/sglang' || github.event_name == 'pull_request' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Fetch enough history for baseline comparison | ||
| fetch-depth: 100 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| bash scripts/ci_install_rust.sh | ||
|
|
||
| - name: Cache Rust dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cargo/bin/ | ||
| ~/.cargo/registry/index/ | ||
| ~/.cargo/registry/cache/ | ||
| ~/.cargo/git/db/ | ||
| sgl-router/target/ | ||
| key: ${{ runner.os }}-cargo-${{ hashFiles('sgl-router/Cargo.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-cargo- | ||
|
|
||
| - name: Build router in release mode | ||
| run: | | ||
| source "$HOME/.cargo/env" | ||
| cd sgl-router/ | ||
| cargo build --release | ||
|
|
||
| - name: Run quick benchmarks | ||
| timeout-minutes: 15 | ||
| run: | | ||
| source "$HOME/.cargo/env" | ||
| cd sgl-router/ | ||
| # Run quick benchmarks for PR validation using Python script | ||
| python3 scripts/run_benchmarks.py --quick --validate-thresholds --save-results | ||
|
|
||
| - name: Upload benchmark results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: benchmark-results-${{ github.sha }} | ||
| path: | | ||
| sgl-router/target/criterion/ | ||
| retention-days: 30 | ||
|
|
||
| - name: Post benchmark results as PR comment | ||
| if: github.event_name == 'pull_request' | ||
| run: | | ||
| cd sgl-router/ | ||
| # Use Python script to post benchmark comment | ||
| python3 scripts/post_benchmark_comment.py \ | ||
| --pr-number ${{ github.event.number }} \ | ||
| --commit-sha ${{ github.sha }} \ | ||
| --results-file benchmark_results.env | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| benchmark-integration-test: | ||
| if: github.repository == 'sgl-project/sglang' || github.event_name == 'pull_request' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| bash scripts/ci_install_rust.sh | ||
|
|
||
| - name: Cache Rust dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/.cargo/bin/ | ||
| ~/.cargo/registry/index/ | ||
| ~/.cargo/registry/cache/ | ||
| ~/.cargo/git/db/ | ||
| sgl-router/target/ | ||
| key: ${{ runner.os }}-cargo-${{ hashFiles('sgl-router/Cargo.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-cargo- | ||
|
|
||
| - name: Run benchmark integration tests | ||
| timeout-minutes: 10 | ||
| run: | | ||
| source "$HOME/.cargo/env" | ||
| cd sgl-router/ | ||
| # Run integration tests to ensure benchmark code compiles and works | ||
| cargo test --test benchmark_integration | ||
|
|
||
| - name: Verify benchmark compilation | ||
| run: | | ||
| source "$HOME/.cargo/env" | ||
| cd sgl-router/ | ||
| # Ensure all benchmarks compile without running them | ||
| cargo check --benches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # SGLang Router Makefile | ||
| # Provides convenient shortcuts for common development tasks | ||
|
|
||
| .PHONY: help bench bench-quick bench-baseline bench-compare test build clean | ||
|
|
||
| help: ## Show this help message | ||
| @echo "SGLang Router Development Commands" | ||
| @echo "==================================" | ||
| @echo "" | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
| @echo "" | ||
|
|
||
| build: ## Build the project in release mode | ||
| @echo "Building SGLang Router..." | ||
| @cargo build --release | ||
|
|
||
| test: ## Run all tests | ||
| @echo "Running tests..." | ||
| @cargo test | ||
|
|
||
| bench: ## Run full benchmark suite | ||
| @echo "Running full benchmarks..." | ||
| @python3 scripts/run_benchmarks.py | ||
|
|
||
| bench-quick: ## Run quick benchmarks only | ||
| @echo "Running quick benchmarks..." | ||
| @python3 scripts/run_benchmarks.py --quick | ||
|
|
||
| bench-baseline: ## Save current performance as baseline | ||
| @echo "Saving performance baseline..." | ||
| @python3 scripts/run_benchmarks.py --save-baseline main | ||
|
|
||
| bench-compare: ## Compare with saved baseline | ||
| @echo "Comparing with baseline..." | ||
| @python3 scripts/run_benchmarks.py --compare-baseline main | ||
|
|
||
| bench-ci: ## Run benchmarks suitable for CI (quick mode) | ||
| @echo "Running CI benchmarks..." | ||
| @python3 scripts/run_benchmarks.py --quick | ||
|
|
||
| clean: ## Clean build artifacts | ||
| @echo "Cleaning build artifacts..." | ||
| @cargo clean | ||
|
|
||
| docs: ## Generate and open documentation | ||
| @echo "Generating documentation..." | ||
| @cargo doc --open | ||
|
|
||
| check: ## Run cargo check and clippy | ||
| @echo "Running cargo check..." | ||
| @cargo check | ||
| @echo "Running clippy..." | ||
| @cargo clippy | ||
|
|
||
| fmt: ## Format code with rustfmt | ||
| @echo "Formatting code..." | ||
| @cargo fmt | ||
|
|
||
| # Development workflow shortcuts | ||
| dev-setup: build test ## Set up development environment | ||
| @echo "Development environment ready!" | ||
|
|
||
| pre-commit: fmt check test bench-quick ## Run pre-commit checks | ||
| @echo "Pre-commit checks passed!" | ||
|
|
||
| # Benchmark analysis shortcuts | ||
| bench-report: ## Open benchmark HTML report | ||
| @if [ -f "target/criterion/request_processing/report/index.html" ]; then \ | ||
| echo "Opening benchmark report..."; \ | ||
| if command -v xdg-open >/dev/null 2>&1; then \ | ||
| xdg-open target/criterion/request_processing/report/index.html; \ | ||
| elif command -v open >/dev/null 2>&1; then \ | ||
| open target/criterion/request_processing/report/index.html; \ | ||
| else \ | ||
| echo "Please open target/criterion/request_processing/report/index.html in your browser"; \ | ||
| fi \ | ||
| else \ | ||
| echo "No benchmark report found. Run 'make bench' first."; \ | ||
| fi | ||
|
|
||
| bench-clean: ## Clean benchmark results | ||
| @echo "Cleaning benchmark results..." | ||
| @rm -rf target/criterion | ||
|
|
||
| # Performance monitoring | ||
| perf-monitor: ## Run continuous performance monitoring | ||
| @echo "Starting performance monitoring..." | ||
| @if command -v watch >/dev/null 2>&1; then \ | ||
| watch -n 300 'make bench-quick'; \ | ||
| else \ | ||
| echo "Warning: 'watch' command not found. Install it or run 'make bench-quick' manually."; \ | ||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.