Die sporadischen Ausfälle hatten zwei gemeinsame Ursachen: feste sleeps statt wait_port für frisch gestartete Stubs, und die Hintergrundprobe, die einen Endpunkt nach einem einzigen fehlgeschlagenen curl für offline_hold_s (20 s) aus dem Verkehr nahm. Unter Last traf beides gelegentlich einen Request: 503 offline statt text-only, 503 statt des Retry-After-Datums, oder ein nicht erreichbarer Stub. - probe_thread versucht eine fehlgeschlagene Probe nach 200 ms erneut; erst zwei Fehlschläge nehmen den Endpunkt offline. - retry-after.sh, ctx-vision.sh und flight.sh warten mit wait_port auf ihre Stubs, statt 0,3–0,8 s zu schlafen; probe_interval 0 schaltet die Hintergrundprobe in diesen deterministischen Abschnitten ab. - cluster.sh: probe_interval 0, größere Startfristen, der Peer-Cache wird gepollt statt nach 0,4 s einmal geprüft, und der Silent-Peer-Test erlaubt 5 s statt 2 s (er prüft, dass nichts hängt, nicht die CPU-Zeit). - mcp_concurrency.py: probe_interval 0; zerrissene Antworten werden mit Status und Rumpf ausgegeben, damit ein Wiederauftreten diagnostizierbar ist. Nachweis: zwei vollständige Läufe ohne nice -n -10 unter Last 6,8 bzw. 9,3, jeweils 484 OK / 0 FAIL.
106 lines
3.7 KiB
Bash
106 lines
3.7 KiB
Bash
#!/bin/bash
|
|
# Wird von tests/run.sh eingebunden: Single-Flight und Modell-Listen im Cache.
|
|
|
|
echo "== 23. Single-Flight: gleiche Anfrage, ein Aufruf =="
|
|
|
|
FPORT=$((PORT+61))
|
|
SPORT=$((PORT+62))
|
|
|
|
# Ein Ziel, das absichtlich langsam antwortet — nur so überlappen sich die Anfragen.
|
|
cat > "$TMP/slow.py" <<'PY'
|
|
import http.server, json, sys, time
|
|
class H(http.server.BaseHTTPRequestHandler):
|
|
def log_message(self, *a): pass
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
self.rfile.read(n)
|
|
time.sleep(3)
|
|
out = json.dumps({"id": "slow", "choices": [{"index": 0,
|
|
"message": {"role": "assistant", "content": "antwort"}}]}).encode()
|
|
self.send_response(200)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.send_header("Content-Length", str(len(out)))
|
|
self.end_headers()
|
|
self.wfile.write(out)
|
|
http.server.HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|
|
PY
|
|
python3 "$TMP/slow.py" "$SPORT" & PIDS+=($!)
|
|
wait_port "$SPORT" 30 || bad "the slow stub did not come up"
|
|
|
|
cat > "$TMP/flight.conf" <<CFG
|
|
listen 127.0.0.1:$FPORT
|
|
probe_interval 0
|
|
cache_ttl 300
|
|
cache_entries 50
|
|
cache_bytes 2000000
|
|
endpoint slow { base http://127.0.0.1:$SPORT/v1; timeout 30 }
|
|
req for "*" pass slow
|
|
CFG
|
|
./junction --config "$TMP/flight.conf" > "$TMP/flight.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port "$FPORT" 30 || bad "the flight instance did not come up"
|
|
|
|
BODY='{"model":"m","messages":[{"role":"user","content":"teure frage"}],"max_tokens":5,"temperature":0}'
|
|
ask() {
|
|
curl -s -m 30 -D - -o /dev/null -X POST -H 'Content-Type: application/json' -d "$BODY" \
|
|
"http://127.0.0.1:$FPORT/v1/chat/completions" | tr -d '\r' \
|
|
| sed -n 's/^[Xx]-[Jj]unction-[Cc]ache: //p'
|
|
}
|
|
|
|
# Drei Anfragen gleichzeitig. Ohne Single-Flight dauern sie 9 s, mit 3 s.
|
|
START=$(date +%s)
|
|
ask > "$TMP/f1.txt" & A=$!
|
|
ask > "$TMP/f2.txt" & B=$!
|
|
ask > "$TMP/f3.txt" & C=$!
|
|
wait $A $B $C
|
|
ELAPSED=$(( $(date +%s) - START ))
|
|
|
|
HITS=$(cat "$TMP/f1.txt" "$TMP/f2.txt" "$TMP/f3.txt" | grep -c '^hit$')
|
|
MISS=$(cat "$TMP/f1.txt" "$TMP/f2.txt" "$TMP/f3.txt" | grep -c '^miss$')
|
|
|
|
if [ "$ELAPSED" -le 5 ]; then
|
|
ok "three concurrent identical requests took ${ELAPSED}s, not 3x3s"
|
|
else
|
|
bad "three concurrent identical requests took ${ELAPSED}s — no sharing happened"
|
|
fi
|
|
if [ "$MISS" -eq 1 ] && [ "$HITS" -eq 2 ]; then
|
|
ok "exactly one request went upstream, two were served from its result"
|
|
else
|
|
bad "expected 1 miss and 2 hits, got ${MISS} misses and ${HITS} hits"
|
|
fi
|
|
|
|
# Der Zähler muss das auch sagen.
|
|
STATUS=$(curl -s -m 5 "http://127.0.0.1:$FPORT/status")
|
|
case "$STATUS" in
|
|
*'"joined":2'*) ok "/status counts the two joined requests" ;;
|
|
*) bad "/status does not count joined requests" ;;
|
|
esac
|
|
|
|
# Modell-Listen sind reproduzierbar und werden ohne Temperatur gecacht.
|
|
cat > "$TMP/models.conf" <<CFG
|
|
listen 127.0.0.1:$((FPORT+2))
|
|
probe_interval 0
|
|
cache_ttl 300
|
|
cache_entries 50
|
|
cache_bytes 2000000
|
|
endpoint a { base http://127.0.0.1:$P_GATED/v1 }
|
|
req path "/v1/models" check none pass a
|
|
req for "*" pass a
|
|
CFG
|
|
./junction --config "$TMP/models.conf" > "$TMP/models.log" 2>&1 &
|
|
PIDS+=($!)
|
|
wait_port $((FPORT+2)) 30 || bad "the model-list instance did not come up"
|
|
# POST, weil der Test-Stub nur POST beantwortet; geprüft wird der Pfad, nicht die Methode.
|
|
mfetch() {
|
|
curl -s -m 10 -D - -o /dev/null -X POST -H 'Content-Type: application/json' \
|
|
-d '{"model":"m","messages":[]}' "http://127.0.0.1:$((FPORT+2))/v1/models" \
|
|
| tr -d '\r' | sed -n 's/^[Xx]-[Jj]unction-[Cc]ache: //p'
|
|
}
|
|
M1=$(mfetch)
|
|
M2=$(mfetch)
|
|
if [ "$M1" = "miss" ] && [ "$M2" = "hit" ]; then
|
|
ok "a model listing is cached without a temperature"
|
|
else
|
|
bad "model listing cache: first=${M1:-none} second=${M2:-none}"
|
|
fi
|