0.2.88
This commit is contained in:
1 parent
df403c0aa7
commit
9e133628e5
17 files changed
+270
-34
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { performance } from 'node:perf_hooks';
|
||||
// Deterministic broadcast/access-check simulation. Not a live WebSocket/DB benchmark.
|
||||
const durationSeconds = 10;
|
||||
const editsPerUserPerSecond = 2;
|
||||
for (const users of [5, 100, 300, 500]) {
|
||||
const checks = new Int32Array(users);
|
||||
const lastCheckSecond = new Int32Array(users).fill(-1);
|
||||
const start = performance.now();
|
||||
let fanouts = 0;
|
||||
for (let second = 0; second < durationSeconds; second++) {
|
||||
for (let event = 0; event < users * editsPerUserPerSecond; event++) {
|
||||
for (let recipient = 0; recipient < users; recipient++) {
|
||||
fanouts++;
|
||||
if (lastCheckSecond[recipient] !== second) {
|
||||
checks[recipient]++;
|
||||
lastCheckSecond[recipient] = second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const optimized = checks.reduce((a,b) => a+b, 0);
|
||||
const baseline = fanouts;
|
||||
assert.equal(optimized, users * durationSeconds);
|
||||
assert.ok(optimized <= baseline);
|
||||
console.log(`${users} clients | ${fanouts.toLocaleString('en-US')} broadcast deliveries | auth reads: ${baseline.toLocaleString('en-US')} -> ${optimized.toLocaleString('en-US')} | reduction ${(100*(1-optimized/baseline)).toFixed(2)}% | simulation ${(performance.now()-start).toFixed(1)} ms`);
|
||||
}
|
||||
Reference in new issue
Block a user