todowindy/scripts/measure_ingest.sh

22 lines
968 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
BASE=${BASE:-http://127.0.0.1:8080}
TEXT=${TEXT:-"明天早上提醒我买菜并安排30分钟写周报"}
TZ=${TZ:-Asia/Shanghai}
N=${N:-3}
printf 'run,total_ms,llm_ms,schedule_ms,db_ms,plan_record_ms\n'
for i in $(seq 1 "$N"); do
now=$(date -u +%Y-%m-%dT%H:%M:%SZ)
body=$(jq -n --arg t "$TEXT" --arg tz "$TZ" --arg n "$now" '{text:$t, timezone:$tz, now:$n}')
resp=$(curl -sS -m 300 -X POST "$BASE/ingest?debug=1" -H 'Content-Type: application/json' -d "$body")
# extract timings
total=$(jq -r '.timings.total_ms' <<<"$resp" 2>/dev/null || echo 0)
llm=$(jq -r '.timings.llm_ms' <<<"$resp" 2>/dev/null || echo 0)
sched=$(jq -r '.timings.schedule_ms' <<<"$resp" 2>/dev/null || echo 0)
db=$(jq -r '.timings.db_ms' <<<"$resp" 2>/dev/null || echo 0)
plan=$(jq -r '.timings.plan_record_ms' <<<"$resp" 2>/dev/null || echo 0)
printf '%d,%s,%s,%s,%s,%s\n' "$i" "$total" "$llm" "$sched" "$db" "$plan"
sleep 1
done