concurrency-test.py
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""四张卡同时跑同一条任务,量并发缩水。
各端口和自己的单跑基线比:cpu 模式 692s,disk 模式 767s。
任务规格从 8011 上那条已完成的 826db7b3f08e 原样取,保证四条完全一致。
"""
import json, time, urllib.request
# 8010/8011 是三小时前起的,跑的还是加 H3_OFFLOAD 之前的 api.py,/health 里没有 offload 字段,
# 所以模式和基线都写在这里。
MODE = {8010: "cpu", 8011: "cpu", 8012: "disk", 8013: "disk"}
BASELINE = {"cpu": 692, "disk": 767}
def call(port, path, body=None):
url = f"http://127.0.0.1:{port}{path}"
req = urllib.request.Request(url, data=body,
headers={"Content-Type": "application/json"} if body else {})
with urllib.request.urlopen(req, timeout=60) as r:
return json.load(r)
spec = json.dumps(call(8011, "/v1/videos/826db7b3f08e")["req"]).encode()
jobs = {}
for port, mode in MODE.items():
jobs[port] = (call(port, "/v1/videos", spec)["id"], mode)
print(f"{port} ({mode}) -> {jobs[port][0]}", flush=True)
print("--- 四条已同时投出,开始轮询", flush=True)
pending = dict(jobs)
while pending:
time.sleep(60)
for port in list(pending):
jid, mode = pending[port]
j = call(port, f"/v1/videos/{jid}")
if j["status"] in ("done", "failed"):
took = j["finished_at"] - j["started_at"]
base = BASELINE[mode]
print(f"{port} ({mode}) {j['status']} {took:.0f}s 基线{base}s "
f"缩水{(took/base-1)*100:+.1f}% 峰值显存{j.get('peak_vram_gb')}G "
f"{j.get('size_bytes')}字节", flush=True)
del pending[port]
else:
print(f" {port} {j['status']} {j.get('elapsed_seconds', 0)}s", flush=True)