- vanilla nginx + Rust 动态模块(取代 OpenResty+Lua),共享内存为运行期真源 - 三域名分流 18098 ssl:mdm 管理台 / lm LLM 代理 / *.dm 企业转发,共用 *.mayishangshu.cn 通配符证书(证书不入库) - LLM 统一出口:同 Key 鉴权、上游 Key 替换、白名单、限流配额、SSE - 回归夹具 tests/(网关 55 + LLM 34 = 89 断言,夹具 cp 覆盖重置) - 文档:readme(16 章)+ CLAUDE.md + conf/tls/README(acme.sh 证书管理、hairpin 环回链路)
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""流式探针:确认 SSE 是「逐块到达」而不是「攒完一次性返回」。
|
||
|
||
GW=http://127.0.0.1:18090 KEY=sk_xxx python3 sse_test.py
|
||
|
||
输出机器可读的四行,供 e2e.sh 断言:
|
||
CT=text/event-stream
|
||
CHUNKS=3 收到几个 data 块
|
||
FIRST=0.01 首块到达耗时(秒);被缓冲住时 ≈ TOTAL
|
||
TOTAL=1.21 总耗时;上游 3 块 × 0.4s ≈ 1.2s
|
||
"""
|
||
|
||
import json
|
||
import os
|
||
import sys
|
||
import time
|
||
import urllib.request
|
||
|
||
KEY = os.environ.get("KEY", "")
|
||
GW = os.environ.get("GW", "http://127.0.0.1:18090")
|
||
URL = GW.rstrip("/") + "/openai/v1/chat/completions"
|
||
|
||
req = urllib.request.Request(
|
||
URL,
|
||
data=json.dumps({"model": "gpt-4o", "stream": True}).encode(),
|
||
headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"},
|
||
)
|
||
|
||
t0 = time.time()
|
||
first = None
|
||
chunks = 0
|
||
ctype = ""
|
||
with urllib.request.urlopen(req) as r:
|
||
ctype = r.headers.get("Content-Type", "")
|
||
while True:
|
||
line = r.readline()
|
||
if not line:
|
||
break
|
||
s = line.decode().strip()
|
||
if s.startswith("data:"):
|
||
chunks += 1
|
||
if first is None:
|
||
first = time.time() - t0
|
||
total = time.time() - t0
|
||
|
||
print("CT=%s" % ctype)
|
||
print("CHUNKS=%d" % chunks)
|
||
print("FIRST=%.2f" % (first if first is not None else -1))
|
||
print("TOTAL=%.2f" % total)
|