Files
ykxmz/_tests/bench_agent.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

134 lines
4.5 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 -*-
"""量一下被控端的实际性能,别凭感觉优化。
要测:
1. 截屏一帧要多久(不同质量/宽度)
2. 编码一帧要多久
3. 空闲时 CPU / 内存
4. 各种质量档位下的字节数(影响传输耗时)
"""
from __future__ import annotations
import io
import os
import statistics
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "windows"))
import psutil # noqa: E402
def bench_capture(quality: int, width: int, rounds: int = 12):
from PIL import ImageGrab
times = []
sizes = []
for _ in range(rounds):
start = time.perf_counter()
shot = ImageGrab.grab()
if width and shot.width > width:
ratio = width / shot.width
shot = shot.resize((width, int(shot.height * ratio)),
ImageGrab.grab().resize.__self__.__class__ and 1
or 1)
buffer = io.BytesIO()
shot.convert("RGB").save(buffer, format="JPEG", quality=quality)
times.append((time.perf_counter() - start) * 1000)
sizes.append(len(buffer.getvalue()))
return times, sizes
def bench_resize_and_encode(quality: int, width: int, rounds: int = 12):
"""先截一次,反复测 缩放+编码 的耗时(隔离出真正的开销)。"""
from PIL import Image, ImageGrab
base = ImageGrab.grab()
times = []
sizes = []
for _ in range(rounds):
start = time.perf_counter()
shot = base
if width and base.width > width:
ratio = width / base.width
shot = base.resize((width, int(base.height * ratio)), Image.LANCZOS)
buffer = io.BytesIO()
shot.convert("RGB").save(buffer, format="JPEG", quality=quality)
times.append((time.perf_counter() - start) * 1000)
sizes.append(len(buffer.getvalue()))
return times, sizes
def main() -> int:
from PIL import Image
screen = Image.new("RGB", (1, 1))
try:
from PIL import ImageGrab
base = ImageGrab.grab()
screen = base
except Exception as exc: # noqa: BLE001
print(f" 截屏失败: {exc}")
return 1
print(f" 屏幕: {screen.width}x{screen.height}")
proc = psutil.Process(os.getpid())
print(f" 基准进程内存: {proc.memory_info().rss / 1024 / 1024:.1f} MB")
print()
print("=" * 66)
print(" 一、纯截屏耗时(ImageGrab)")
print("=" * 66)
times = []
for _ in range(15):
start = time.perf_counter()
ImageGrab.grab()
times.append((time.perf_counter() - start) * 1000)
times.sort()
print(f" 平均 {statistics.mean(times):6.1f} ms 中位 {statistics.median(times):6.1f} ms "
f"最快 {times[0]:6.1f} 最慢 {times[-1]:6.1f}")
print(f" -> 理论上限约 {1000 / statistics.median(times):.1f} 帧/秒")
print()
print("=" * 66)
print(" 二、缩放 + JPEG 编码耗时(截屏不算)")
print("=" * 66)
print(f" {'宽度':>6} {'质量':>5} {'中位耗时':>10} {'大小':>10} {'理论帧率':>10}")
for width in (0, 1280, 960, 800):
for quality in (75, 55, 40):
t, s = bench_resize_and_encode(quality, width)
median = statistics.median(t)
print(f" {str(width or '原始'):>6} {quality:>5} {median:>9.1f}ms "
f"{statistics.mean(s) / 1024:>9.1f}KB {1000 / median:>9.1f}")
print()
print("=" * 66)
print(" 三、整条链路(截屏 + 缩放 + 编码)")
print("=" * 66)
for width, quality in ((0, 75), (1280, 75), (960, 60), (800, 50)):
t, s = bench_capture(quality, width)
median = statistics.median(t)
print(f" 宽度 {str(width or '原始'):>5} 质量 {quality:>3}: "
f"{median:>7.1f}ms/帧 -> {1000 / median:>5.1f} 帧/秒, "
f"{statistics.mean(s) / 1024:.0f}KB/帧, "
f"{statistics.mean(s) / 1024 * 1000 / median * 8 / 1000:.1f} Mbps")
print()
print("=" * 66)
print(" 四、当前默认设置是多少")
print("=" * 66)
from lanremote.config import Store
import tempfile
store = Store(Path(tempfile.mkdtemp()))
for key in ("image_width", "image_quality", "screen_fps",
"screen_quality", "screen_width", "screen_scale"):
value = store.get(key)
if value is not None:
print(f" {key} = {value}")
return 0
if __name__ == "__main__":
sys.exit(main())