Reduce host capacity headroom and remove learned usage padding
This commit is contained in:
@@ -696,6 +696,22 @@ describe('automatic capacity admission and placement', () => {
|
||||
expect(db().prepare('SELECT * FROM ec_host_ports').all()).toEqual([]);
|
||||
expect(db().prepare('SELECT * FROM server_launch_collections').all()).toEqual([]);
|
||||
});
|
||||
it.each([
|
||||
{ resource: 'CPU', measurements: { cpuCount: 4, cpuUsagePercent: 82.5 }, over: { cpuUsagePercent: 82.51 } },
|
||||
{ resource: 'memory', measurements: { memoryAvailable: 1024 ** 3 + 500_000_000 }, over: { memoryAvailable: 1024 ** 3 + 499_999_999 } }
|
||||
])('reserves only the requested host $resource headroom', async ({ measurements, over }) => {
|
||||
await prepareLibrary();
|
||||
const { heartbeat } = await import('../../src/lib/server/hosts/index.js');
|
||||
const { choosePlacement } = await import('../../src/lib/server/hosts/capacity.js');
|
||||
const options = { hostId, libraryId, image };
|
||||
heartbeat(hostId, { ...inventory(), ...measurements });
|
||||
// Includes the new server's 0.5-core / 1-GiB bootstrap reservation.
|
||||
expect(choosePlacement(options).host.id).toBe(hostId);
|
||||
expect(choosePlacement({ ...options, thorough: true }).host.id).toBe(hostId);
|
||||
heartbeat(hostId, { ...inventory(), ...measurements, ...over });
|
||||
expect(() => choosePlacement(options)).toThrow('capacity');
|
||||
expect(() => choosePlacement({ ...options, thorough: true })).toThrow('capacity');
|
||||
});
|
||||
it('uses calibrated footprints to admit more instances than the cold-start allowance', async () => {
|
||||
const first = await queue();
|
||||
const { heartbeat } = await import('../../src/lib/server/hosts/index.js');
|
||||
@@ -786,7 +802,7 @@ describe('automatic capacity admission and placement', () => {
|
||||
await advance();
|
||||
const instance = nativeInstance(first.name)!;
|
||||
// 0.2 GiB OS + 0.8 GiB container. The remaining 0.2 GiB of its 1 GiB
|
||||
// reservation plus a new 1 GiB server fit below 2.5 GiB usable memory.
|
||||
// reservation plus a new 1 GiB server fit below 2.53 GiB usable memory.
|
||||
heartbeat(hostId, { ...host, memoryAvailable: 2 * GiB, instanceResources: [{ instanceId: instance.id,
|
||||
generation: instance.generation, uptimeSeconds: 60, cpuCores: 0.1, memoryBytes: Math.floor(0.8 * GiB) }] });
|
||||
const second = queueNativeCreation(input);
|
||||
@@ -809,7 +825,7 @@ describe('automatic capacity admission and placement', () => {
|
||||
instanceResources: evidence === 'missing' ? [] : [{ instanceId: instance.id, generation: instance.generation + 1,
|
||||
uptimeSeconds: 60, cpuCores: 0.1, memoryBytes: Math.floor(0.8 * GiB) }] });
|
||||
expect(queueNativeCreation(input)).toMatchObject({ ok: false, kind: 'conflict',
|
||||
message: expect.stringContaining('3.00 GiB projected, 2.50 GiB usable') });
|
||||
message: expect.stringContaining('3.00 GiB projected, 2.53 GiB usable') });
|
||||
});
|
||||
it('waits when capacity disappears after admission without sending a create command', async () => {
|
||||
await prepareLibrary();
|
||||
|
||||
Reference in New Issue
Block a user