feat: 分时段轮询(营业 2s / 出单后 1.5s 追击 / 非营业 8s)+ 端到端延迟指标
- 实测订单接口平均 300ms,2.5 次/秒连续 20 次无限流,故营业时段可压到 2 秒 - 商家后台 JS 无 WebSocket/SSE/socket.io/MQTT(0 命中)→ 平台不推,只能轮询 - 出单后 60 秒内自动加密到 1.5 秒(出单常成串),窗口结束回落 - 新增 last_detect_lag_sec:以订单 payTime 计算「支付→检出」真实延迟,写入 state 并暴露在 /healthz - 新增 6 项节奏测试(共 30 项全绿) - 修复 login_url 折行产生空格、上传内网绕过系统代理、新增 --upload-only 补传
This commit is contained in:
1 parent
4ad6ecd5c9
commit
88f7183554
7 files changed
+187
-3
No files matched your search
@@ -0,0 +1,63 @@
|
||||
"""探测丰享商家后台的数据获取方式:WebSocket / 长轮询 / 定时轮询。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import time
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
COOKIES = json.loads(Path("data/cookies.json").read_text(encoding="utf-8"))
|
||||
|
||||
reqs: list[str] = []
|
||||
ws_urls: list[str] = []
|
||||
order_hits: list[str] = []
|
||||
|
||||
|
||||
def main() -> None:
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
ctx = browser.new_context()
|
||||
ctx.add_cookies(
|
||||
[{"name": k, "value": v, "domain": ".szfx.com", "path": "/"} for k, v in COOKIES.items()]
|
||||
)
|
||||
page = ctx.new_page()
|
||||
|
||||
page.on("websocket", lambda ws: ws_urls.append(ws.url))
|
||||
page.on("request", lambda r: reqs.append(r.url))
|
||||
|
||||
try:
|
||||
page.goto("https://fs.szfx.com/MMS", wait_until="domcontentloaded", timeout=45000)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print("打开 MMS 失败:", exc)
|
||||
|
||||
# 停留在订单页,观察 60 秒,看是否有周期请求或 WebSocket 推消息
|
||||
for _ in range(6):
|
||||
page.wait_for_timeout(10000)
|
||||
print(f" +{(len(reqs))} 请求累计 {len(reqs)},WS {len(ws_urls)}")
|
||||
|
||||
print("\n=== WebSocket ===")
|
||||
for u in set(ws_urls):
|
||||
print(" ", u[:160])
|
||||
|
||||
print("\n=== 订单/消息相关接口(去重)===")
|
||||
seen = set()
|
||||
for u in reqs:
|
||||
if any(k in u.lower() for k in ("order", "notice", "message", "push", "socket", "notify")):
|
||||
key = u.split("?")[0]
|
||||
if key not in seen:
|
||||
seen.add(key)
|
||||
print(" ", key[:150])
|
||||
|
||||
print("\n=== 高频接口 TOP10(同一路径重复出现=轮询)===")
|
||||
cnt = Counter(u.split("?")[0] for u in reqs)
|
||||
for path, n in cnt.most_common(10):
|
||||
print(f" {n:>3} 次 {path[:130]}")
|
||||
|
||||
print(f"\n总计 {len(reqs)} 个请求,{len(ws_urls)} 个 WebSocket")
|
||||
browser.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user