Spread fleet replicas across extra machines and show message RTT percentiles
Some checks are pending
offline / test (push) Waiting to run
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:
parent
6fbc808bb1
commit
b325f6f697
17 changed files with 673 additions and 53 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { describe, it, after } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { loadFleet, listServices } from '../src/load.js';
|
||||
import { loadFleet, listServices, FLEET_ROOT } from '../src/load.js';
|
||||
import { Supervisor } from '../src/supervisor.js';
|
||||
import { Monitor } from '../src/monitor.js';
|
||||
|
||||
function treeOnly(healthBase) {
|
||||
const loaded = loadFleet();
|
||||
const loaded = loadFleet(FLEET_ROOT, { overlay: false });
|
||||
for (const s of Object.values(loaded.services)) {
|
||||
s.enabled = s.id === 'tree-node';
|
||||
if (s.id === 'tree-node') {
|
||||
|
|
@ -15,6 +15,13 @@ function treeOnly(healthBase) {
|
|||
s.ports = { healthBase };
|
||||
}
|
||||
}
|
||||
loaded.machinesOverlay = null;
|
||||
loaded.machines = loaded.machines.filter((m) => m.kind === 'local' && m.enabled);
|
||||
if (!loaded.machines.length) {
|
||||
loaded.machines = [
|
||||
{ id: 'local', title: 'local', kind: 'local', host: '127.0.0.1', enabled: true, capacity: 32, roles: ['*'] },
|
||||
];
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
|
||||
|
|
@ -96,4 +103,39 @@ describe('verae-fleet', () => {
|
|||
assert.equal(st.available, 3);
|
||||
assert.ok(st.instances.some((i) => i.id === 'tree-node-2' || i.id === 'tree-node-0'));
|
||||
});
|
||||
|
||||
it('spreads replicas across two defined machines', async () => {
|
||||
const loaded = treeOnly(15100);
|
||||
loaded.services['tree-node'].min = 4;
|
||||
loaded.services['tree-node'].max = 6;
|
||||
loaded.machines = [
|
||||
{ id: 'rack-a', title: 'A', kind: 'local', host: '127.0.0.1', enabled: true, capacity: 8, roles: ['*'] },
|
||||
{ id: 'rack-b', title: 'B', kind: 'local', host: '127.0.0.1', enabled: true, capacity: 8, roles: ['*'] },
|
||||
];
|
||||
const sup = new Supervisor({ loaded });
|
||||
supervisors.push(sup);
|
||||
await sup.startService('tree-node');
|
||||
const hosts = new Set(sup.status().services['tree-node'].instances.map((i) => i.machine));
|
||||
assert.ok(hosts.has('rack-a') && hosts.has('rack-b'), `hosts ${[...hosts]}`);
|
||||
const machines = sup.status().machines;
|
||||
assert.equal(machines.length, 2);
|
||||
assert.ok(machines.every((m) => m.running >= 1));
|
||||
});
|
||||
|
||||
it('records message-processing RTT percentiles', async () => {
|
||||
const loaded = treeOnly(15200);
|
||||
loaded.services['tree-node'].min = 1;
|
||||
loaded.services['tree-node'].max = 2;
|
||||
const sup = new Supervisor({ loaded });
|
||||
supervisors.push(sup);
|
||||
await sup.startService('tree-node');
|
||||
const rec = [...sup.instances.values()][0];
|
||||
for (let i = 0; i < 8; i += 1) await sup.probe(rec);
|
||||
const rtt = rec.rtt;
|
||||
assert.ok(rtt.count >= 8, `count ${rtt.count}`);
|
||||
assert.ok(rtt.minMs <= rtt.p50Ms && rtt.p50Ms <= rtt.p90Ms);
|
||||
const svc = sup.status().services['tree-node'].rtt;
|
||||
assert.ok(svc.count >= 8);
|
||||
assert.ok(svc.minMs != null && svc.avgMs != null);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
42
packages/verae-fleet/test/rtt.test.js
Normal file
42
packages/verae-fleet/test/rtt.test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue