Skip to content

Commit c5f1734

Browse files
committed
test(webapp): sample benchmark ELU as a per-window delta and build poison JSON iteratively
The ELU monitor called eventLoopUtilization() with no args, which returns the cumulative average since thread start, so each sample smoothed out the spikes the percentile stats are meant to catch; sample the delta between consecutive readings instead. The benchmark producer now builds the deeply nested poison JSON as a string iteratively (and validates the depth) so it does not depend on runtime-specific deep JSON.stringify support.
1 parent fc94129 commit c5f1734

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

apps/webapp/test/runsReplicationBenchmark.producer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ interface ProducerConfig {
1919
poisonDepth?: number;
2020
}
2121

22-
function deeplyNestedOutput(depth: number): Record<string, unknown> {
23-
let node: Record<string, unknown> = { leaf: 1 };
24-
for (let i = 0; i < depth; i++) {
25-
node = { [`k${i}`]: node };
22+
function deeplyNestedJson(depth: number): string {
23+
const safeDepth = Number.isSafeInteger(depth) && depth >= 0 ? depth : 0;
24+
const open: string[] = [];
25+
for (let i = 0; i < safeDepth; i++) {
26+
open.push(`{"k${i}":`);
2627
}
27-
return node;
28+
return open.join("") + '{"leaf":1}' + "}".repeat(safeDepth);
2829
}
2930

3031
// Error templates for realistic variety
@@ -158,7 +159,7 @@ async function runProducer(config: ProducerConfig) {
158159
}
159160

160161
if (isPoison) {
161-
runData.output = JSON.stringify(deeplyNestedOutput(poisonDepth));
162+
runData.output = deeplyNestedJson(poisonDepth);
162163
runData.outputType = "application/json";
163164
poisoned++;
164165
}

apps/webapp/test/runsReplicationJsonRecoveryBenchmark.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ class ELUMonitor {
2727

2828
start(intervalMs = 100) {
2929
this.samples = [];
30-
performance.eventLoopUtilization();
30+
let last = performance.eventLoopUtilization();
3131
this.interval = setInterval(() => {
32-
this.samples.push(performance.eventLoopUtilization().utilization * 100);
32+
const current = performance.eventLoopUtilization();
33+
this.samples.push(performance.eventLoopUtilization(current, last).utilization * 100);
34+
last = current;
3335
}, intervalMs);
3436
}
3537

0 commit comments

Comments
 (0)