Skip to content

Commit 40dcd79

Browse files
fix(pubsub-bench): unblock scale fanout sims (#650)
1 parent fdb0ec2 commit 40dcd79

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

packages/transport/pubsub/benchmark/fanout-tree-sim-lib.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,22 @@ export const runFanoutTreeSim = async (
484484
});
485485

486486
const bootstrapIndexSet = new Set<number>(bootstrapIndices);
487+
// Sim-only connection caps must account for tracker/bootstrap fan-in. Capping those
488+
// peers near the overlay degree works for small runs, but at 5k+ it starves join
489+
// formation long before the tree itself is saturated.
490+
const rootConnectionCap = Math.max(256, params.rootMaxChildren * 8);
491+
const relayConnectionCap = Math.max(64, params.relayMaxChildren * 4);
492+
const bootstrapConnectionCap = Math.max(
493+
512,
494+
Math.min(
495+
2_048,
496+
Math.ceil((subscriberIndices.length + 1) / Math.max(1, bootstrapIndices.length)),
497+
),
498+
);
487499
const maxConnectionsFor = (index: number) => {
488-
if (index === rootIndex) return 256;
489-
if (bootstrapIndexSet.has(index)) return 128;
490-
if (relaySet.has(index)) return 64;
500+
if (index === rootIndex) return rootConnectionCap;
501+
if (bootstrapIndexSet.has(index)) return bootstrapConnectionCap;
502+
if (relaySet.has(index)) return relayConnectionCap;
491503
return 16;
492504
};
493505
const seenCacheMaxFor = (index: number) => {
@@ -1546,7 +1558,31 @@ export const runFanoutTreeSim = async (
15461558
};
15471559
};
15481560

1549-
const result = await run();
1561+
const abortPromise =
1562+
timeoutMs > 0
1563+
? new Promise<never>((_, reject) => {
1564+
const onAbort = () => {
1565+
timeoutSignal.removeEventListener("abort", onAbort);
1566+
const reason = timeoutSignal.reason;
1567+
reject(
1568+
reason instanceof Error
1569+
? reason
1570+
: new Error(
1571+
typeof reason === "string"
1572+
? reason
1573+
: "fanout-tree-sim aborted",
1574+
),
1575+
);
1576+
};
1577+
if (timeoutSignal.aborted) {
1578+
onAbort();
1579+
return;
1580+
}
1581+
timeoutSignal.addEventListener("abort", onAbort, { once: true });
1582+
})
1583+
: undefined;
1584+
1585+
const result = abortPromise ? await Promise.race([run(), abortPromise]) : await run();
15501586

15511587
if (profileEnabled && profileCpuStart) {
15521588
try {

0 commit comments

Comments
 (0)