Spread fleet replicas across extra machines and show message RTT percentiles
Some checks are pending
offline / test (push) Waiting to run

machines.json plus Add-machine UI place copies on the least-loaded host.
Monitor samples processing RTT and displays min, avg, p50, and p90 for
capacity planning. Remote hosts run src/agent.js.
This commit is contained in:
George Lambert 2026-09-11 13:25:05 -04:00
parent 6fbc808bb1
commit b325f6f697
17 changed files with 673 additions and 53 deletions

View file

@ -0,0 +1,42 @@
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { summarizeRtt, RttWindow } from '../src/rtt.js';
import { pickMachine } from '../src/machines.js';
describe('RTT planning stats', () => {
it('computes min, avg, p50, p90 in order', () => {
const s = summarizeRtt([10, 20, 30, 40, 50, 60, 70, 80, 90, 100]);
assert.equal(s.count, 10);
assert.equal(s.minMs, 10);
assert.equal(s.avgMs, 55);
assert.ok(s.p50Ms >= s.minMs && s.p50Ms <= s.p90Ms);
assert.ok(s.p90Ms <= 100);
});
it('empty window is nulls', () => {
const s = new RttWindow().stats();
assert.equal(s.count, 0);
assert.equal(s.minMs, null);
});
});
describe('machine placement', () => {
it('spreads onto the least-loaded eligible host', () => {
const machines = [
{ id: 'a', enabled: true, capacity: 4, roles: ['*'] },
{ id: 'b', enabled: true, capacity: 4, roles: ['*'] },
];
const instances = [{ machine: 'a', pid: 1 }];
const pick = pickMachine(machines, instances, 'tree-node', 'tree-node');
assert.equal(pick.id, 'b');
});
it('skips machines that do not allow the role', () => {
const machines = [
{ id: 'edge', enabled: true, capacity: 8, roles: ['zappier-edge'] },
{ id: 'trees', enabled: true, capacity: 8, roles: ['tree-node'] },
];
const pick = pickMachine(machines, [], 'tree-node', 'tree-node');
assert.equal(pick.id, 'trees');
});
});