Copilot commented on code in PR #123:
URL: 
https://github.com/apache/dubbo-go-pixiu-samples/pull/123#discussion_r2831751885


##########
ai/kvcache/mock/run.sh:
##########
@@ -0,0 +1,197 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_CONFIG="${PIXIU_CONFIG:-${SCRIPT_DIR}/pixiu/conf.yaml}"
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:18888}";
+LMCACHE_ADMIN="${LMCACHE_ADMIN:-http://127.0.0.1:18081}";
+ENGINE_A_ADMIN="${ENGINE_A_ADMIN:-http://127.0.0.1:18091}";
+ENGINE_B_ADMIN="${ENGINE_B_ADMIN:-http://127.0.0.1:18092}";
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"
+GO_CACHE_DIR="${GO_CACHE_DIR:-/tmp/go-build-cache}"
+GO_MOD_CACHE_DIR="${GO_MOD_CACHE_DIR:-/tmp/go-mod-cache}"
+export NO_PROXY="${NO_PROXY:-127.0.0.1,localhost}"
+export no_proxy="${no_proxy:-127.0.0.1,localhost}"
+
+WORK_DIR="$(mktemp -d /tmp/kvcache-mock-XXXXXX)"
+CONTROLLER_LOG="${WORK_DIR}/mock_controller.log"
+ENGINE_A_LOG="${WORK_DIR}/mock_engine_a.log"
+ENGINE_B_LOG="${WORK_DIR}/mock_engine_b.log"
+PIXIU_LOG="${WORK_DIR}/pixiu.log"
+
+CONTROLLER_PID=""
+ENGINE_A_PID=""
+ENGINE_B_PID=""
+PIXIU_PID=""
+
+REQ_BODY='{"model":"mock-model","messages":[{"role":"user","content":"please 
explain kv cache routing"}]}'
+
+cleanup() {
+  set +e
+  if [[ -n "${PIXIU_PID}" ]] && kill -0 "${PIXIU_PID}" >/dev/null 2>&1; then
+    kill "${PIXIU_PID}" >/dev/null 2>&1
+    wait "${PIXIU_PID}" >/dev/null 2>&1
+  fi
+  if [[ -n "${CONTROLLER_PID}" ]] && kill -0 "${CONTROLLER_PID}" >/dev/null 
2>&1; then
+    kill "${CONTROLLER_PID}" >/dev/null 2>&1
+    wait "${CONTROLLER_PID}" >/dev/null 2>&1
+  fi
+  if [[ -n "${ENGINE_A_PID}" ]] && kill -0 "${ENGINE_A_PID}" >/dev/null 2>&1; 
then
+    kill "${ENGINE_A_PID}" >/dev/null 2>&1
+    wait "${ENGINE_A_PID}" >/dev/null 2>&1
+  fi
+  if [[ -n "${ENGINE_B_PID}" ]] && kill -0 "${ENGINE_B_PID}" >/dev/null 2>&1; 
then
+    kill "${ENGINE_B_PID}" >/dev/null 2>&1
+    wait "${ENGINE_B_PID}" >/dev/null 2>&1
+  fi

Review Comment:
   WORK_DIR is created but never removed in cleanup(). This will leave logs/tmp 
dirs under /tmp on every run; consider removing WORK_DIR in cleanup (optionally 
gated by a KEEP_WORKDIR flag for debugging).
   ```suggestion
     fi
     if [[ "${KEEP_WORKDIR:-0}" != "1" ]] && [[ -n "${WORK_DIR:-}" ]] && [[ -d 
"${WORK_DIR}" ]]; then
       rm -rf "${WORK_DIR}"
     fi
   ```



##########
ai/kvcache/real-engine/test/pixiu_test.go:
##########
@@ -0,0 +1,87 @@
+package test
+
+import (
+       "bytes"
+       "encoding/json"
+       "io"
+       "net/http"
+       "os"
+       "testing"
+)
+
+const defaultBYOEPixiuURL = "http://127.0.0.1:18889";
+
+func envOrDefault(key string, fallback string) string {
+       if v := os.Getenv(key); v != "" {
+               return v
+       }
+       return fallback
+}
+
+func checkPixiuAvailable(url string) bool {
+       payload := map[string]any{
+               "model":  envOrDefault("MODEL_NAME", "Qwen2.5-3B-Instruct"),
+               "prompt": "kvcache byoe availability probe",
+       }
+       data, _ := json.Marshal(payload)

Review Comment:
   checkPixiuAvailable ignores json.Marshal errors (`data, _ := 
json.Marshal(...)`). If marshaling fails, the function will still send an 
empty/partial body and may return a misleading availability result; handle the 
error and return false (or bubble it up).
   ```suggestion
        data, err := json.Marshal(payload)
        if err != nil {
                return false
        }
   ```



##########
ai/kvcache/mock/test/pixiu_test.go:
##########
@@ -0,0 +1,164 @@
+package test
+
+import (
+       "bytes"
+       "encoding/json"
+       "io"
+       "net/http"
+       "os"
+       "testing"
+       "time"
+)
+
+const (
+       defaultPixiuURL      = "http://127.0.0.1:18888";
+       defaultControllerURL = "http://127.0.0.1:18081";
+       defaultEngineAURL    = "http://127.0.0.1:18091";
+       defaultEngineBURL    = "http://127.0.0.1:18092";
+)
+
+func getEnvOrDefault(key string, fallback string) string {
+       if v := os.Getenv(key); v != "" {
+               return v
+       }
+       return fallback
+}
+
+func checkServiceAvailable(url string) bool {
+       resp, err := http.Get(url)
+       if err != nil {
+               return false
+       }
+       defer resp.Body.Close()
+       return resp.StatusCode >= 200 && resp.StatusCode < 300
+}

Review Comment:
   checkServiceAvailable uses http.Get with no timeout. If a local port accepts 
connections but doesn't respond, the test can hang; prefer an http.Client with 
a short Timeout and reuse it across helpers.



##########
ai/kvcache/mock/run.sh:
##########
@@ -0,0 +1,197 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_CONFIG="${PIXIU_CONFIG:-${SCRIPT_DIR}/pixiu/conf.yaml}"
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:18888}";
+LMCACHE_ADMIN="${LMCACHE_ADMIN:-http://127.0.0.1:18081}";
+ENGINE_A_ADMIN="${ENGINE_A_ADMIN:-http://127.0.0.1:18091}";
+ENGINE_B_ADMIN="${ENGINE_B_ADMIN:-http://127.0.0.1:18092}";
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"
+GO_CACHE_DIR="${GO_CACHE_DIR:-/tmp/go-build-cache}"
+GO_MOD_CACHE_DIR="${GO_MOD_CACHE_DIR:-/tmp/go-mod-cache}"
+export NO_PROXY="${NO_PROXY:-127.0.0.1,localhost}"
+export no_proxy="${no_proxy:-127.0.0.1,localhost}"
+
+WORK_DIR="$(mktemp -d /tmp/kvcache-mock-XXXXXX)"
+CONTROLLER_LOG="${WORK_DIR}/mock_controller.log"
+ENGINE_A_LOG="${WORK_DIR}/mock_engine_a.log"
+ENGINE_B_LOG="${WORK_DIR}/mock_engine_b.log"
+PIXIU_LOG="${WORK_DIR}/pixiu.log"
+
+CONTROLLER_PID=""
+ENGINE_A_PID=""
+ENGINE_B_PID=""
+PIXIU_PID=""
+
+REQ_BODY='{"model":"mock-model","messages":[{"role":"user","content":"please 
explain kv cache routing"}]}'
+
+cleanup() {
+  set +e
+  if [[ -n "${PIXIU_PID}" ]] && kill -0 "${PIXIU_PID}" >/dev/null 2>&1; then
+    kill "${PIXIU_PID}" >/dev/null 2>&1
+    wait "${PIXIU_PID}" >/dev/null 2>&1
+  fi
+  if [[ -n "${CONTROLLER_PID}" ]] && kill -0 "${CONTROLLER_PID}" >/dev/null 
2>&1; then
+    kill "${CONTROLLER_PID}" >/dev/null 2>&1
+    wait "${CONTROLLER_PID}" >/dev/null 2>&1
+  fi
+  if [[ -n "${ENGINE_A_PID}" ]] && kill -0 "${ENGINE_A_PID}" >/dev/null 2>&1; 
then
+    kill "${ENGINE_A_PID}" >/dev/null 2>&1
+    wait "${ENGINE_A_PID}" >/dev/null 2>&1
+  fi
+  if [[ -n "${ENGINE_B_PID}" ]] && kill -0 "${ENGINE_B_PID}" >/dev/null 2>&1; 
then
+    kill "${ENGINE_B_PID}" >/dev/null 2>&1
+    wait "${ENGINE_B_PID}" >/dev/null 2>&1
+  fi
+}
+trap cleanup EXIT INT TERM
+
+extract_num() {
+  local json="$1"
+  local key="$2"
+  sed -n "s/.*\"${key}\":\([0-9][0-9]*\).*/\1/p" <<<"${json}"
+}
+
+extract_str() {
+  local json="$1"
+  local key="$2"
+  sed -n "s/.*\"${key}\":\"\([^\"]*\)\".*/\1/p" <<<"${json}"
+}
+
+wait_for_health() {
+  local url="$1"
+  for _ in $(seq 1 80); do
+    if curl -fsS "${url}" >/dev/null 2>&1; then
+      return 0
+    fi
+    sleep 0.2
+  done
+  return 1
+}
+
+wait_for_pixiu() {
+  for _ in $(seq 1 80); do
+    local status
+    status="$(curl -s -o /tmp/kvcache-pixiu-ready.out -w '%{http_code}' \

Review Comment:
   wait_for_pixiu writes to a fixed file (/tmp/kvcache-pixiu-ready.out), which 
can be clobbered by concurrent runs. Prefer a per-run path under WORK_DIR or a 
mktemp-generated file.
   ```suggestion
       status="$(curl -s -o "${WORK_DIR}/kvcache-pixiu-ready.out" -w 
'%{http_code}' \
   ```



##########
ai/kvcache/mock/test/pixiu_test.go:
##########
@@ -0,0 +1,164 @@
+package test
+
+import (
+       "bytes"
+       "encoding/json"
+       "io"
+       "net/http"
+       "os"
+       "testing"
+       "time"
+)
+
+const (
+       defaultPixiuURL      = "http://127.0.0.1:18888";
+       defaultControllerURL = "http://127.0.0.1:18081";
+       defaultEngineAURL    = "http://127.0.0.1:18091";
+       defaultEngineBURL    = "http://127.0.0.1:18092";
+)
+
+func getEnvOrDefault(key string, fallback string) string {
+       if v := os.Getenv(key); v != "" {
+               return v
+       }
+       return fallback
+}
+
+func checkServiceAvailable(url string) bool {
+       resp, err := http.Get(url)
+       if err != nil {
+               return false
+       }
+       defer resp.Body.Close()
+       return resp.StatusCode >= 200 && resp.StatusCode < 300
+}
+
+func checkPixiuAvailable(url string) bool {
+       payload := map[string]any{
+               "model":  "mock-model",
+               "prompt": "kvcache availability probe",
+       }
+       data, _ := json.Marshal(payload)

Review Comment:
   checkPixiuAvailable ignores json.Marshal errors (`data, _ := 
json.Marshal(...)`). If marshaling fails, the function may still issue a 
request with a bad body and return a misleading availability result; handle the 
error and return false.
   ```suggestion
        data, err := json.Marshal(payload)
        if err != nil {
                return false
        }
   ```



##########
ai/kvcache/mock/run.sh:
##########
@@ -0,0 +1,197 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_CONFIG="${PIXIU_CONFIG:-${SCRIPT_DIR}/pixiu/conf.yaml}"
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:18888}";
+LMCACHE_ADMIN="${LMCACHE_ADMIN:-http://127.0.0.1:18081}";
+ENGINE_A_ADMIN="${ENGINE_A_ADMIN:-http://127.0.0.1:18091}";
+ENGINE_B_ADMIN="${ENGINE_B_ADMIN:-http://127.0.0.1:18092}";
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"

Review Comment:
   PIXIU_SOURCE defaults to a developer-specific absolute path 
(/home/chen/dubbo-go-pixiu), which will be wrong for most users. Consider 
leaving it unset by default and documenting it, or use a relative path if this 
repo vendors Pixiu nearby.
   ```suggestion
   PIXIU_SOURCE="${PIXIU_SOURCE:-${SCRIPT_DIR}/../../dubbo-go-pixiu}"
   ```



##########
ai/kvcache/real-engine/verify.sh:
##########
@@ -0,0 +1,326 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"
+START_PIXIU="${START_PIXIU:-1}"
+GO_CACHE_DIR="${GO_CACHE_DIR:-/tmp/go-build-cache}"
+GO_MOD_CACHE_DIR="${GO_MOD_CACHE_DIR:-/tmp/go-mod-cache}"
+export NO_PROXY="${NO_PROXY:-127.0.0.1,localhost}"
+export no_proxy="${no_proxy:-127.0.0.1,localhost}"
+
+required_cmds=(curl jq envsubst awk sort)
+for cmd in "${required_cmds[@]}"; do
+  if ! command -v "${cmd}" >/dev/null 2>&1; then
+    echo "missing required command: ${cmd}"
+    exit 1
+  fi
+done
+
+require_env() {
+  local key="$1"
+  if [[ -z "${!key:-}" ]]; then
+    echo "missing required env: ${key}"
+    exit 1
+  fi
+}
+
+parse_url_scheme() {
+  local url="$1"
+  if [[ "${url}" == https://* ]]; then
+    echo "https"
+  else
+    echo "http"
+  fi
+}
+
+parse_url_host() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  echo "${tmp%%:*}"
+}
+
+parse_url_port() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  if [[ "${tmp}" == *:* ]]; then
+    echo "${tmp##*:}"
+    return
+  fi
+  if [[ "${url}" == https://* ]]; then
+    echo "443"
+  else
+    echo "80"
+  fi
+}
+
+require_env VLLM_ENDPOINT
+require_env LMCACHE_ENDPOINT
+
+export PIXIU_LISTEN_PORT="${PIXIU_LISTEN_PORT:-18889}"
+export PIXIU_PROM_PORT="${PIXIU_PROM_PORT:-2223}"
+export MODEL_NAME="${MODEL_NAME:-Qwen2.5-3B-Instruct}"
+export HOT_CONTENT_THRESHOLD="${HOT_CONTENT_THRESHOLD:-3}"
+export LOAD_THRESHOLD="${LOAD_THRESHOLD:-0.7}"
+export MEMORY_THRESHOLD="${MEMORY_THRESHOLD:-0.8}"
+export LLM_SCHEME="${LLM_SCHEME:-$(parse_url_scheme "${VLLM_ENDPOINT}")}" # 
override to https if needed
+
+export ENGINE_ENDPOINT_A_ID="${ENGINE_ENDPOINT_A_ID:-engine-a}"
+export ENGINE_ENDPOINT_B_ID="${ENGINE_ENDPOINT_B_ID:-engine-b}"
+export ENGINE_ENDPOINT_A_HOST="${ENGINE_ENDPOINT_A_HOST:-$(parse_url_host 
"${VLLM_ENDPOINT}")}" 
+export ENGINE_ENDPOINT_A_PORT="${ENGINE_ENDPOINT_A_PORT:-$(parse_url_port 
"${VLLM_ENDPOINT}")}" 
+export 
ENGINE_ENDPOINT_B_HOST="${ENGINE_ENDPOINT_B_HOST:-${ENGINE_ENDPOINT_A_HOST}}"
+export 
ENGINE_ENDPOINT_B_PORT="${ENGINE_ENDPOINT_B_PORT:-${ENGINE_ENDPOINT_A_PORT}}"
+
+export PIN_INSTANCE_ID="${PIN_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+export PIN_LOCATION="${PIN_LOCATION:-lmcache}"
+export COMPRESS_INSTANCE_ID="${COMPRESS_INSTANCE_ID:-${ENGINE_ENDPOINT_B_ID}}"
+export COMPRESS_LOCATION="${COMPRESS_LOCATION:-lmcache}"
+export EVICT_INSTANCE_ID="${EVICT_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:${PIXIU_LISTEN_PORT}}";
+PROM_URL="${PROM_URL:-http://127.0.0.1:${PIXIU_PROM_PORT}/metrics}";
+
+WORK_DIR="$(mktemp -d /tmp/kvcache-real-verify-XXXXXX)"
+RENDERED_CONFIG="${WORK_DIR}/pixiu.rendered.yaml"
+PIXIU_LOG="${WORK_DIR}/pixiu.log"
+
+BASELINE_ROUNDS="${BASELINE_ROUNDS:-12}"
+CACHED_ROUNDS="${CACHED_ROUNDS:-12}"
+BASELINE_FILE="${WORK_DIR}/baseline.times"
+CACHED_FILE="${WORK_DIR}/cached.times"
+
+PIXIU_PID=""
+
+cleanup() {
+  set +e
+  if [[ -n "${PIXIU_PID}" ]] && kill -0 "${PIXIU_PID}" >/dev/null 2>&1; then
+    kill "${PIXIU_PID}" >/dev/null 2>&1
+    wait "${PIXIU_PID}" >/dev/null 2>&1
+  fi
+}
+trap cleanup EXIT INT TERM
+
+wait_for_pixiu() {
+  local body
+  body="$(jq -nc --arg model "${MODEL_NAME}" '{model:$model,prompt:"kvcache 
smoke"}')"
+  for _ in $(seq 1 100); do
+    local code
+    code="$(curl -s -o /tmp/kvcache-real-ready.out -w '%{http_code}' \
+      -H 'Content-Type: application/json' \
+      -X POST "${PIXIU_URL}/v1/chat/completions" \
+      -d "${body}" || true)"
+    if [[ "${code}" == "200" || "${code}" == "4"* || "${code}" == "5"* ]]; then
+      return 0
+    fi
+    sleep 0.3
+  done
+  return 1
+}
+
+start_pixiu() {
+  if command -v pixiu >/dev/null 2>&1; then
+    pixiu gateway start -c "${RENDERED_CONFIG}" >"${PIXIU_LOG}" 2>&1 &
+    PIXIU_PID="$!"
+  elif [[ -d "${PIXIU_SOURCE}/cmd/pixiu" ]]; then
+    (
+      cd "${PIXIU_SOURCE}"
+      env GOCACHE="${GO_CACHE_DIR}" GOMODCACHE="${GO_MOD_CACHE_DIR}" go run 
./cmd/pixiu/*.go gateway start -c "${RENDERED_CONFIG}"
+    ) >"${PIXIU_LOG}" 2>&1 &
+    PIXIU_PID="$!"
+  else
+    echo "cannot find pixiu binary or source. set PIXIU_SOURCE or install 
pixiu in PATH"
+    exit 1
+  fi
+
+  if ! wait_for_pixiu; then
+    echo "pixiu not ready, log: ${PIXIU_LOG}"
+    exit 1
+  fi
+}
+
+render_config() {
+  envsubst <"${SCRIPT_DIR}/pixiu/conf.yaml" >"${RENDERED_CONFIG}"
+}
+
+p95() {
+  local file="$1"
+  awk 'NF {print $1}' "${file}" | sort -n | awk '
+    {
+      arr[NR] = $1
+    }
+    END {
+      if (NR == 0) {
+        print "0"
+        exit
+      }
+      idx = int((NR * 95 + 99) / 100)
+      if (idx < 1) idx = 1
+      if (idx > NR) idx = NR
+      print arr[idx]
+    }'
+}
+
+avg() {
+  local file="$1"
+  awk '{sum += $1; n += 1} END {if (n == 0) {print "0"} else {printf "%.6f", 
sum / n}}' "${file}"
+}
+
+run_load() {
+  local mode="$1"
+  local rounds="$2"
+  local output_file="$3"
+  local fixed_prompt="kvcache route preference probe"
+
+  : >"${output_file}"
+  for i in $(seq 1 "${rounds}"); do
+    local prompt
+    if [[ "${mode}" == "baseline" ]]; then
+      prompt="${fixed_prompt} baseline-${i}-$(date +%s%N)"
+    else
+      prompt="${fixed_prompt}"
+    fi
+
+    local body
+    body="$(jq -nc --arg model "${MODEL_NAME}" --arg prompt "${prompt}" 
'{model:$model,messages:[{role:"user",content:$prompt}]}')"
+
+    local result
+    result="$(curl -sS -o /tmp/kvcache-real-${mode}.out -w '%{http_code} 
%{time_total}' \
+      -H 'Content-Type: application/json' \
+      -X POST "${PIXIU_URL}/v1/chat/completions" \
+      -d "${body}")"
+
+    local status
+    status="${result%% *}"
+    local timing
+    timing="${result##* }"
+
+    if [[ "${status}" != "200" ]]; then
+      echo "request failed in ${mode} mode: status=${status}"
+      cat /tmp/kvcache-real-${mode}.out
+      exit 1
+    fi
+
+    echo "${timing}" >>"${output_file}"
+  done
+}
+
+lookup_probe() {
+  local tokenize_body
+  tokenize_body="$(jq -nc --arg model "${MODEL_NAME}" 
'{model:$model,prompt:"kvcache lookup probe"}')"
+
+  local tokenize_resp
+  tokenize_resp="$(curl -sS -H 'Content-Type: application/json' -X POST 
"${VLLM_ENDPOINT}/tokenize" -d "${tokenize_body}")"
+
+  local tokens_json
+  tokens_json="$(jq -c '.tokens // []' <<<"${tokenize_resp}")"
+  if [[ "${tokens_json}" == "[]" ]]; then
+    echo "lookup_probe_error: tokenize returned empty tokens"
+    exit 1
+  fi
+
+  local lookup_body
+  lookup_body="$(jq -nc --argjson t "${tokens_json}" '{tokens:$t}')"
+  local lookup_resp
+  lookup_resp="$(curl -sS -H 'Content-Type: application/json' -X POST 
"${LMCACHE_ENDPOINT}/lookup" -d "${lookup_body}")"
+
+  local preferred
+  preferred="$(jq -r '.layout_info | to_entries | max_by(.value["1"]) | .key 
// empty' <<<"${lookup_resp}")"
+  if [[ -z "${preferred}" ]]; then
+    echo "lookup_probe_error: cannot parse preferred endpoint from lookup 
response"
+    exit 1
+  fi

Review Comment:
   lookup_probe assumes successful JSON responses from /tokenize and /lookup; 
with `set -e`, any non-JSON/partial response will cause jq to exit non-zero and 
the script will terminate with a jq error instead of a clear message. Consider 
checking HTTP status codes (e.g., curl -f with captured status/body) and making 
the jq queries resilient (e.g., defaulting `.layout_info` to `{}`) so failures 
produce actionable errors.



##########
ai/kvcache/mock/test/pixiu_test.go:
##########
@@ -0,0 +1,164 @@
+package test
+
+import (
+       "bytes"
+       "encoding/json"
+       "io"
+       "net/http"
+       "os"
+       "testing"
+       "time"
+)
+
+const (
+       defaultPixiuURL      = "http://127.0.0.1:18888";
+       defaultControllerURL = "http://127.0.0.1:18081";
+       defaultEngineAURL    = "http://127.0.0.1:18091";
+       defaultEngineBURL    = "http://127.0.0.1:18092";
+)
+
+func getEnvOrDefault(key string, fallback string) string {
+       if v := os.Getenv(key); v != "" {
+               return v
+       }
+       return fallback
+}
+
+func checkServiceAvailable(url string) bool {
+       resp, err := http.Get(url)
+       if err != nil {
+               return false
+       }
+       defer resp.Body.Close()
+       return resp.StatusCode >= 200 && resp.StatusCode < 300
+}
+
+func checkPixiuAvailable(url string) bool {
+       payload := map[string]any{
+               "model":  "mock-model",
+               "prompt": "kvcache availability probe",
+       }
+       data, _ := json.Marshal(payload)
+       req, err := http.NewRequest(http.MethodPost, 
url+"/v1/chat/completions", bytes.NewReader(data))
+       if err != nil {
+               return false
+       }
+       req.Header.Set("Content-Type", "application/json")
+       resp, err := http.DefaultClient.Do(req)
+       if err != nil {
+               return false
+       }
+       defer resp.Body.Close()
+       return resp.StatusCode >= 200 && resp.StatusCode < 600
+}
+
+func postJSON(t *testing.T, url string, payload any) map[string]any {
+       t.Helper()
+       data, err := json.Marshal(payload)
+       if err != nil {
+               t.Fatalf("marshal payload failed: %v", err)
+       }
+
+       req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(data))
+       if err != nil {
+               t.Fatalf("create request failed: %v", err)
+       }
+       req.Header.Set("Content-Type", "application/json")
+
+       resp, err := http.DefaultClient.Do(req)
+       if err != nil {
+               t.Fatalf("request failed: %v", err)
+       }
+       defer resp.Body.Close()
+       body, _ := io.ReadAll(resp.Body)
+       if resp.StatusCode < 200 || resp.StatusCode >= 300 {
+               t.Fatalf("request status %d: %s", resp.StatusCode, string(body))
+       }
+
+       var out map[string]any
+       if err := json.Unmarshal(body, &out); err != nil {
+               t.Fatalf("unmarshal response failed: %v body=%s", err, 
string(body))
+       }
+       return out
+}
+
+func getJSON(t *testing.T, url string) map[string]any {
+       t.Helper()
+       resp, err := http.Get(url)
+       if err != nil {
+               t.Fatalf("get request failed: %v", err)
+       }

Review Comment:
   postJSON/getJSON use http.DefaultClient / http.Get with no timeout. If pixiu 
or a mock server becomes unresponsive, `go test` can hang indefinitely; 
consider using an http.Client with Timeout and using it for all requests in 
this test.



##########
ai/kvcache/real-engine/test/pixiu_test.go:
##########
@@ -0,0 +1,87 @@
+package test
+
+import (
+       "bytes"
+       "encoding/json"
+       "io"
+       "net/http"
+       "os"
+       "testing"
+)
+
+const defaultBYOEPixiuURL = "http://127.0.0.1:18889";
+
+func envOrDefault(key string, fallback string) string {
+       if v := os.Getenv(key); v != "" {
+               return v
+       }
+       return fallback
+}
+
+func checkPixiuAvailable(url string) bool {
+       payload := map[string]any{
+               "model":  envOrDefault("MODEL_NAME", "Qwen2.5-3B-Instruct"),
+               "prompt": "kvcache byoe availability probe",
+       }
+       data, _ := json.Marshal(payload)
+       req, err := http.NewRequest(http.MethodPost, 
url+"/v1/chat/completions", bytes.NewReader(data))
+       if err != nil {
+               return false
+       }
+       req.Header.Set("Content-Type", "application/json")
+       resp, err := http.DefaultClient.Do(req)
+       if err != nil {
+               return false
+       }
+       defer resp.Body.Close()
+       return resp.StatusCode >= 200 && resp.StatusCode < 600
+}
+
+func TestBYOEEnvironmentAndGatewayAvailability(t *testing.T) {
+       if os.Getenv("VLLM_ENDPOINT") == "" || os.Getenv("LMCACHE_ENDPOINT") == 
"" {
+               t.Skip("VLLM_ENDPOINT/LMCACHE_ENDPOINT not set; BYOE 
environment not configured")
+       }
+
+       pixiuURL := envOrDefault("PIXIU_URL", defaultBYOEPixiuURL)
+       if !checkPixiuAvailable(pixiuURL) {
+               t.Skip("pixiu gateway is unavailable; start pixiu with 
ai/kvcache/real-engine/pixiu/conf.yaml first")
+       }
+}
+
+func TestBYOERequestSmoke(t *testing.T) {
+       if os.Getenv("VLLM_ENDPOINT") == "" || os.Getenv("LMCACHE_ENDPOINT") == 
"" {
+               t.Skip("VLLM_ENDPOINT/LMCACHE_ENDPOINT not set; BYOE 
environment not configured")
+       }
+
+       pixiuURL := envOrDefault("PIXIU_URL", defaultBYOEPixiuURL)
+       if !checkPixiuAvailable(pixiuURL) {
+               t.Skip("pixiu gateway is unavailable; start pixiu first")
+       }
+
+       payload := map[string]any{
+               "model": envOrDefault("MODEL_NAME", "Qwen2.5-3B-Instruct"),
+               "messages": []map[string]any{{
+                       "role":    "user",
+                       "content": "kvcache byoe smoke test",
+               }},
+       }
+       data, err := json.Marshal(payload)
+       if err != nil {
+               t.Fatalf("marshal payload failed: %v", err)
+       }
+       req, err := http.NewRequest(http.MethodPost, 
pixiuURL+"/v1/chat/completions", bytes.NewReader(data))
+       if err != nil {
+               t.Fatalf("create request failed: %v", err)
+       }
+       req.Header.Set("Content-Type", "application/json")
+
+       resp, err := http.DefaultClient.Do(req)
+       if err != nil {

Review Comment:
   These tests use http.DefaultClient / http.Get with no timeout. In a 
misconfigured BYOE env this can hang `go test` indefinitely; consider using an 
http.Client with a short Timeout (and/or per-request context with deadline) for 
both availability probes and the smoke request.



##########
ai/kvcache/real-engine/verify.sh:
##########
@@ -0,0 +1,326 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"
+START_PIXIU="${START_PIXIU:-1}"
+GO_CACHE_DIR="${GO_CACHE_DIR:-/tmp/go-build-cache}"
+GO_MOD_CACHE_DIR="${GO_MOD_CACHE_DIR:-/tmp/go-mod-cache}"
+export NO_PROXY="${NO_PROXY:-127.0.0.1,localhost}"
+export no_proxy="${no_proxy:-127.0.0.1,localhost}"
+
+required_cmds=(curl jq envsubst awk sort)
+for cmd in "${required_cmds[@]}"; do
+  if ! command -v "${cmd}" >/dev/null 2>&1; then
+    echo "missing required command: ${cmd}"
+    exit 1
+  fi
+done
+
+require_env() {
+  local key="$1"
+  if [[ -z "${!key:-}" ]]; then
+    echo "missing required env: ${key}"
+    exit 1
+  fi
+}
+
+parse_url_scheme() {
+  local url="$1"
+  if [[ "${url}" == https://* ]]; then
+    echo "https"
+  else
+    echo "http"
+  fi
+}
+
+parse_url_host() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  echo "${tmp%%:*}"
+}
+
+parse_url_port() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  if [[ "${tmp}" == *:* ]]; then
+    echo "${tmp##*:}"
+    return
+  fi
+  if [[ "${url}" == https://* ]]; then
+    echo "443"
+  else
+    echo "80"
+  fi
+}
+
+require_env VLLM_ENDPOINT
+require_env LMCACHE_ENDPOINT
+
+export PIXIU_LISTEN_PORT="${PIXIU_LISTEN_PORT:-18889}"
+export PIXIU_PROM_PORT="${PIXIU_PROM_PORT:-2223}"
+export MODEL_NAME="${MODEL_NAME:-Qwen2.5-3B-Instruct}"
+export HOT_CONTENT_THRESHOLD="${HOT_CONTENT_THRESHOLD:-3}"
+export LOAD_THRESHOLD="${LOAD_THRESHOLD:-0.7}"
+export MEMORY_THRESHOLD="${MEMORY_THRESHOLD:-0.8}"
+export LLM_SCHEME="${LLM_SCHEME:-$(parse_url_scheme "${VLLM_ENDPOINT}")}" # 
override to https if needed
+
+export ENGINE_ENDPOINT_A_ID="${ENGINE_ENDPOINT_A_ID:-engine-a}"
+export ENGINE_ENDPOINT_B_ID="${ENGINE_ENDPOINT_B_ID:-engine-b}"
+export ENGINE_ENDPOINT_A_HOST="${ENGINE_ENDPOINT_A_HOST:-$(parse_url_host 
"${VLLM_ENDPOINT}")}" 
+export ENGINE_ENDPOINT_A_PORT="${ENGINE_ENDPOINT_A_PORT:-$(parse_url_port 
"${VLLM_ENDPOINT}")}" 
+export 
ENGINE_ENDPOINT_B_HOST="${ENGINE_ENDPOINT_B_HOST:-${ENGINE_ENDPOINT_A_HOST}}"
+export 
ENGINE_ENDPOINT_B_PORT="${ENGINE_ENDPOINT_B_PORT:-${ENGINE_ENDPOINT_A_PORT}}"
+
+export PIN_INSTANCE_ID="${PIN_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+export PIN_LOCATION="${PIN_LOCATION:-lmcache}"
+export COMPRESS_INSTANCE_ID="${COMPRESS_INSTANCE_ID:-${ENGINE_ENDPOINT_B_ID}}"
+export COMPRESS_LOCATION="${COMPRESS_LOCATION:-lmcache}"
+export EVICT_INSTANCE_ID="${EVICT_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:${PIXIU_LISTEN_PORT}}";
+PROM_URL="${PROM_URL:-http://127.0.0.1:${PIXIU_PROM_PORT}/metrics}";
+
+WORK_DIR="$(mktemp -d /tmp/kvcache-real-verify-XXXXXX)"
+RENDERED_CONFIG="${WORK_DIR}/pixiu.rendered.yaml"
+PIXIU_LOG="${WORK_DIR}/pixiu.log"
+
+BASELINE_ROUNDS="${BASELINE_ROUNDS:-12}"
+CACHED_ROUNDS="${CACHED_ROUNDS:-12}"
+BASELINE_FILE="${WORK_DIR}/baseline.times"
+CACHED_FILE="${WORK_DIR}/cached.times"
+
+PIXIU_PID=""
+
+cleanup() {
+  set +e
+  if [[ -n "${PIXIU_PID}" ]] && kill -0 "${PIXIU_PID}" >/dev/null 2>&1; then
+    kill "${PIXIU_PID}" >/dev/null 2>&1
+    wait "${PIXIU_PID}" >/dev/null 2>&1
+  fi

Review Comment:
   WORK_DIR is created with mktemp but never removed. This leaves temp 
directories/logs under /tmp across runs; consider extending cleanup() to `rm 
-rf "$WORK_DIR"` (and ensure it still prints paths when needed).
   ```suggestion
     fi
   
     if [[ -n "${WORK_DIR:-}" && -d "${WORK_DIR}" ]]; then
       rm -rf "${WORK_DIR}"
     fi
   ```



##########
ai/kvcache/real-engine/verify.sh:
##########
@@ -0,0 +1,326 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"
+START_PIXIU="${START_PIXIU:-1}"
+GO_CACHE_DIR="${GO_CACHE_DIR:-/tmp/go-build-cache}"
+GO_MOD_CACHE_DIR="${GO_MOD_CACHE_DIR:-/tmp/go-mod-cache}"
+export NO_PROXY="${NO_PROXY:-127.0.0.1,localhost}"
+export no_proxy="${no_proxy:-127.0.0.1,localhost}"
+
+required_cmds=(curl jq envsubst awk sort)
+for cmd in "${required_cmds[@]}"; do
+  if ! command -v "${cmd}" >/dev/null 2>&1; then
+    echo "missing required command: ${cmd}"
+    exit 1
+  fi
+done
+
+require_env() {
+  local key="$1"
+  if [[ -z "${!key:-}" ]]; then
+    echo "missing required env: ${key}"
+    exit 1
+  fi
+}
+
+parse_url_scheme() {
+  local url="$1"
+  if [[ "${url}" == https://* ]]; then
+    echo "https"
+  else
+    echo "http"
+  fi
+}
+
+parse_url_host() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  echo "${tmp%%:*}"
+}
+
+parse_url_port() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  if [[ "${tmp}" == *:* ]]; then
+    echo "${tmp##*:}"
+    return
+  fi
+  if [[ "${url}" == https://* ]]; then
+    echo "443"
+  else
+    echo "80"
+  fi
+}
+
+require_env VLLM_ENDPOINT
+require_env LMCACHE_ENDPOINT
+
+export PIXIU_LISTEN_PORT="${PIXIU_LISTEN_PORT:-18889}"
+export PIXIU_PROM_PORT="${PIXIU_PROM_PORT:-2223}"
+export MODEL_NAME="${MODEL_NAME:-Qwen2.5-3B-Instruct}"
+export HOT_CONTENT_THRESHOLD="${HOT_CONTENT_THRESHOLD:-3}"
+export LOAD_THRESHOLD="${LOAD_THRESHOLD:-0.7}"
+export MEMORY_THRESHOLD="${MEMORY_THRESHOLD:-0.8}"
+export LLM_SCHEME="${LLM_SCHEME:-$(parse_url_scheme "${VLLM_ENDPOINT}")}" # 
override to https if needed
+
+export ENGINE_ENDPOINT_A_ID="${ENGINE_ENDPOINT_A_ID:-engine-a}"
+export ENGINE_ENDPOINT_B_ID="${ENGINE_ENDPOINT_B_ID:-engine-b}"
+export ENGINE_ENDPOINT_A_HOST="${ENGINE_ENDPOINT_A_HOST:-$(parse_url_host 
"${VLLM_ENDPOINT}")}" 
+export ENGINE_ENDPOINT_A_PORT="${ENGINE_ENDPOINT_A_PORT:-$(parse_url_port 
"${VLLM_ENDPOINT}")}" 
+export 
ENGINE_ENDPOINT_B_HOST="${ENGINE_ENDPOINT_B_HOST:-${ENGINE_ENDPOINT_A_HOST}}"
+export 
ENGINE_ENDPOINT_B_PORT="${ENGINE_ENDPOINT_B_PORT:-${ENGINE_ENDPOINT_A_PORT}}"
+
+export PIN_INSTANCE_ID="${PIN_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+export PIN_LOCATION="${PIN_LOCATION:-lmcache}"
+export COMPRESS_INSTANCE_ID="${COMPRESS_INSTANCE_ID:-${ENGINE_ENDPOINT_B_ID}}"
+export COMPRESS_LOCATION="${COMPRESS_LOCATION:-lmcache}"
+export EVICT_INSTANCE_ID="${EVICT_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:${PIXIU_LISTEN_PORT}}";
+PROM_URL="${PROM_URL:-http://127.0.0.1:${PIXIU_PROM_PORT}/metrics}";
+
+WORK_DIR="$(mktemp -d /tmp/kvcache-real-verify-XXXXXX)"
+RENDERED_CONFIG="${WORK_DIR}/pixiu.rendered.yaml"
+PIXIU_LOG="${WORK_DIR}/pixiu.log"
+
+BASELINE_ROUNDS="${BASELINE_ROUNDS:-12}"
+CACHED_ROUNDS="${CACHED_ROUNDS:-12}"
+BASELINE_FILE="${WORK_DIR}/baseline.times"
+CACHED_FILE="${WORK_DIR}/cached.times"
+
+PIXIU_PID=""
+
+cleanup() {
+  set +e
+  if [[ -n "${PIXIU_PID}" ]] && kill -0 "${PIXIU_PID}" >/dev/null 2>&1; then
+    kill "${PIXIU_PID}" >/dev/null 2>&1
+    wait "${PIXIU_PID}" >/dev/null 2>&1
+  fi
+}
+trap cleanup EXIT INT TERM
+
+wait_for_pixiu() {
+  local body
+  body="$(jq -nc --arg model "${MODEL_NAME}" '{model:$model,prompt:"kvcache 
smoke"}')"
+  for _ in $(seq 1 100); do
+    local code
+    code="$(curl -s -o /tmp/kvcache-real-ready.out -w '%{http_code}' \

Review Comment:
   curl output is written to a fixed path (/tmp/kvcache-real-ready.out). This 
can clobber concurrent runs and may leak data across users; prefer using a file 
under WORK_DIR or a mktemp-generated path.
   ```suggestion
       code="$(curl -s -o /dev/null -w '%{http_code}' \
   ```



##########
ai/kvcache/real-engine/verify.sh:
##########
@@ -0,0 +1,326 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"
+START_PIXIU="${START_PIXIU:-1}"
+GO_CACHE_DIR="${GO_CACHE_DIR:-/tmp/go-build-cache}"
+GO_MOD_CACHE_DIR="${GO_MOD_CACHE_DIR:-/tmp/go-mod-cache}"
+export NO_PROXY="${NO_PROXY:-127.0.0.1,localhost}"
+export no_proxy="${no_proxy:-127.0.0.1,localhost}"
+
+required_cmds=(curl jq envsubst awk sort)
+for cmd in "${required_cmds[@]}"; do
+  if ! command -v "${cmd}" >/dev/null 2>&1; then
+    echo "missing required command: ${cmd}"
+    exit 1
+  fi
+done
+
+require_env() {
+  local key="$1"
+  if [[ -z "${!key:-}" ]]; then
+    echo "missing required env: ${key}"
+    exit 1
+  fi
+}
+
+parse_url_scheme() {
+  local url="$1"
+  if [[ "${url}" == https://* ]]; then
+    echo "https"
+  else
+    echo "http"
+  fi
+}
+
+parse_url_host() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  echo "${tmp%%:*}"
+}
+
+parse_url_port() {
+  local url="$1"
+  local tmp="${url#*://}"
+  tmp="${tmp%%/*}"
+  if [[ "${tmp}" == *:* ]]; then
+    echo "${tmp##*:}"
+    return
+  fi
+  if [[ "${url}" == https://* ]]; then
+    echo "443"
+  else
+    echo "80"
+  fi
+}
+
+require_env VLLM_ENDPOINT
+require_env LMCACHE_ENDPOINT
+
+export PIXIU_LISTEN_PORT="${PIXIU_LISTEN_PORT:-18889}"
+export PIXIU_PROM_PORT="${PIXIU_PROM_PORT:-2223}"
+export MODEL_NAME="${MODEL_NAME:-Qwen2.5-3B-Instruct}"
+export HOT_CONTENT_THRESHOLD="${HOT_CONTENT_THRESHOLD:-3}"
+export LOAD_THRESHOLD="${LOAD_THRESHOLD:-0.7}"
+export MEMORY_THRESHOLD="${MEMORY_THRESHOLD:-0.8}"
+export LLM_SCHEME="${LLM_SCHEME:-$(parse_url_scheme "${VLLM_ENDPOINT}")}" # 
override to https if needed
+
+export ENGINE_ENDPOINT_A_ID="${ENGINE_ENDPOINT_A_ID:-engine-a}"
+export ENGINE_ENDPOINT_B_ID="${ENGINE_ENDPOINT_B_ID:-engine-b}"
+export ENGINE_ENDPOINT_A_HOST="${ENGINE_ENDPOINT_A_HOST:-$(parse_url_host 
"${VLLM_ENDPOINT}")}" 
+export ENGINE_ENDPOINT_A_PORT="${ENGINE_ENDPOINT_A_PORT:-$(parse_url_port 
"${VLLM_ENDPOINT}")}" 
+export 
ENGINE_ENDPOINT_B_HOST="${ENGINE_ENDPOINT_B_HOST:-${ENGINE_ENDPOINT_A_HOST}}"
+export 
ENGINE_ENDPOINT_B_PORT="${ENGINE_ENDPOINT_B_PORT:-${ENGINE_ENDPOINT_A_PORT}}"
+
+export PIN_INSTANCE_ID="${PIN_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+export PIN_LOCATION="${PIN_LOCATION:-lmcache}"
+export COMPRESS_INSTANCE_ID="${COMPRESS_INSTANCE_ID:-${ENGINE_ENDPOINT_B_ID}}"
+export COMPRESS_LOCATION="${COMPRESS_LOCATION:-lmcache}"
+export EVICT_INSTANCE_ID="${EVICT_INSTANCE_ID:-${ENGINE_ENDPOINT_A_ID}}"
+
+PIXIU_URL="${PIXIU_URL:-http://127.0.0.1:${PIXIU_LISTEN_PORT}}";
+PROM_URL="${PROM_URL:-http://127.0.0.1:${PIXIU_PROM_PORT}/metrics}";
+
+WORK_DIR="$(mktemp -d /tmp/kvcache-real-verify-XXXXXX)"
+RENDERED_CONFIG="${WORK_DIR}/pixiu.rendered.yaml"
+PIXIU_LOG="${WORK_DIR}/pixiu.log"
+
+BASELINE_ROUNDS="${BASELINE_ROUNDS:-12}"
+CACHED_ROUNDS="${CACHED_ROUNDS:-12}"
+BASELINE_FILE="${WORK_DIR}/baseline.times"
+CACHED_FILE="${WORK_DIR}/cached.times"
+
+PIXIU_PID=""
+
+cleanup() {
+  set +e
+  if [[ -n "${PIXIU_PID}" ]] && kill -0 "${PIXIU_PID}" >/dev/null 2>&1; then
+    kill "${PIXIU_PID}" >/dev/null 2>&1
+    wait "${PIXIU_PID}" >/dev/null 2>&1
+  fi
+}
+trap cleanup EXIT INT TERM
+
+wait_for_pixiu() {
+  local body
+  body="$(jq -nc --arg model "${MODEL_NAME}" '{model:$model,prompt:"kvcache 
smoke"}')"
+  for _ in $(seq 1 100); do
+    local code
+    code="$(curl -s -o /tmp/kvcache-real-ready.out -w '%{http_code}' \
+      -H 'Content-Type: application/json' \
+      -X POST "${PIXIU_URL}/v1/chat/completions" \
+      -d "${body}" || true)"
+    if [[ "${code}" == "200" || "${code}" == "4"* || "${code}" == "5"* ]]; then
+      return 0
+    fi
+    sleep 0.3
+  done
+  return 1
+}
+
+start_pixiu() {
+  if command -v pixiu >/dev/null 2>&1; then
+    pixiu gateway start -c "${RENDERED_CONFIG}" >"${PIXIU_LOG}" 2>&1 &
+    PIXIU_PID="$!"
+  elif [[ -d "${PIXIU_SOURCE}/cmd/pixiu" ]]; then
+    (
+      cd "${PIXIU_SOURCE}"
+      env GOCACHE="${GO_CACHE_DIR}" GOMODCACHE="${GO_MOD_CACHE_DIR}" go run 
./cmd/pixiu/*.go gateway start -c "${RENDERED_CONFIG}"
+    ) >"${PIXIU_LOG}" 2>&1 &
+    PIXIU_PID="$!"
+  else
+    echo "cannot find pixiu binary or source. set PIXIU_SOURCE or install 
pixiu in PATH"
+    exit 1
+  fi
+
+  if ! wait_for_pixiu; then
+    echo "pixiu not ready, log: ${PIXIU_LOG}"
+    exit 1
+  fi
+}
+
+render_config() {
+  envsubst <"${SCRIPT_DIR}/pixiu/conf.yaml" >"${RENDERED_CONFIG}"
+}
+
+p95() {
+  local file="$1"
+  awk 'NF {print $1}' "${file}" | sort -n | awk '
+    {
+      arr[NR] = $1
+    }
+    END {
+      if (NR == 0) {
+        print "0"
+        exit
+      }
+      idx = int((NR * 95 + 99) / 100)
+      if (idx < 1) idx = 1
+      if (idx > NR) idx = NR
+      print arr[idx]
+    }'
+}
+
+avg() {
+  local file="$1"
+  awk '{sum += $1; n += 1} END {if (n == 0) {print "0"} else {printf "%.6f", 
sum / n}}' "${file}"
+}
+
+run_load() {
+  local mode="$1"
+  local rounds="$2"
+  local output_file="$3"
+  local fixed_prompt="kvcache route preference probe"
+
+  : >"${output_file}"
+  for i in $(seq 1 "${rounds}"); do
+    local prompt
+    if [[ "${mode}" == "baseline" ]]; then
+      prompt="${fixed_prompt} baseline-${i}-$(date +%s%N)"
+    else
+      prompt="${fixed_prompt}"
+    fi
+
+    local body
+    body="$(jq -nc --arg model "${MODEL_NAME}" --arg prompt "${prompt}" 
'{model:$model,messages:[{role:"user",content:$prompt}]}')"
+
+    local result
+    result="$(curl -sS -o /tmp/kvcache-real-${mode}.out -w '%{http_code} 
%{time_total}' \
+      -H 'Content-Type: application/json' \
+      -X POST "${PIXIU_URL}/v1/chat/completions" \
+      -d "${body}")"
+
+    local status
+    status="${result%% *}"
+    local timing
+    timing="${result##* }"
+
+    if [[ "${status}" != "200" ]]; then
+      echo "request failed in ${mode} mode: status=${status}"
+      cat /tmp/kvcache-real-${mode}.out
+      exit 1

Review Comment:
   run_load writes responses to a fixed file (/tmp/kvcache-real-${mode}.out). 
This will overwrite across runs and mixes baseline/cached output between 
parallel executions; consider writing these files into WORK_DIR (or using 
mktemp) and including the request index in the filename.



##########
ai/kvcache/real-engine/verify.sh:
##########
@@ -0,0 +1,326 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PIXIU_SOURCE="${PIXIU_SOURCE:-/home/chen/dubbo-go-pixiu}"

Review Comment:
   PIXIU_SOURCE defaults to a developer-specific absolute path 
(/home/chen/dubbo-go-pixiu), which will be wrong for most users. Consider 
defaulting it to empty and requiring users to set it explicitly, or use a 
relative path (and keep the PATH-based pixiu lookup as the primary path).
   ```suggestion
   PIXIU_SOURCE="${PIXIU_SOURCE:-}"
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to