发问准备可以并行,三个开关先保持关闭(BUG-1337~1339)
开流前的注销检查可以和读会话、解析模型同时进行;审核改到扣点前等待,不再挡住第一行;模型版本可以短缓存;两个领域可以一起算。本机没有数据库中位数,也没有带星盘网络库的镜像,所以默认仍是关闭、缓存 0、领域逐个算。 自测:tsc 0 错;lint 0 error;相关测试失败 0、取消 0。test:db 未跑。 Co-Authored-By: Grok (agent loop)
This commit is contained in:
co-authored by
Grok (agent loop)
parent
66cd60081f
commit
a0e223e20c
@@ -0,0 +1,24 @@
|
||||
"""Two-domain concurrency bench.
|
||||
|
||||
The vedastro image and the local API were not started in this round.
|
||||
The task book's draft on one public chart was about 10 percent faster when
|
||||
cold and slower when the chart was already cached. The switch opens only
|
||||
when the vedastro image is at least 25 percent faster, contention 429s do
|
||||
not rise, and the byte diff matches. Default stays 1.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print("CONSULT_DOMAIN_CONCURRENCY default stays 1")
|
||||
print("vedastro image bench: not run")
|
||||
print("local API bench: not run")
|
||||
print("contention 429 count: not run")
|
||||
print("byte diff: not run")
|
||||
print("reason: this round has no vedastro measurement; the published draft missed the 25 percent gate")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* In-process overlap check for consult preparation.
|
||||
*
|
||||
* This does not measure local Postgres. Those medians were not collected,
|
||||
* so the switches stay at their code defaults.
|
||||
*/
|
||||
import { register } from "node:module";
|
||||
|
||||
await register(new URL("../../tests/support/stub-server-only.mjs", import.meta.url).href, import.meta.url);
|
||||
const { loadConsultTurnHead } = await import("../../src/lib/consult/turn-prep.ts");
|
||||
|
||||
const delays = { deletion: 50, session: 80, model: 80 };
|
||||
|
||||
async function run(parallel: boolean) {
|
||||
let now = 0;
|
||||
const waiters: Array<{ at: number; resolve: () => void }> = [];
|
||||
let finished = false;
|
||||
let inFlight = 0;
|
||||
let maxInFlight = 0;
|
||||
function sleep(ms: number) {
|
||||
return new Promise<void>((resolve) => {
|
||||
waiters.push({ at: now + ms, resolve });
|
||||
});
|
||||
}
|
||||
async function occupy(ms: number) {
|
||||
inFlight += 1;
|
||||
maxInFlight = Math.max(maxInFlight, inFlight);
|
||||
await sleep(ms);
|
||||
inFlight -= 1;
|
||||
}
|
||||
const pending = loadConsultTurnHead({
|
||||
parallel,
|
||||
getUser: async () => ({ data: { user: { id: "user-1" } }, error: null }),
|
||||
readPendingDeletion: () => occupy(delays.deletion).then(() => null),
|
||||
readBody: async () => ({ success: true as const, data: { sessionId: "s", modelId: "m" } }),
|
||||
readSession: () => occupy(delays.session).then(() => ({
|
||||
data: { model_id: "m", model_config_version: 2, session_type: "consultation" },
|
||||
error: null,
|
||||
})),
|
||||
resolveModel: () => occupy(delays.model).then(() => ({ id: "m" })),
|
||||
}).then((head) => {
|
||||
finished = true;
|
||||
return head;
|
||||
});
|
||||
for (let guard = 0; guard < 40 && !finished; guard += 1) {
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
if (!waiters.length) continue;
|
||||
waiters.sort((left, right) => left.at - right.at);
|
||||
now = waiters[0]!.at;
|
||||
const due: Array<() => void> = [];
|
||||
while (waiters.length && waiters[0]!.at <= now) due.push(waiters.shift()!.resolve);
|
||||
for (const resolve of due) resolve();
|
||||
}
|
||||
if (!finished) throw new Error("clock did not settle");
|
||||
const head = await pending;
|
||||
if (!head.ok) throw new Error("head failed");
|
||||
return { elapsed: now, maxInFlight };
|
||||
}
|
||||
|
||||
const on = await run(true);
|
||||
const off = await run(false);
|
||||
const report = {
|
||||
kind: "logical-clock",
|
||||
delays,
|
||||
parallelElapsed: on.elapsed,
|
||||
serialElapsed: off.elapsed,
|
||||
parallelMaxInFlight: on.maxInFlight,
|
||||
serialMaxInFlight: off.maxInFlight,
|
||||
postgresMedians: "not-measured",
|
||||
aliyunKey: "absent",
|
||||
moderationSimulationMs: [300, 1500],
|
||||
decision: {
|
||||
CONSULT_PREP_PARALLEL: "off",
|
||||
MODEL_VERSION_CACHE_TTL_MS: 0,
|
||||
reason: "开启条件要求本机 Postgres 中位数。本轮没有量到,默认保持关闭。",
|
||||
},
|
||||
};
|
||||
console.log(JSON.stringify(report));
|
||||
Reference in New Issue
Block a user