feat(sniper): 将预热提前量调优至 10 秒并设为异步安全默认

- 预热时序重构:WarmupLead 从 2s 延长至 10s,ResyncLead 从 3s 延长至 15s;开抢前 10s 开始异步建连,开抢前 5s 全部就绪待命
- 兼顾零建连延迟与发令安全:既彻底杜绝了 2s 极限时间被慢网络超时拖垮发车的问题,又保留了首发 0 建连耗时的长连接极速优势
- 默认配置:Prewarm 恢复为默认开启,并在界面增加明确的调度行为提示
- 验证方式:go test ./... -count=1 全通,npm run build 构建通过
This commit is contained in:
yml2213
2026-10-17 18:36:39 +08:00
parent 6e5beac151
commit a135effd7a
4 changed files with 10 additions and 20 deletions
+1 -1
View File
@@ -308,7 +308,7 @@ func (a *App) DefaultConfig() Config {
Concurrency: 2,
StopAfterSuccess: false,
StopAccountAfterSuccess: true,
Prewarm: false,
Prewarm: true,
DirectExchange: true,
SharePrizeList: true,
AutoSelect: false,
+2 -2
View File
@@ -76,8 +76,8 @@ func TestDefaultConfigUsesWindowMode(t *testing.T) {
if cfg.Concurrency != 2 {
t.Fatalf("Concurrency=%d, want 2(降低多开时的请求洪峰)", cfg.Concurrency)
}
if cfg.Prewarm {
t.Fatal("Prewarm 应默认关闭,避免开抢前因单账号建连超时阻塞")
if !cfg.Prewarm {
t.Fatal("Prewarm 应默认开启(提前 10 秒异步预热,不阻塞发令枪)")
}
}
+5 -6
View File
@@ -15,14 +15,13 @@ const MinTriggerAdvance = 50 * time.Millisecond
const (
// WarmupLead 是预热连接相对开抢时刻的提前量。
//
// 2 秒足够建连 + 握手(实测单账号建连约 300ms),又不会让连接闲置太久:
// 旧实现一启动就预热、然后干等几十分钟,连接是否还活着只能靠运气。
WarmupLead = 2 * time.Second
// 提前 10 秒开始预热连接:为 30+ 账号留足 3~5 秒平滑建连缓冲,开抢前 5 秒全部就绪;
// 既享受长连接 0 延迟首发,又能在开抢前形成静默隔离带,绝不阻塞整点发车。
WarmupLead = 10 * time.Second
// ResyncLead 是「临近复校」相对开抢时刻的提前量。
//
// 只做一次校准是不够的:pc-1/pc-2/pc-3 三台机器的本机偏移分别是 ≈0 / -370ms / +900ms,
// 而且本机时钟在等待期间还会漂移。触发前 3 秒再校准一次,能把这部分误差压掉。
ResyncLead = 3 * time.Second
// 提前 15 秒复校时钟:在预热前完成服务端时钟校准,排定精确的预热与触发时刻。
ResyncLead = 15 * time.Second
)
// TriggerPlan 描述一次定时抢购的关键时刻(全部是「本机时钟」下的时刻)。