#!/usr/bin/env bash # Flow control, Part A: Dynamo 1.6.1 frontend + Mocker (4 workers) on the Mac, in a linux/arm64 Python 3.12 container # (ai-dynamo-runtime ships manylinux wheels only). Arms at 64 agent sessions, 6 min each: # D0 no policy YAML (no router queue: excess goes to the workers' own queues) # D1 two classes, equal DRR quantum (policy-D1.yaml) # D2 weighted 4096:512 for chat (policy-D2.yaml) # D3 D2 + x-dynamo-request-strict-priority: 1 on chat # For content/standalone/06-serving-in-production/07-serving-stack-flow-control (run 2026-10-31). Report the ordering # (chat share of completions, chat p95 TTFT) and the 429/529 counts, not absolute latencies: the Mocker's timing # model is its own, not the calibrated llm-d simulator. # CALIB=~/Workspace/flowctl/calib.json bash dynamo-run.sh # CALIB optional: only the KV block count is read # Run it with the site's dev server stopped, after or before kind-run.sh (not at the same time). Resumable per arm. set -u D=$(cd "$(dirname "$0")" && pwd) HARNESS=$D/../../../measure/flowctl_harness.py OUT=${OUT:-~/Workspace/flowctl/dynamo}; mkdir -p "$OUT/runs" ARMS=${ARMS:-"D0 D1 D2 D3"}; SESSIONS=${SESSIONS:-64} C=flowctl-dynamo; PORT=18000 MODEL=Qwen/Qwen3-8B; REV=b968826d9c46dd6066d109eabc6255188de91218 log() { echo "$(date '+%F %T') [dynamo] $*" | tee -a "$OUT/progress.txt"; } have() { [ -s "$1" ]; } KVB=7500 # KV blocks of 16 tokens per worker (about 120k tokens) unless the calibration says otherwise [ -n "${CALIB:-}" ] && have "$CALIB" && KVB=$(python3 -c "import json;print(json.load(open('$CALIB'))['kv_cache_blocks'] or 7500)") CHAT_RATE=${CHAT_RATE:-$( [ -n "${CALIB:-}" ] && have "$CALIB" \ && python3 -c "import json;c=json.load(open('$CALIB'));print(round(0.3*4*c['chat_capacity_per_replica_rps'],3))" || echo 1.0)} pgrep -f "[d]ev-guarded" >/dev/null && { log "ABORT: the site's dev server is running; stop it first"; exit 2; } if [ ! -x "$OUT/venv/bin/python" ]; then python3 -m venv "$OUT/venv" && "$OUT/venv/bin/pip" -q install httpx; fi # One long-lived container; Dynamo and the tokenizer files (no weights: the Mocker does not load any) installed once. if ! docker ps --format '{{.Names}}' | grep -qx $C; then docker rm -f $C >/dev/null 2>&1 docker run -d --name $C --platform linux/arm64 -p $PORT:8000 -v "$D":/cfg:ro -v "$OUT":/out python:3.12-slim \ sleep infinity > /dev/null || { log "ABORT: container start failed"; exit 1; } fi if ! docker exec $C python -c "import dynamo" 2>/dev/null; then docker exec $C bash -c "apt-get -qq update && apt-get -qq install -y procps" > "$OUT/pip.log" 2>&1 # pkill docker exec $C pip -q install "ai-dynamo==1.6.1" huggingface_hub >> "$OUT/pip.log" 2>&1 || { log "ABORT: pip install failed"; exit 1; } docker exec $C python -c " from huggingface_hub import snapshot_download snapshot_download('$MODEL', revision='$REV', allow_patterns=['*.json', '*.txt'], local_dir='/models/qwen3-8b-tok')" \ >> "$OUT/pip.log" 2>&1 || { log "ABORT: tokenizer download failed"; exit 1; } log "installed: $(docker exec $C pip show ai-dynamo ai-dynamo-runtime 2>/dev/null | grep -E '^(Name|Version)' | tr '\n' ' ')" fi arm() { local a=$1 policy="" strict="" have "$OUT/runs/$a/summary.json" && { log "skip $a (exists)"; return 0; } case $a in D1) policy="--router-policy-config /cfg/policy-D1.yaml";; D2|D3) policy="--router-policy-config /cfg/policy-D2.yaml";; esac [ $a = D3 ] && strict="--dynamo-strict-chat" docker exec $C bash -c 'pkill -f "dynamo\.(mocker|frontend)"; sleep 3; rm -rf /tmp/dyn-kv' 2>/dev/null docker exec -d $C bash -c "export DYN_FILE_KV=/tmp/dyn-kv python -m dynamo.mocker --model-path /models/qwen3-8b-tok --model-name $MODEL --discovery-backend file \ --num-workers 4 --max-num-seqs 16 --max-num-batched-tokens 8192 --block-size 16 --num-gpu-blocks-override $KVB \ --speedup-ratio 1 > /out/mocker-$a.log 2>&1 & sleep 5 python -m dynamo.frontend --http-port 8000 --discovery-backend file --router-mode kv --load-aware $policy \ > /out/frontend-$a.log 2>&1" local i for i in $(seq 1 60); do curl -sf -m 3 localhost:$PORT/v1/models 2>/dev/null | grep -q "$MODEL" && break; sleep 5; done curl -sf -m 3 localhost:$PORT/v1/models | grep -q "$MODEL" || { log "FAILED $a: frontend has no model after 5 min"; return 1; } log "$a: $SESSIONS sessions, chat $CHAT_RATE req/s, ${policy:-no policy} $strict" "$OUT/venv/bin/python" "$HARNESS" --base-url http://127.0.0.1:$PORT --model $MODEL --out "$OUT/runs" --label $a \ --sessions $SESSIONS --agent-cap 30000 --chat-rate $CHAT_RATE --headers dynamo $strict \ --scrape http://127.0.0.1:$PORT/metrics > "$OUT/runs/harness-$a.log" 2>&1 log "$a exit $?: $(grep -E '^\[' "$OUT/runs/harness-$a.log" | tail -2 | tr '\n' ' ' | cut -c1-300)" } for a in $ARMS; do arm $a; done docker exec $C bash -c 'pkill -f "dynamo\.(mocker|frontend)"' 2>/dev/null log "ALL DONE (Dynamo); container $C left running (docker rm -f $C to remove)"