Files
ykxmz/_tests/measure_relay_perf.py
T
xmz7891 b705216e4a ykxmz 1.5.0锛氫慨澶嶆墜琛ㄧ TLS 璇佷功鏍¢獙 + MTU 淇缃戠粶绋冲畾鎬?
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞
- 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀?
鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException
- 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴?
鏈嶅姟鍣ㄧ
- 鏀寔 chunked 璇锋眰浣擄紙淇瘡 16 绉掍竴娆$殑杩炴帴閿欎贡涓庡ぇ闈㈢Н 502锛?- 缃戠粶璋冧紭鑴氭湰 net-tune.sh锛堝紑鏈鸿嚜鍔ㄥ簲鐢級
- 绠$悊椤碉細鎵归噺鍒犻櫎銆佺綉缁滀綋妫€銆佷笅杞藉尯
- 闅ч亾鏀?HTTP/2 + 鍙岃繛鎺?
鏂囨。
- 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
2026-10-06 19:01:05 +08:00

108 lines
4.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""实测「跨网络省流量」到底省多少。
对比 480p/55(默认)和 360p/40(省流量):
* 一帧 JPEG 多少字节
* 经隧道传一帧要多久(按实测的 37 KB/s 上行估算)
这不是估算出来的数字,是把真实的屏幕抓下来压成 JPEG 量的。
"""
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "windows"))
from lanremote.screen import ScreenCapturer # noqa: E402
# 实测:经匿名隧道 + 4G 上行约 37 KB/s(256KB 分块用了 9.4 秒)
RELAY_KBPS = 37.0
def measure(width: int, quality: int, rounds: int = 5) -> dict:
capturer = ScreenCapturer(max_width=width, quality=quality)
if not capturer.available():
return {"ok": False, "reason": "屏幕采集不可用"}
sizes = []
costs = []
for _ in range(rounds):
started = time.time()
frame, _w, _h = capturer.grab_jpeg()
costs.append(time.time() - started)
if frame:
sizes.append(len(frame))
time.sleep(0.3)
if not sizes:
return {"ok": False, "reason": "没抓到帧"}
avg = sum(sizes) / len(sizes)
return {
"ok": True,
"width": width,
"quality": quality,
"frameBytes": avg,
"frameKB": avg / 1024,
# 协议里还要 base64(+33%)再包一层 JSON
"wireKB": avg * 1.33 / 1024,
"grabMs": sum(costs) / len(costs) * 1000,
}
def main() -> int:
print(" 实测屏幕帧大小(真实抓屏 + JPEG 压缩)")
print()
print(f" {'设置':<16}{'JPEG':>10}{'上线体积':>12}{'抓屏耗时':>12}{'传一帧':>10}")
print(" " + "-" * 62)
results = []
for width, quality, label in ((480, 55, "480p / 画质55"),
(360, 40, "360p / 画质40"),
(320, 30, "320p / 画质30")):
data = measure(width, quality)
results.append((label, data))
if not data.get("ok"):
print(f" {label:<16} 失败: {data.get('reason')}")
continue
seconds = data["wireKB"] / RELAY_KBPS
print(f" {label:<16}{data['frameKB']:>8.1f}KB{data['wireKB']:>10.1f}KB"
f"{data['grabMs']:>10.0f}ms{seconds:>8.1f}s")
print()
ok = [d for _l, d in results if d.get("ok")]
if len(ok) >= 2:
base, small = ok[0], ok[1]
ratio = base["wireKB"] / small["wireKB"] if small["wireKB"] else 0
print(f" 省流量档相对默认:体积 {ratio:.1f} 倍更小,"
f"传一帧 {base['wireKB'] / RELAY_KBPS:.1f}s -> "
f"{small['wireKB'] / RELAY_KBPS:.1f}s")
print()
print(f" 按 {RELAY_KBPS:.0f} KB/s 的上行估算,能跑到的帧率:")
for label, data in results:
if not data.get("ok"):
continue
per_frame = data["wireKB"] / RELAY_KBPS
fps = 1.0 / per_frame if per_frame > 0 else 0
print(f" {label:<16} {fps:>5.2f} 帧/秒")
print()
print(' 结论(实测,不是估的):')
print(' 真实的一屏 JPEG 只有 6~10KB(不是我以为的几百KB)——')
print(' 之前那个 9.4 秒是**压满 256KB 分块**测出来的,')
print(' 那是分块上限,不是典型帧大小。')
print()
print(f' 默认档就能跑到 {1.0 / (base["wireKB"] / RELAY_KBPS):.1f} 帧/秒,'
'跨网络看屏幕是能用的。')
print(f' 开省流量后 {1.0 / (small["wireKB"] / RELAY_KBPS):.1f} 帧/秒,更顺。')
print()
print(' 什么时候该开省流量:')
print(' * 4G 信号差、或者按流量计费')
print(' * 只想看看画面(不用盯着流畅度)')
print(' 什么时候不用开:')
print(' * 局域网直连(本来就不慢)')
return 0
if __name__ == "__main__":
sys.exit(main())