modify: 性能优化

This commit is contained in:
2026-08-23 04:34:05 +08:00
parent 8b13ed17e6
commit a1be33376e
21 changed files with 1389 additions and 71 deletions
+4 -4
View File
@@ -12,7 +12,7 @@ MQTT 端到端测试脚本
"""
import asyncio
import json
import orjson
import sys
import logging
from amqtt.client import MQTTClient
@@ -51,7 +51,7 @@ async def run_test():
for i, case in enumerate(TEST_CASES):
a, b, expected = case["a"], case["b"], case["expected"]
payload = {"meta": {"method": "MQTT"}, "data": {"a": a, "b": b}}
payload_bytes = json.dumps(payload).encode("utf-8")
payload_bytes = orjson.dumps(payload)
await client.publish(REQUEST_TOPIC, payload_bytes, QOS_1)
print(f"📤 [{i+1}/{len(TEST_CASES)}] 发送: {REQUEST_TOPIC} → {payload}")
@@ -59,14 +59,14 @@ async def run_test():
# 等待响应(超时 5 秒)
try:
message = await asyncio.wait_for(client.deliver_message(), timeout=5.0)
data = json.loads(message.data.decode("utf-8")) # type: ignore
data = orjson.loads(message.data) # type: ignore
actual = data.get("result")
status = "✅ PASS" if abs(actual - expected) < 0.01 else "❌ FAIL"
if status == "✅ PASS":
PASS += 1
else:
FAIL += 1
print(f"📥 [{i+1}/{len(TEST_CASES)}] 响应: {json.dumps(data)} → {status} (expect={expected}, got={actual})")
print(f"📥 [{i+1}/{len(TEST_CASES)}] 响应: {orjson.dumps(data).decode()} → {status} (expect={expected}, got={actual})")
except asyncio.TimeoutError:
FAIL += 1
print(f"📥 [{i+1}/{len(TEST_CASES)}] ❌ FAIL: 超时无响应")