mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 14:50:45 +00:00
琚帶绔?- 淇 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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
112 lines
4.4 KiB
Python
112 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""把 ha-connections=1 定稿(写进 install.sh 和说明)。
|
||
|
||
实测全过程(同一条 4G 线路):
|
||
链路好的时候:
|
||
ha=4 -> 9/10(而且只成功注册 1 条,其余一直握手超时)
|
||
ha=2 -> 10/10
|
||
ha=1 -> 10/10
|
||
链路退化的时候(18 次断开 / 20 次 quic 错误):
|
||
ha=2 -> 0/10 (一条一直失败重试,把另一条也拖下水)
|
||
ha=1 -> 15/15 + 10/10,100%
|
||
|
||
结论:**ha=1 最稳**。这条线路对并发 UDP 很敏感,
|
||
多一条连接不是多一份冗余,而是多一份争抢。
|
||
冗余交给看门狗(断了 30-60 秒内重启)比交给并发连接更靠谱。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
||
INSTALL = ROOT / "relay" / "install.sh"
|
||
PKG = ROOT / "_build" / "package_remote.py"
|
||
|
||
INSTALL_OLD = '''# 连接数:ha-connections=2。
|
||
# 默认是 4,但实测这条线路上 4 条并发 QUIC 握手会互相挤,
|
||
# 只成功 1 条、可用率 9/10;降到 2 条后 10/10,
|
||
# 而且仍有冗余(连两个不同边缘节点)。
|
||
ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate \\
|
||
--edge-ip-version 4 --ha-connections 2 --retries 5 \\
|
||
--url http://127.0.0.1:8080'''
|
||
|
||
INSTALL_NEW = '''# 连接数:ha-connections=1。
|
||
# 默认是 4。实测这条线路对并发 UDP 很敏感:
|
||
# 链路好时 ha=4 -> 9/10(只成功注册 1 条);
|
||
# ha=2 -> 10/10;ha=1 -> 10/10
|
||
# 链路差时 ha=2 -> 0/10(一条失败重试把另一条也拖下水)
|
||
# ha=1 -> 15/15 + 10/10,100%
|
||
# 多一条连接不是多一份冗余,而是多一份争抢。
|
||
# 冗余交给看门狗(断了 30-60 秒内重启)更靠谱。
|
||
ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate \\
|
||
--edge-ip-version 4 --ha-connections 1 --retries 5 \\
|
||
--url http://127.0.0.1:8080'''
|
||
|
||
PKG_OLD = ''' --ha-connections 2 并发连接数'''
|
||
PKG_NEW = ''' --ha-connections 1 并发连接数'''
|
||
|
||
PKG_OLD2 = ''' ③ 连接数:默认 4,但这条线路上 4 条并发 QUIC 握手会互相挤,
|
||
只成功 1 条、可用率 9/10。降到 2 条后 10/10,
|
||
定稿后连打 30 次 29/30 成功、0 次断开。'''
|
||
|
||
PKG_NEW2 = ''' ③ 连接数:用 1(默认是 4)。这条线路对并发 UDP 很敏感:
|
||
链路好时 ha=4 只成功注册 1 条(9/10),ha=2 是 10/10;
|
||
链路退化时 ha=2 掉到 0/10(一条失败重试把另一条也拖下水),
|
||
而 ha=1 是 15/15 + 10/10(100%)。
|
||
多一条连接不是多一份冗余,而是多一份争抢。
|
||
冗余交给看门狗(每 30 秒查一次,断了就重启)更靠谱。'''
|
||
|
||
|
||
def main() -> int:
|
||
ok = True
|
||
|
||
text = INSTALL.read_text(encoding="utf-8")
|
||
if "--ha-connections 1" in text:
|
||
print(" install.sh: 已经是 ha=1")
|
||
elif INSTALL_OLD in text:
|
||
text = text.replace(INSTALL_OLD, INSTALL_NEW, 1)
|
||
INSTALL.write_text(text, encoding="utf-8", newline="\n")
|
||
print(" install.sh: 连接数改成 1")
|
||
else:
|
||
print(" [失败] install.sh 锚点没找到")
|
||
for line in text.splitlines():
|
||
if "ExecStart" in line and "cloudflared" in line:
|
||
print(f" 实际: {line.strip()[:100]}")
|
||
ok = False
|
||
|
||
text = PKG.read_text(encoding="utf-8")
|
||
changed = 0
|
||
for old, new in ((PKG_OLD, PKG_NEW), (PKG_OLD2, PKG_NEW2)):
|
||
if old in text:
|
||
text = text.replace(old, new, 1)
|
||
changed += 1
|
||
if changed:
|
||
PKG.write_text(text, encoding="utf-8", newline="\n")
|
||
print(f" package_remote.py: 说明改了 {changed} 处")
|
||
else:
|
||
print(" package_remote.py: 说明已经改过")
|
||
|
||
# LF / 语法
|
||
raw = INSTALL.read_bytes()
|
||
if b"\r\n" in raw:
|
||
INSTALL.write_bytes(raw.replace(b"\r\n", b"\n"))
|
||
print(" install.sh: 修了 CRLF")
|
||
|
||
import ast
|
||
try:
|
||
ast.parse(PKG.read_text(encoding="utf-8"))
|
||
print(" package_remote.py 语法 OK")
|
||
except SyntaxError as exc:
|
||
print(f" 语法错误: {exc}")
|
||
ok = False
|
||
|
||
for line in INSTALL.read_text(encoding="utf-8").splitlines():
|
||
if "ExecStart" in line and "cloudflared" in line:
|
||
print(f" install.sh 现在: {line.strip()[:110]}")
|
||
return 0 if ok else 1
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|