[router] enable sccache in ci and local build (#10099)
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
# SGLang Router Makefile
|
||||
# Provides convenient shortcuts for common development tasks
|
||||
|
||||
# Check if sccache is available and set RUSTC_WRAPPER accordingly
|
||||
SCCACHE := $(shell which sccache 2>/dev/null)
|
||||
ifdef SCCACHE
|
||||
export RUSTC_WRAPPER := $(SCCACHE)
|
||||
$(info Using sccache for compilation caching)
|
||||
else
|
||||
$(info sccache not found. Install it for faster builds: cargo install sccache)
|
||||
endif
|
||||
|
||||
.PHONY: help bench bench-quick bench-baseline bench-compare test build clean
|
||||
|
||||
help: ## Show this help message
|
||||
@@ -90,3 +99,33 @@ perf-monitor: ## Run continuous performance monitoring
|
||||
else \
|
||||
echo "Warning: 'watch' command not found. Install it or run 'make bench-quick' manually."; \
|
||||
fi
|
||||
|
||||
# sccache management targets
|
||||
setup-sccache: ## Install and configure sccache
|
||||
@echo "Setting up sccache..."
|
||||
@./scripts/setup-sccache.sh
|
||||
|
||||
sccache-stats: ## Show sccache statistics
|
||||
@if [ -n "$(SCCACHE)" ]; then \
|
||||
echo "sccache statistics:"; \
|
||||
sccache -s; \
|
||||
else \
|
||||
echo "sccache not installed. Run 'make setup-sccache' to install it."; \
|
||||
fi
|
||||
|
||||
sccache-clean: ## Clear sccache cache
|
||||
@if [ -n "$(SCCACHE)" ]; then \
|
||||
echo "Clearing sccache cache..."; \
|
||||
sccache -C; \
|
||||
echo "sccache cache cleared"; \
|
||||
else \
|
||||
echo "sccache not installed"; \
|
||||
fi
|
||||
|
||||
sccache-stop: ## Stop the sccache server
|
||||
@if [ -n "$(SCCACHE)" ]; then \
|
||||
echo "Stopping sccache server..."; \
|
||||
sccache --stop-server || true; \
|
||||
else \
|
||||
echo "sccache not installed"; \
|
||||
fi
|
||||
|
||||
84
sgl-router/scripts/setup-sccache.sh
Executable file
84
sgl-router/scripts/setup-sccache.sh
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
echo "Setting up sccache for faster Rust compilation..."
|
||||
|
||||
has_cmd() { command -v "$1" >/dev/null 2>&1; }
|
||||
|
||||
install_sccache() {
|
||||
echo "sccache not found."
|
||||
if [[ "${AUTO_INSTALL:-0}" != "1" ]]; then
|
||||
read -r -p "Install sccache now? [y/N] " response
|
||||
response=${response:-N}
|
||||
if [[ ! "$response" =~ ^[Yy]$ ]]; then
|
||||
echo "Skipping installation. Please install sccache manually:"
|
||||
echo " cargo install sccache"
|
||||
echo " or"
|
||||
echo " brew install sccache (macOS)"
|
||||
echo " or"
|
||||
echo " sudo apt-get install -y sccache (Debian/Ubuntu)"
|
||||
echo " or"
|
||||
echo " sudo dnf install -y sccache (RHEL/Fedora)"
|
||||
echo " or"
|
||||
echo " sudo pacman -S sccache (Arch)"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if has_cmd cargo; then
|
||||
echo "Installing via cargo..."
|
||||
cargo install sccache --locked
|
||||
elif has_cmd brew; then
|
||||
echo "Installing via Homebrew..."
|
||||
brew install sccache
|
||||
elif has_cmd apt-get; then
|
||||
echo "Installing via apt-get..."
|
||||
sudo apt-get update -y && sudo apt-get install -y sccache
|
||||
elif has_cmd dnf; then
|
||||
echo "Installing via dnf..."
|
||||
sudo dnf install -y sccache
|
||||
elif has_cmd pacman; then
|
||||
echo "Installing via pacman..."
|
||||
sudo pacman -S --noconfirm sccache
|
||||
else
|
||||
echo "No supported package manager detected. Install manually:"
|
||||
echo " cargo install sccache"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if ! has_cmd sccache; then
|
||||
install_sccache
|
||||
fi
|
||||
|
||||
echo "Configuring sccache..."
|
||||
|
||||
export SCCACHE_CACHE_SIZE="${SCCACHE_CACHE_SIZE:-10G}"
|
||||
export SCCACHE_STATS="${SCCACHE_STATS:-1}"
|
||||
|
||||
# Set RUSTC_WRAPPER to sccache for this shell session.
|
||||
SCCACHE_BIN="$(command -v sccache)"
|
||||
if [[ -z "${SCCACHE_BIN}" ]]; then
|
||||
echo "Unexpected: sccache still not on PATH after install. Check your environment."
|
||||
exit 1
|
||||
fi
|
||||
export RUSTC_WRAPPER="${SCCACHE_BIN}"
|
||||
|
||||
echo "sccache version: $(sccache --version || echo 'unknown')"
|
||||
echo "Current cache stats:"
|
||||
sccache -s || true
|
||||
|
||||
# If script not sourced, remind user about persistence.
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
echo
|
||||
echo "Environment variables exported for this process only."
|
||||
echo "To persist, add to your shell profile (e.g., ~/.bashrc or ~/.zshrc):"
|
||||
echo ' export RUSTC_WRAPPER="$(command -v sccache 2>/dev/null || echo "")"'
|
||||
echo ' export SCCACHE_CACHE_SIZE="10G"'
|
||||
# echo ' export SCCACHE_DIR="$HOME/.cache/sccache"'
|
||||
echo ' export SCCACHE_STATS="1"'
|
||||
fi
|
||||
|
||||
echo "sccache is configured."
|
||||
@@ -986,7 +986,7 @@ pub fn start_health_checker(
|
||||
|
||||
// Periodically reset load counters to prevent drift
|
||||
// Only do this when we believe all workers should be idle
|
||||
if check_count.is_multiple_of(LOAD_RESET_INTERVAL) {
|
||||
if check_count % LOAD_RESET_INTERVAL == 0 {
|
||||
let max_load = workers_to_check.iter().map(|w| w.load()).max().unwrap_or(0);
|
||||
// Only reset if load appears to be very low (likely drift)
|
||||
if max_load <= 2 {
|
||||
|
||||
Reference in New Issue
Block a user