perf(全链路): 连接池/事务边界/轮询与 IO 效率收口
Java: - LLM 180s 读超时不再被全局 call-timeout 静默截断成 90s(长思考请求被掐断→重试→付费网关二次计费) - 代理 HttpClient 缓存改有界 LRU(jikip 每次提取新 IP,无界缓存持续泄漏 selector 线程与连接池) - 12 个 service 的 Redis 任务锁移出 @Transactional(自旋最坏 10s 白占 DB 连接,池仅 30),远端对象删/传改 afterCommit - 结果文件 Job 闸门拒绝时不再回退内联执行(改重新入队,避免把背压转嫁给 MQ 消费线程) - imagevideo 每秒扫描加列投影、过期清理加 LIMIT;权限页整表查询改列投影(不再拉回密码哈希) - 哈希改 HexFormat;补 5 处"不能改"的技术依据注释(批量插入会丢回填主键、流式丢模板与图片等) 前端:4 个工具页轮询改轻量端点(带 fallback);PriceTrack 快照节流写盘;候选店铺表分页;页面隐藏时停表 客户端:HTTP 连接池按出口复用(Session 仍每请求新建,保持无跨请求状态);品牌检测 WIPO 逐请求握手; 代理配置按 mtime 缓存;串行任务改专属池;异常降级为标签页重连;紫鸟启动改端口轮询;模板编译缓存; 日志上报连接与落盘收口;Flask 版本 API 改按请求复用连接
This commit is contained in:
@@ -57,6 +57,8 @@ interface VisibilityHarness {
|
||||
loop: ReturnType<typeof useTaskProgressLoop<{ taskId?: number; status?: string }>>
|
||||
doc: FakeDoc
|
||||
sink: TimerSinkEntry[]
|
||||
/** 被 clearTimeout 取消过的定时器 id(用于断言隐藏时确实停了表) */
|
||||
cleared: unknown[]
|
||||
fetchCount: () => number
|
||||
}
|
||||
|
||||
@@ -72,6 +74,7 @@ async function makeVisibilityLoop(
|
||||
}
|
||||
const doc = installFakeDocument(visibility)
|
||||
const sink: TimerSinkEntry[] = []
|
||||
const cleared: unknown[] = []
|
||||
const storage = new Map<string, string>()
|
||||
let fetchCount = 0
|
||||
;(globalThis as Record<string, unknown>).window = {
|
||||
@@ -84,7 +87,10 @@ async function makeVisibilityLoop(
|
||||
sink.push({ fn, ms })
|
||||
return globalThis.setTimeout(fn, ms)
|
||||
},
|
||||
clearTimeout: (id: unknown) => globalThis.clearTimeout(id as number),
|
||||
clearTimeout: (id: unknown) => {
|
||||
cleared.push(id)
|
||||
globalThis.clearTimeout(id as number)
|
||||
},
|
||||
setInterval: (fn: () => void, ms: number) => globalThis.setInterval(fn, ms),
|
||||
clearInterval: (id: unknown) => globalThis.clearInterval(id as number),
|
||||
}
|
||||
@@ -98,7 +104,7 @@ async function makeVisibilityLoop(
|
||||
extractStatus: (d) => d?.status,
|
||||
})
|
||||
loop.reset([1])
|
||||
return { loop, doc, sink, fetchCount: () => fetchCount }
|
||||
return { loop, doc, sink, cleared, fetchCount: () => fetchCount }
|
||||
}
|
||||
|
||||
test('test_hidden_long_interval', async () => {
|
||||
@@ -187,3 +193,35 @@ test('test_hidden_no_immediate_refresh', async () => {
|
||||
h.loop.dispose()
|
||||
cleanupDocument()
|
||||
})
|
||||
|
||||
test('test_hidden_stops_polling', async () => {
|
||||
const h = await makeVisibilityLoop('visible')
|
||||
await tick(10)
|
||||
const scheduledBefore = h.sink.length
|
||||
const before = h.fetchCount()
|
||||
h.doc.setVisibility('hidden')
|
||||
h.doc.dispatch('visibilitychange')
|
||||
await tick(10)
|
||||
assert.equal(h.fetchCount(), before, '隐藏后不再发起请求')
|
||||
assert.equal(h.sink.length, scheduledBefore, '隐藏后不再排定新的轮询定时器')
|
||||
assert.ok(h.cleared.length > 0, '隐藏时清掉了已排定的轮询定时器')
|
||||
h.loop.dispose()
|
||||
cleanupDocument()
|
||||
})
|
||||
|
||||
test('test_visible_restarts_polling', async () => {
|
||||
const h = await makeVisibilityLoop('visible')
|
||||
await tick(10)
|
||||
h.doc.setVisibility('hidden')
|
||||
h.doc.dispatch('visibilitychange')
|
||||
await tick(10)
|
||||
const before = h.fetchCount()
|
||||
h.doc.setVisibility('visible')
|
||||
h.doc.dispatch('visibilitychange')
|
||||
await tick(10)
|
||||
assert.equal(h.fetchCount(), before + 1, '恢复可见立即补拉一轮')
|
||||
assert.equal(h.sink.at(-1)?.ms, TASK_POLL_VISIBLE_INTERVAL_MS, '恢复可见后按可见间隔重启轮询')
|
||||
assert.deepEqual(h.loop.taskIds.value, [1], '停表期间任务集合不变')
|
||||
h.loop.dispose()
|
||||
cleanupDocument()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user