@hearsay-tools/squawk 0.19.0-dev.9172 → 0.19.0-dev.9180
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ci-wait/controller.d.ts +7 -7
- package/dist/contract/hosts.d.ts +925 -0
- package/dist/contract/index.js +104 -2
- package/dist/core/server-hook-registry.d.ts +13 -0
- package/dist/core/server-hook-registry.js.map +1 -1
- package/dist/delegation/routes.d.ts +78 -78
- package/dist/features/hosts/admission.d.ts +52 -0
- package/dist/features/hosts/admission.js +89 -0
- package/dist/features/hosts/admission.js.map +1 -0
- package/dist/features/hosts/gateway.d.ts +14 -3
- package/dist/features/hosts/gateway.js +35 -21
- package/dist/features/hosts/gateway.js.map +1 -1
- package/dist/features/hosts/index.d.ts +7 -3
- package/dist/features/hosts/index.js +41 -7
- package/dist/features/hosts/index.js.map +1 -1
- package/dist/features/hosts/registry-reconciler.d.ts +41 -0
- package/dist/features/hosts/registry-reconciler.js +168 -0
- package/dist/features/hosts/registry-reconciler.js.map +1 -0
- package/dist/features/hosts/routes.d.ts +414 -48
- package/dist/features/hosts/routes.js +72 -62
- package/dist/features/hosts/routes.js.map +1 -1
- package/dist/features/hosts/runs-index-events.d.ts +23 -0
- package/dist/features/hosts/runs-index-events.js +116 -0
- package/dist/features/hosts/runs-index-events.js.map +1 -0
- package/dist/features/hosts/runs-index-patch.d.ts +203 -0
- package/dist/features/hosts/runs-index-patch.js +798 -0
- package/dist/features/hosts/runs-index-patch.js.map +1 -0
- package/dist/features/hosts/runs-index.d.ts +149 -0
- package/dist/features/hosts/runs-index.js +762 -0
- package/dist/features/hosts/runs-index.js.map +1 -0
- package/dist/features/hosts/runs-search.d.ts +28 -0
- package/dist/features/hosts/runs-search.js +151 -0
- package/dist/features/hosts/runs-search.js.map +1 -0
- package/dist/features/hosts/supervisor.d.ts +4 -0
- package/dist/features/hosts/supervisor.js +14 -6
- package/dist/features/hosts/supervisor.js.map +1 -1
- package/dist/features/reports/routes.d.ts +2 -2
- package/dist/features/webhooks/routes.d.ts +38 -38
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/server/activity-routes.d.ts +23 -23
- package/dist/server/models-routes.d.ts +12 -12
- package/dist/server/project-settings-routes.d.ts +107 -107
- package/dist/server/projects-routes.d.ts +41 -41
- package/dist/server/provider-sign-in-routes.d.ts +2 -2
- package/dist/server/providers-routes.d.ts +58 -58
- package/dist/server/runner-install-routes.d.ts +10 -10
- package/dist/server/runners-routes.d.ts +10 -10
- package/dist/server/runs-routes.d.ts +344 -344
- package/dist/server/server.d.ts +1195 -1195
- package/dist/server/server.js +7 -1
- package/dist/server/server.js.map +1 -1
- package/dist/server/workspace-identity-routes.d.ts +5 -5
- package/dist/server/workspace-live-routes.d.ts +5 -5
- package/dist/server/workspace-routes.d.ts +85 -85
- package/dist/server/workspace-run-feed.d.ts +4 -0
- package/dist/server/workspace-run-feed.js +13 -0
- package/dist/server/workspace-run-feed.js.map +1 -1
- package/package.json +4 -4
- package/scripts/benchmark-hosts-runs-index-probes.ts +242 -0
- package/scripts/benchmark-hosts-runs-index.ts +776 -0
- package/web/dist/assets/accounts-section-BDUoikVg.js +1 -0
- package/web/dist/assets/activity-motion-CYdEr0hu.js +1 -0
- package/web/dist/assets/{activity-route-C2zP5vVV.js → activity-route-D8BPLoZj.js} +1 -1
- package/web/dist/assets/{agent-accounts-D_ZKAmaW.js → agent-accounts-C2ILQhZy.js} +1 -1
- package/web/dist/assets/{agent-config-section-CwK_izpU.js → agent-config-section-BO8w2cry.js} +2 -2
- package/web/dist/assets/agent-defaults-section-BBcv7Vbh.js +1 -0
- package/web/dist/assets/{appearance-DvoRcoRX.js → appearance-yF_NXlq5.js} +1 -1
- package/web/dist/assets/{archive-on-merge-field-DWPtF9dh.js → archive-on-merge-field-Dh1M21D6.js} +1 -1
- package/web/dist/assets/{ask-card-D-om0EtP.js → ask-card-2E9m5VRA.js} +1 -1
- package/web/dist/assets/attention-C7BUdd2s.js +1 -0
- package/web/dist/assets/automations-route-D27bK2j6.js +2 -0
- package/web/dist/assets/{commit-list-CPJLP4DU.js → commit-list-sFxchD2V.js} +1 -1
- package/web/dist/assets/{diff-BQJN6jzN.js → diff-C5-32cRp.js} +2 -2
- package/web/dist/assets/{diff-controls-AsSX7gfO.js → diff-controls-Ci36iPlK.js} +1 -1
- package/web/dist/assets/{diff-view-BW5bbiaq.js → diff-view-CCtuYJNL.js} +1 -1
- package/web/dist/assets/{discard-changes-dialog-Bv4yc0N1.js → discard-changes-dialog-BACqR1hj.js} +1 -1
- package/web/dist/assets/{file-preview-CnrFxbea.js → file-preview-B7T7jFYo.js} +1 -1
- package/web/dist/assets/{folder-browser-CFd1U5hn.js → folder-browser-3cBLlnE9.js} +1 -1
- package/web/dist/assets/{git-toolbar-C7iolhIi.js → git-toolbar-UkRnjuDs.js} +1 -1
- package/web/dist/assets/github-CkbZgMnJ.js +1 -0
- package/web/dist/assets/{global-activity-route-Dijwg4OL.js → global-activity-route-j37l-BQU.js} +1 -1
- package/web/dist/assets/hosts-iUyg8S3j.js +1 -0
- package/web/dist/assets/index-DkQ5xrLr.js +21 -0
- package/web/dist/assets/{label-CgU9vxuM.js → label-CWlxyeC-.js} +1 -1
- package/web/dist/assets/{markdown-Cljq4S1h.js → markdown-FIfZPsax.js} +1 -1
- package/web/dist/assets/{open-in-menu-BI7mnPPf.js → open-in-menu-Bf8JA2DJ.js} +1 -1
- package/web/dist/assets/{option-select-BcTkv-7t.js → option-select-DylfDjGi.js} +1 -1
- package/web/dist/assets/{preferences-section-CEKXGhEj.js → preferences-section-DjWfc1i-.js} +1 -1
- package/web/dist/assets/{preview-EtD19mg1.js → preview-BSFJfN4s.js} +1 -1
- package/web/dist/assets/{preview-pane-connected-CKRBfx7t.js → preview-pane-connected-CfiPFvTH.js} +2 -2
- package/web/dist/assets/{project-location-hufc_p8y.js → project-location-CEX0-MZp.js} +1 -1
- package/web/dist/assets/{project-router-Dc6KBQsv.js → project-router-CwD1firw.js} +1 -1
- package/web/dist/assets/{projects-section-vOFZ4lbx.js → projects-section-Czmf0wFK.js} +1 -1
- package/web/dist/assets/{prompt-templates-section-Caash2nq.js → prompt-templates-section-DK4CV73w.js} +1 -1
- package/web/dist/assets/queries-D9mg7sFY.js +1 -0
- package/web/dist/assets/{read-state-BeVNfGkB.js → read-state-BsTfJki5.js} +1 -1
- package/web/dist/assets/{reference-chip-BjerVjzM.js → reference-chip-CZKBU_Ud.js} +1 -1
- package/web/dist/assets/{remote-settings-notice-fNgh5LdN.js → remote-settings-notice-Dott-jyP.js} +1 -1
- package/web/dist/assets/repo-git-Djt3N2wP.js +1 -0
- package/web/dist/assets/{report-reader-CK1WDtEH.js → report-reader-CrdDix7Z.js} +1 -1
- package/web/dist/assets/{report-selection-CZ8eb9QP.js → report-selection-Y2F9NTAs.js} +1 -1
- package/web/dist/assets/{reports-B-GImLAo.js → reports-Iw4LUvz2.js} +1 -1
- package/web/dist/assets/{resources-section-ApF3gXrw.js → resources-section-D3wUzdUQ.js} +1 -1
- package/web/dist/assets/{review-notes-drafts-BdjEFs1G.js → review-notes-drafts-xyC7GvRB.js} +1 -1
- package/web/dist/assets/{review-panel-D4zmYH8O.js → review-panel-3x_2lbej.js} +1 -1
- package/web/dist/assets/{review-strip-BpHXklAn.js → review-strip-CDYpq9_S.js} +1 -1
- package/web/dist/assets/{run-detail-refresh-CE0vyYYA.js → run-detail-refresh-SYZM94ch.js} +1 -1
- package/web/dist/assets/{run-diff-ClfLRsHF.js → run-diff-D26PXp6r.js} +1 -1
- package/web/dist/assets/run-header-DZ0rkryR.js +2 -0
- package/web/dist/assets/{select-CwDhRDtw.js → select-DC_G2no3.js} +1 -1
- package/web/dist/assets/{session-context-section-C87jx7RB.js → session-context-section-DEUv-ISr.js} +1 -1
- package/web/dist/assets/{settings-agent-picker-Dk8yJ57U.js → settings-agent-picker-BrFN2RaQ.js} +1 -1
- package/web/dist/assets/{settings-save-bar-cu8BKCGT.js → settings-save-bar-C0pFHqte.js} +1 -1
- package/web/dist/assets/{settings-shell-mhQfQKf1.js → settings-shell-BWWbVxv-.js} +1 -1
- package/web/dist/assets/{sidebar-section-DOQ5N1L6.js → sidebar-section-BGo1zjJt.js} +1 -1
- package/web/dist/assets/{skills-DXJ1gQBD.js → skills-qFMQz6sm.js} +1 -1
- package/web/dist/assets/{status-dot-Bmn4xhch.js → status-dot-DTU7afRv.js} +1 -1
- package/web/dist/assets/{tab-link-6TltE1jl.js → tab-link-BJDe5cT4.js} +1 -1
- package/web/dist/assets/{task-changes-D9Sdmpmw.js → task-changes-DKJHAtKC.js} +2 -2
- package/web/dist/assets/{task-commits-A0UIqxpL.js → task-commits-Dtt60D0o.js} +1 -1
- package/web/dist/assets/{task-file-scope-ID220XKo.js → task-file-scope-FTt7SiGn.js} +1 -1
- package/web/dist/assets/{task-files-Id2tuAAG.js → task-files-DVz4222z.js} +1 -1
- package/web/dist/assets/{task-github-item-YKUcwp2o.js → task-github-item-CJpKQ6cU.js} +1 -1
- package/web/dist/assets/{task-groups-DCg4iOB9.js → task-groups-BvVfsQKd.js} +1 -1
- package/web/dist/assets/{task-thread-A_vkygGX.js → task-thread-DiYtqka4.js} +2 -2
- package/web/dist/assets/{thread-state-6-BzRrJ_.js → thread-state-pO7Wy_7R.js} +1 -1
- package/web/dist/assets/toaster-2ud_VdfV.js +4 -0
- package/web/dist/assets/{use-finish-run-DO-nnAaa.js → use-finish-run-5S30Eu3d.js} +1 -1
- package/web/dist/assets/{use-hand-to-agent-state-CADaL8U8.js → use-hand-to-agent-state-BB_VmbF7.js} +1 -1
- package/web/dist/assets/use-path-bases-npA-uKvg.js +1 -0
- package/web/dist/assets/use-workspace-config-save-DDI7_WtK.js +1 -0
- package/web/dist/assets/{workflows-DOLG-Rns.js → workflows-DLuBawpi.js} +2 -2
- package/web/dist/assets/{workspace-tools-DTCJVDTE.js → workspace-tools-D4jshe-2.js} +1 -1
- package/web/dist/assets/{worktrees-section-BOHDbywt.js → worktrees-section-CESTBOem.js} +5 -5
- package/web/dist/index.html +19 -19
- package/web/dist/assets/accounts-section-Bnr89jmC.js +0 -1
- package/web/dist/assets/activity-motion-BW0tAmYF.js +0 -1
- package/web/dist/assets/agent-defaults-section-RyEogH0g.js +0 -1
- package/web/dist/assets/attention-BI6592lk.js +0 -1
- package/web/dist/assets/automations-route-DfGE4xWT.js +0 -2
- package/web/dist/assets/github-DGElvfMU.js +0 -1
- package/web/dist/assets/hosts-CpDMDiQW.js +0 -1
- package/web/dist/assets/index-DPfg7xSB.js +0 -21
- package/web/dist/assets/queries-IlC9MZgh.js +0 -1
- package/web/dist/assets/repo-git-5MK_RAR6.js +0 -1
- package/web/dist/assets/run-header-BUe92WWr.js +0 -2
- package/web/dist/assets/toaster-DNnL8v10.js +0 -4
- package/web/dist/assets/use-path-bases-CFAmFn_E.js +0 -1
- package/web/dist/assets/use-workspace-config-save-DScW6_8J.js +0 -1
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-host task index benchmark (hearsay-tools/squawk#4541, slice S5a).
|
|
3
|
+
*
|
|
4
|
+
* Boots the real bundled `hosts` feature through `bootRuntime()` and `startServer()` (importing no
|
|
5
|
+
* feature internals) against real loopback HTTP remote servers over a local TCP-forwarding `ssh`
|
|
6
|
+
* shim, and measures 1, 3, and 8 connected hosts holding 1,000, 5,000, and 20,000 rows each:
|
|
7
|
+
* - First read of a host index (ms per host: loopback transfer + JSON parse + Zod + store load)
|
|
8
|
+
* - One SSE `run-summary` event applied (µs per event: loopback SSE + parse + Zod + store patch)
|
|
9
|
+
* - `GET /api/v1/hosts/runs-index` answer time (cold after mutation / warm cached, ms) and bytes
|
|
10
|
+
* - Retained V8 heap memory held per host (MiB, requires `--expose-gc`)
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* node --expose-gc --import tsx packages/cezar/scripts/benchmark-hosts-runs-index.ts
|
|
14
|
+
* node --expose-gc --import tsx packages/cezar/scripts/benchmark-hosts-runs-index.ts --json
|
|
15
|
+
*/
|
|
16
|
+
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { createServer, type Server, type ServerResponse } from 'node:http';
|
|
18
|
+
import type { AddressInfo } from 'node:net';
|
|
19
|
+
import { tmpdir } from 'node:os';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { performance } from 'node:perf_hooks';
|
|
22
|
+
import { parseArgs } from 'node:util';
|
|
23
|
+
import {
|
|
24
|
+
HOSTS_CHANGED_EVENT,
|
|
25
|
+
HOST_RUN_SUMMARY_EVENT,
|
|
26
|
+
HOST_USAGE_EVENT,
|
|
27
|
+
} from '@open-mercato/cezar-contract/hosts';
|
|
28
|
+
import type { RunIndexEntry, RunSummary } from '@open-mercato/cezar-contract/runs';
|
|
29
|
+
import type { RunsIndexResponse } from '@open-mercato/cezar-contract/workspace-events';
|
|
30
|
+
import { bootRuntime } from '../src/boot.ts';
|
|
31
|
+
import { installWindowsIdentityStore } from '../src/delegation/windows-identity-store.ts';
|
|
32
|
+
import { Home } from '../src/home/home.ts';
|
|
33
|
+
import { projectPaths } from '../src/project-paths.ts';
|
|
34
|
+
import { RunStore } from '../src/runs/store.ts';
|
|
35
|
+
import { WorkspaceEventBus } from '../src/server/server.ts';
|
|
36
|
+
import { startServer } from '../src/server/start-server.ts';
|
|
37
|
+
import type { RunManager } from '../src/workflows/run.ts';
|
|
38
|
+
import {
|
|
39
|
+
createEventLoopProbe,
|
|
40
|
+
createIsolatedHttpClient,
|
|
41
|
+
openSummarySseClient,
|
|
42
|
+
type IsolatedHttpClient,
|
|
43
|
+
} from './benchmark-hosts-runs-index-probes.ts';
|
|
44
|
+
|
|
45
|
+
const BENCH_VERSION: string = (
|
|
46
|
+
JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version: string }
|
|
47
|
+
).version;
|
|
48
|
+
const ARCHIVED_PER_PROJECT_LIMIT = 200;
|
|
49
|
+
const RUNNING_TASKS_PER_HOST = 5;
|
|
50
|
+
|
|
51
|
+
function projectCountForHost(rowsPerHost: number): number {
|
|
52
|
+
return Math.max(10, Math.ceil(Math.max(0, rowsPerHost - RUNNING_TASKS_PER_HOST) / ARCHIVED_PER_PROJECT_LIMIT));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function projectIdForRow(rowIdx: number, rowsPerHost: number): string {
|
|
56
|
+
if (rowIdx < RUNNING_TASKS_PER_HOST) return 'project-0';
|
|
57
|
+
return `project-${(rowIdx - RUNNING_TASKS_PER_HOST) % projectCountForHost(rowsPerHost)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface BenchRowResult {
|
|
61
|
+
hosts: number;
|
|
62
|
+
rowsPerHost: number;
|
|
63
|
+
totalRows: number;
|
|
64
|
+
firstReadPerHostMs: number;
|
|
65
|
+
snapshotInstallBlockMs: number;
|
|
66
|
+
eventAppliedUs: number;
|
|
67
|
+
getIndexColdMs: number;
|
|
68
|
+
getIndexWarmMs: number;
|
|
69
|
+
getIndexAfterUsageMs: number;
|
|
70
|
+
getIndexAfterUsageBlockMs: number;
|
|
71
|
+
getIndexBytes: number;
|
|
72
|
+
memoryPerHostMb: number | null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface TenKEventsBenchResult {
|
|
76
|
+
rowsPerHost: number;
|
|
77
|
+
eventsApplied: number;
|
|
78
|
+
memoryBeforeEventsMb: number | null;
|
|
79
|
+
memoryAfterEventsMb: number | null;
|
|
80
|
+
memoryDeltaMb: number | null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface RelayAndPerHostBenchResult {
|
|
84
|
+
rowsPerHost: number;
|
|
85
|
+
perHostGetMs: number;
|
|
86
|
+
perHostGetBlockMs: number;
|
|
87
|
+
perHostGetBytes: number;
|
|
88
|
+
runningTasks: number;
|
|
89
|
+
relayedEvents: number;
|
|
90
|
+
relayEventsPerSec: number;
|
|
91
|
+
relayPerEventUs: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface RemoteStubHost {
|
|
95
|
+
readonly hostId: string;
|
|
96
|
+
readonly installId: string;
|
|
97
|
+
readonly port: number;
|
|
98
|
+
readonly server: Server;
|
|
99
|
+
firstReadStartedAt: number | undefined;
|
|
100
|
+
releasePayload(): void;
|
|
101
|
+
sendSse(event: string, data: unknown): void;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function makeRealisticSummary(hostIdx: number, rowIdx: number, baseMs: number): RunSummary {
|
|
106
|
+
const id = `00000000-0000-4000-8${String(hostIdx).padStart(3, '0')}-${String(rowIdx).padStart(12, '0')}`;
|
|
107
|
+
const createdAt = new Date(baseMs - rowIdx * 60_000).toISOString();
|
|
108
|
+
const archived = rowIdx >= RUNNING_TASKS_PER_HOST;
|
|
109
|
+
const status = rowIdx < RUNNING_TASKS_PER_HOST ? 'running' : rowIdx < 15 ? 'review' : 'done';
|
|
110
|
+
return {
|
|
111
|
+
id,
|
|
112
|
+
title: `Implement feature slice ${rowIdx} on host ${hostIdx} with multi-step verification`,
|
|
113
|
+
titleOrigin: 'auto',
|
|
114
|
+
status,
|
|
115
|
+
createdAt,
|
|
116
|
+
startedAt: createdAt,
|
|
117
|
+
...(archived ? { finishedAt: createdAt, seenAt: createdAt } : {}),
|
|
118
|
+
archived,
|
|
119
|
+
workflow: 'quick-task',
|
|
120
|
+
workflowLabel: 'quick-task',
|
|
121
|
+
branch: `cez/host-${hostIdx}-task-${rowIdx}`,
|
|
122
|
+
...(rowIdx % 3 === 0 ? { prNumber: 4000 + (rowIdx % 500) } : {}),
|
|
123
|
+
runner: 'codex',
|
|
124
|
+
model: 'gpt-5.4',
|
|
125
|
+
tokensUsed: 12_500 + (rowIdx % 90_000),
|
|
126
|
+
costUsd: 0.14,
|
|
127
|
+
diffStat: { files: 4, adds: 120, dels: 35 },
|
|
128
|
+
...(status === 'review' ? { statePreview: { kind: 'review' as const, text: 'Ready for review with passing checks' } } : {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function buildSnapshotJson(hostIdx: number, rowsPerHost: number): string {
|
|
133
|
+
const baseMs = Date.parse('2026-12-01T00:00:00.000Z') - hostIdx * 1_000;
|
|
134
|
+
const runs: RunIndexEntry[] = [];
|
|
135
|
+
for (let i = 0; i < rowsPerHost; i += 1) {
|
|
136
|
+
const projectId = projectIdForRow(i, rowsPerHost);
|
|
137
|
+
runs.push({ projectId, ...makeRealisticSummary(hostIdx, i, baseMs) });
|
|
138
|
+
}
|
|
139
|
+
// Every project fits within the 200-archived-row window with no omitted archived history, so
|
|
140
|
+
// `truncated` stays empty per the runs-index contract.
|
|
141
|
+
const snapshot: RunsIndexResponse = {
|
|
142
|
+
runs,
|
|
143
|
+
referenceStatuses: {},
|
|
144
|
+
perProjectLimit: ARCHIVED_PER_PROJECT_LIMIT,
|
|
145
|
+
truncated: [],
|
|
146
|
+
generation: `gen-host-${hostIdx}`,
|
|
147
|
+
eventSeq: 0,
|
|
148
|
+
};
|
|
149
|
+
return JSON.stringify(snapshot);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function startRemoteStubHost(hostIdx: number, rowsPerHost: number): Promise<RemoteStubHost> {
|
|
153
|
+
const hostId = `host-${hostIdx}`;
|
|
154
|
+
const installId = `00000000-0000-4000-9000-${String(hostIdx).padStart(12, '0')}`;
|
|
155
|
+
let snapshotPayload: Buffer | undefined = Buffer.from(buildSnapshotJson(hostIdx, rowsPerHost), 'utf8');
|
|
156
|
+
const sseClients = new Set<ServerResponse>();
|
|
157
|
+
|
|
158
|
+
const stub: RemoteStubHost = {
|
|
159
|
+
hostId,
|
|
160
|
+
installId,
|
|
161
|
+
port: 0,
|
|
162
|
+
server: undefined as unknown as Server,
|
|
163
|
+
firstReadStartedAt: undefined,
|
|
164
|
+
releasePayload() {
|
|
165
|
+
snapshotPayload = undefined;
|
|
166
|
+
},
|
|
167
|
+
sendSse(event, data) {
|
|
168
|
+
const frame = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
169
|
+
for (const client of sseClients) client.write(frame);
|
|
170
|
+
},
|
|
171
|
+
async close() {
|
|
172
|
+
for (const client of sseClients) client.destroy();
|
|
173
|
+
sseClients.clear();
|
|
174
|
+
await new Promise<void>((resolve) => {
|
|
175
|
+
stub.server.close(() => resolve());
|
|
176
|
+
stub.server.closeAllConnections();
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const server = createServer((req, res) => {
|
|
182
|
+
const url = req.url ?? '';
|
|
183
|
+
if (url === '/api/v1/workspace/identity') {
|
|
184
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
185
|
+
res.end(JSON.stringify({ installId, version: BENCH_VERSION }));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (url === '/api/v1/health') {
|
|
189
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
190
|
+
res.end(JSON.stringify({
|
|
191
|
+
ok: true,
|
|
192
|
+
version: BENCH_VERSION,
|
|
193
|
+
capabilities: { localHandoff: false, settingsAdmin: false },
|
|
194
|
+
}));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (url.startsWith('/api/v1/workspace/events')) {
|
|
198
|
+
res.writeHead(200, {
|
|
199
|
+
'content-type': 'text/event-stream',
|
|
200
|
+
'cache-control': 'no-cache, no-transform',
|
|
201
|
+
});
|
|
202
|
+
res.write(`event: ready\ndata: ${JSON.stringify({ generation: `gen-host-${hostIdx}`, seq: 0 })}\n\n`);
|
|
203
|
+
sseClients.add(res);
|
|
204
|
+
res.on('close', () => { sseClients.delete(res); });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (url === '/api/v1/workspace/runs-index') {
|
|
208
|
+
if (stub.firstReadStartedAt === undefined) stub.firstReadStartedAt = performance.now();
|
|
209
|
+
// Rebuild on demand if released for heap measurement so a backstop/reconnect never wipes rows.
|
|
210
|
+
const body = snapshotPayload ?? Buffer.from(buildSnapshotJson(hostIdx, rowsPerHost), 'utf8');
|
|
211
|
+
res.writeHead(200, {
|
|
212
|
+
'content-type': 'application/json',
|
|
213
|
+
'content-length': String(body.byteLength),
|
|
214
|
+
});
|
|
215
|
+
res.end(body);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
res.writeHead(404, { 'content-type': 'application/json' });
|
|
219
|
+
res.end('{"error":"not found"}');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
223
|
+
(stub as { server: Server }).server = server;
|
|
224
|
+
(stub as { port: number }).port = (server.address() as AddressInfo).port;
|
|
225
|
+
return stub;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function writeFakeSshBin(
|
|
229
|
+
binDir: string,
|
|
230
|
+
configPath: string,
|
|
231
|
+
hosts: ReadonlyArray<{ hostId: string; port: number; installId: string }>,
|
|
232
|
+
): void {
|
|
233
|
+
const map: Record<string, { port: number; installId: string; version: string }> = {};
|
|
234
|
+
for (const h of hosts) {
|
|
235
|
+
map[h.hostId] = { port: h.port, installId: h.installId, version: BENCH_VERSION };
|
|
236
|
+
}
|
|
237
|
+
writeFileSync(configPath, JSON.stringify(map), 'utf8');
|
|
238
|
+
const scriptPath = join(binDir, 'ssh');
|
|
239
|
+
const script = `#!${process.execPath}
|
|
240
|
+
const { readFileSync } = require('node:fs');
|
|
241
|
+
const { createConnection, createServer } = require('node:net');
|
|
242
|
+
|
|
243
|
+
const hosts = JSON.parse(readFileSync(${JSON.stringify(configPath)}, 'utf8'));
|
|
244
|
+
const argv = process.argv.slice(2);
|
|
245
|
+
let isTunnel = false;
|
|
246
|
+
let forwardSpec = '';
|
|
247
|
+
const positionals = [];
|
|
248
|
+
const withArg = new Set(['-o', '-F', '-L', '-i', '-p', '-l', '-J', '-W', '-b', '-c', '-D', '-E', '-I', '-m', '-O', '-Q', '-R', '-S', '-w']);
|
|
249
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
250
|
+
const arg = argv[i];
|
|
251
|
+
if (arg === '--') { positionals.push(...argv.slice(i + 1)); break; }
|
|
252
|
+
if (arg === '-N') { isTunnel = true; continue; }
|
|
253
|
+
if (arg === '-L') { forwardSpec = argv[i + 1] ?? ''; i += 1; continue; }
|
|
254
|
+
if (withArg.has(arg)) { i += 1; continue; }
|
|
255
|
+
if (arg.startsWith('-')) continue;
|
|
256
|
+
positionals.push(arg);
|
|
257
|
+
}
|
|
258
|
+
const alias = positionals[0] ?? '';
|
|
259
|
+
const command = positionals.slice(1).join(' ');
|
|
260
|
+
const entry = hosts[alias];
|
|
261
|
+
if (!entry) {
|
|
262
|
+
process.stderr.write('ssh: unknown host ' + alias + '\\n');
|
|
263
|
+
process.exit(255);
|
|
264
|
+
}
|
|
265
|
+
if (isTunnel && forwardSpec) {
|
|
266
|
+
const parts = forwardSpec.split(':');
|
|
267
|
+
const localPort = Number(parts[1]);
|
|
268
|
+
const remotePort = Number(parts[3]);
|
|
269
|
+
const sockets = new Set();
|
|
270
|
+
const srv = createServer((client) => {
|
|
271
|
+
const up = createConnection({ host: '127.0.0.1', port: remotePort });
|
|
272
|
+
sockets.add(client); sockets.add(up);
|
|
273
|
+
client.pipe(up); up.pipe(client);
|
|
274
|
+
const drop = () => { sockets.delete(client); sockets.delete(up); client.destroy(); up.destroy(); };
|
|
275
|
+
client.on('error', drop); up.on('error', drop); client.on('close', drop); up.on('close', drop);
|
|
276
|
+
});
|
|
277
|
+
srv.on('error', (err) => { process.stderr.write(err.message + '\\n'); process.exit(255); });
|
|
278
|
+
srv.listen(localPort, '127.0.0.1');
|
|
279
|
+
const stop = () => { for (const s of sockets) s.destroy(); srv.close(() => process.exit(0)); };
|
|
280
|
+
process.on('SIGTERM', stop);
|
|
281
|
+
process.on('SIGINT', stop);
|
|
282
|
+
} else if (command.includes('NODE_BIN=')) {
|
|
283
|
+
process.stdout.write(JSON.stringify({
|
|
284
|
+
ok: true,
|
|
285
|
+
nodePath: process.execPath,
|
|
286
|
+
nodeVersion: '24.21.0',
|
|
287
|
+
platform: 'linux',
|
|
288
|
+
dataDir: '/tmp/bench-data',
|
|
289
|
+
configDir: '/tmp/bench-config',
|
|
290
|
+
runtimeDir: '/tmp/bench-data/runtime/' + entry.version,
|
|
291
|
+
runtimeEntry: '/tmp/bench-data/runtime/' + entry.version + '/dist/hsq.js',
|
|
292
|
+
runtimeInstalled: true,
|
|
293
|
+
installId: entry.installId,
|
|
294
|
+
}) + '\\n');
|
|
295
|
+
} else if (command.includes('host-server') && command.includes('ensure')) {
|
|
296
|
+
process.stdout.write(JSON.stringify({
|
|
297
|
+
status: 'ready',
|
|
298
|
+
ownership: 'managed',
|
|
299
|
+
port: entry.port,
|
|
300
|
+
pid: process.pid,
|
|
301
|
+
version: entry.version,
|
|
302
|
+
installId: entry.installId,
|
|
303
|
+
}) + '\\n');
|
|
304
|
+
} else if (command.includes('host-server') && command.includes('status')) {
|
|
305
|
+
process.stdout.write(JSON.stringify({
|
|
306
|
+
ok: true,
|
|
307
|
+
version: entry.version,
|
|
308
|
+
installId: entry.installId,
|
|
309
|
+
dbPath: '/tmp/bench-data/host-server.db',
|
|
310
|
+
paused: false,
|
|
311
|
+
claim: null,
|
|
312
|
+
leases: [{ pid: process.pid, port: entry.port, instance: 'bench', installId: entry.installId }],
|
|
313
|
+
state: 'ready',
|
|
314
|
+
}) + '\\n');
|
|
315
|
+
} else {
|
|
316
|
+
process.stderr.write('unsupported fake ssh command: ' + command + '\\n');
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
`;
|
|
320
|
+
writeFileSync(scriptPath, script, 'utf8');
|
|
321
|
+
chmodSync(scriptPath, 0o755);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function forceGc(): boolean {
|
|
325
|
+
const gc = (globalThis as { gc?: (() => void) | undefined }).gc;
|
|
326
|
+
if (!gc) return false;
|
|
327
|
+
gc();
|
|
328
|
+
gc();
|
|
329
|
+
gc();
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function measureHeapUsed(): Promise<number | null> {
|
|
334
|
+
if (!forceGc()) return null;
|
|
335
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
336
|
+
forceGc();
|
|
337
|
+
return process.memoryUsage().heapUsed;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
interface BenchHarness {
|
|
341
|
+
readonly workspaceEvents: WorkspaceEventBus;
|
|
342
|
+
readonly stubs: readonly RemoteStubHost[];
|
|
343
|
+
readonly server: ReturnType<typeof startServer>;
|
|
344
|
+
readonly mainOrigin: string;
|
|
345
|
+
close(): Promise<void>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function createBenchHarness(
|
|
349
|
+
prefix: string,
|
|
350
|
+
hostsCount: number,
|
|
351
|
+
rowsPerHost: number,
|
|
352
|
+
): Promise<BenchHarness> {
|
|
353
|
+
const tempRoot = mkdtempSync(join(tmpdir(), prefix));
|
|
354
|
+
const homeDir = join(tempRoot, 'home');
|
|
355
|
+
const repoRoot = join(tempRoot, 'repo');
|
|
356
|
+
const binDir = join(tempRoot, 'bin');
|
|
357
|
+
mkdirSync(projectPaths(repoRoot).write, { recursive: true });
|
|
358
|
+
mkdirSync(binDir, { recursive: true });
|
|
359
|
+
|
|
360
|
+
const prevPath = process.env.PATH ?? '';
|
|
361
|
+
process.env.HSQ_HOME = process.env.CEZ_HOME = homeDir;
|
|
362
|
+
const home = Home.sandbox(homeDir);
|
|
363
|
+
const store = RunStore.open(projectPaths(repoRoot).write);
|
|
364
|
+
const workspaceEvents = new WorkspaceEventBus();
|
|
365
|
+
const stubs: RemoteStubHost[] = [];
|
|
366
|
+
for (let h = 0; h < hostsCount; h += 1) {
|
|
367
|
+
stubs.push(await startRemoteStubHost(h, rowsPerHost));
|
|
368
|
+
}
|
|
369
|
+
writeFakeSshBin(binDir, join(tempRoot, 'hosts-map.json'), stubs);
|
|
370
|
+
process.env.PATH = `${binDir}:${prevPath}`;
|
|
371
|
+
|
|
372
|
+
const server = startServer(
|
|
373
|
+
{
|
|
374
|
+
home,
|
|
375
|
+
repoRoot,
|
|
376
|
+
store,
|
|
377
|
+
manager: { isActive: () => false } as unknown as RunManager,
|
|
378
|
+
version: BENCH_VERSION,
|
|
379
|
+
workspaceEvents,
|
|
380
|
+
detectEnvironment: async () => [],
|
|
381
|
+
},
|
|
382
|
+
0,
|
|
383
|
+
);
|
|
384
|
+
if (!server.listening) {
|
|
385
|
+
await new Promise<void>((resolve) => server.once('listening', resolve));
|
|
386
|
+
}
|
|
387
|
+
const mainOrigin = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
|
|
388
|
+
|
|
389
|
+
return {
|
|
390
|
+
workspaceEvents,
|
|
391
|
+
stubs,
|
|
392
|
+
server,
|
|
393
|
+
mainOrigin,
|
|
394
|
+
async close() {
|
|
395
|
+
process.env.PATH = prevPath;
|
|
396
|
+
if (server.listening) await server.shutdownForRestart();
|
|
397
|
+
for (const stub of stubs) await stub.close();
|
|
398
|
+
store.close();
|
|
399
|
+
rmSync(tempRoot, { recursive: true, force: true });
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function waitForHostIndexLoaded(workspaceEvents: WorkspaceEventBus, hostId: string): Promise<number> {
|
|
405
|
+
return new Promise<number>((resolve) => {
|
|
406
|
+
const off = workspaceEvents.on((event, data) => {
|
|
407
|
+
if (event !== HOSTS_CHANGED_EVENT) return;
|
|
408
|
+
const payload = data as { hostIds?: string[]; stateChanged?: boolean; indexChanged?: boolean } | null;
|
|
409
|
+
if (!payload?.hostIds?.includes(hostId) || payload.stateChanged || !payload.indexChanged) return;
|
|
410
|
+
off();
|
|
411
|
+
resolve(performance.now());
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async function addBenchHost(mainOrigin: string, hostId: string, label: string): Promise<void> {
|
|
417
|
+
const addRes = await fetch(`${mainOrigin}/api/v1/hosts`, {
|
|
418
|
+
method: 'POST',
|
|
419
|
+
headers: { 'content-type': 'application/json' },
|
|
420
|
+
body: JSON.stringify({ id: hostId, sshAlias: hostId, label }),
|
|
421
|
+
});
|
|
422
|
+
if (addRes.status !== 201) throw new Error(`POST /api/v1/hosts failed: ${addRes.status}`);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async function sendAndAwaitAppliedBatch(
|
|
426
|
+
stub: RemoteStubHost,
|
|
427
|
+
mainOrigin: string,
|
|
428
|
+
rowsPerHost: number,
|
|
429
|
+
eventsCount: number,
|
|
430
|
+
): Promise<number> {
|
|
431
|
+
const baseMs = Date.parse('2026-12-01T00:00:00.000Z');
|
|
432
|
+
const sentinelRow = (eventsCount - 1) % rowsPerHost;
|
|
433
|
+
const sentinelId = makeRealisticSummary(0, sentinelRow, baseMs).id;
|
|
434
|
+
const sentinelTokens = 900_000_000 + eventsCount;
|
|
435
|
+
const sseClient = await openSummarySseClient(mainOrigin);
|
|
436
|
+
try {
|
|
437
|
+
const sentinelPromise = sseClient.waitForMatch(
|
|
438
|
+
HOST_RUN_SUMMARY_EVENT,
|
|
439
|
+
(data) => data.includes(sentinelId) && data.includes(String(sentinelTokens)),
|
|
440
|
+
20_000,
|
|
441
|
+
);
|
|
442
|
+
const t0 = performance.now();
|
|
443
|
+
for (let i = 1; i <= eventsCount; i += 1) {
|
|
444
|
+
const targetRow = (i - 1) % rowsPerHost;
|
|
445
|
+
const summary = makeRealisticSummary(0, targetRow, baseMs);
|
|
446
|
+
summary.tokensUsed = i === eventsCount ? sentinelTokens : summary.tokensUsed + i;
|
|
447
|
+
stub.sendSse('run-summary', {
|
|
448
|
+
project: projectIdForRow(targetRow, rowsPerHost),
|
|
449
|
+
seq: i,
|
|
450
|
+
run: summary,
|
|
451
|
+
relationships: `rel-${i}`,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const t1 = await sentinelPromise;
|
|
455
|
+
return Math.max(0.001, t1 - t0);
|
|
456
|
+
} finally {
|
|
457
|
+
sseClient.close();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
async function runCell(
|
|
462
|
+
hostsCount: number,
|
|
463
|
+
rowsPerHost: number,
|
|
464
|
+
eventSamples: number,
|
|
465
|
+
httpClient: IsolatedHttpClient,
|
|
466
|
+
): Promise<BenchRowResult> {
|
|
467
|
+
const harness = await createBenchHarness('hsq-bench-hosts-', hostsCount, rowsPerHost);
|
|
468
|
+
const { workspaceEvents, stubs, server, mainOrigin } = harness;
|
|
469
|
+
|
|
470
|
+
try {
|
|
471
|
+
const firstReadTimes: number[] = [];
|
|
472
|
+
const installBlocks: number[] = [];
|
|
473
|
+
|
|
474
|
+
for (const stub of stubs) {
|
|
475
|
+
const probe = createEventLoopProbe();
|
|
476
|
+
const loadedPromise = waitForHostIndexLoaded(workspaceEvents, stub.hostId);
|
|
477
|
+
|
|
478
|
+
// Add one host at a time via the real HTTP route so each host's first read is measured cleanly.
|
|
479
|
+
await probe.start();
|
|
480
|
+
await addBenchHost(mainOrigin, stub.hostId, `Host ${stub.hostId}`);
|
|
481
|
+
let loadTimer: ReturnType<typeof setTimeout> | undefined;
|
|
482
|
+
const finishedAt = await Promise.race([
|
|
483
|
+
loadedPromise,
|
|
484
|
+
new Promise<never>((_, reject) => {
|
|
485
|
+
loadTimer = setTimeout(() => {
|
|
486
|
+
reject(new Error(`Timed out waiting for ${stub.hostId} to load.`));
|
|
487
|
+
}, 15_000);
|
|
488
|
+
loadTimer.unref();
|
|
489
|
+
}),
|
|
490
|
+
]).finally(() => {
|
|
491
|
+
if (loadTimer !== undefined) clearTimeout(loadTimer);
|
|
492
|
+
});
|
|
493
|
+
installBlocks.push(await probe.stopMs());
|
|
494
|
+
const startedAt = stub.firstReadStartedAt ?? finishedAt;
|
|
495
|
+
firstReadTimes.push(Math.max(0, finishedAt - startedAt));
|
|
496
|
+
stub.releasePayload();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const heapWithHosts = await measureHeapUsed();
|
|
500
|
+
|
|
501
|
+
// Measure GET /api/v1/hosts/runs-index cold (first read, builds merged sorted array) and warm
|
|
502
|
+
// (cached merged array, JSON serialization only) from an isolated child HTTP client.
|
|
503
|
+
const expectedTotalRows = hostsCount * rowsPerHost;
|
|
504
|
+
const { getIndexColdMs, getIndexWarmMs, getIndexBytes } = await (async () => {
|
|
505
|
+
const cold = await httpClient.get(`${mainOrigin}/api/v1/hosts/runs-index`, { countRuns: true });
|
|
506
|
+
if (cold.status !== 200) throw new Error(`GET /api/v1/hosts/runs-index failed: ${cold.status}`);
|
|
507
|
+
if (cold.runsCount !== expectedTotalRows) {
|
|
508
|
+
throw new Error(`Expected ${expectedTotalRows} runs on cold GET, got ${cold.runsCount}`);
|
|
509
|
+
}
|
|
510
|
+
const warm = await httpClient.get(`${mainOrigin}/api/v1/hosts/runs-index`);
|
|
511
|
+
if (warm.status !== 200) throw new Error(`GET /api/v1/hosts/runs-index warm failed: ${warm.status}`);
|
|
512
|
+
return { getIndexColdMs: cold.elapsedMs, getIndexWarmMs: warm.elapsedMs, getIndexBytes: cold.bytes };
|
|
513
|
+
})();
|
|
514
|
+
|
|
515
|
+
// Measure GET /api/v1/hosts/runs-index right after a single live `usage` tick on host-0.
|
|
516
|
+
const stub0 = stubs[0]!;
|
|
517
|
+
const sseClient = await openSummarySseClient(mainOrigin);
|
|
518
|
+
try {
|
|
519
|
+
const usageRelayed = sseClient.waitForEvent(HOST_USAGE_EVENT, 1, 10_000);
|
|
520
|
+
const firstRowId = makeRealisticSummary(0, 0, Date.parse('2026-12-01T00:00:00.000Z')).id;
|
|
521
|
+
stub0.sendSse('usage', {
|
|
522
|
+
project: 'project-0',
|
|
523
|
+
usage: { [firstRowId]: { cpuPct: 12.5, rssBytes: 128 * 1024 * 1024, procCount: 2 } },
|
|
524
|
+
});
|
|
525
|
+
await usageRelayed;
|
|
526
|
+
} finally {
|
|
527
|
+
sseClient.close();
|
|
528
|
+
}
|
|
529
|
+
const usageGetProbe = createEventLoopProbe();
|
|
530
|
+
await usageGetProbe.start();
|
|
531
|
+
const usageRes = await httpClient.get(`${mainOrigin}/api/v1/hosts/runs-index`, { countRuns: true });
|
|
532
|
+
if (usageRes.status !== 200) throw new Error(`GET after usage failed: ${usageRes.status}`);
|
|
533
|
+
if (usageRes.runsCount !== expectedTotalRows) {
|
|
534
|
+
throw new Error(`Expected ${expectedTotalRows} runs after usage GET, got ${usageRes.runsCount}`);
|
|
535
|
+
}
|
|
536
|
+
const getIndexAfterUsageMs = usageRes.elapsedMs;
|
|
537
|
+
const getIndexAfterUsageBlockMs = await usageGetProbe.stopMs();
|
|
538
|
+
|
|
539
|
+
// Measure one SSE `run-summary` event applied via a batch fenced on the final sentinel event.
|
|
540
|
+
const batchElapsedMs = await sendAndAwaitAppliedBatch(stub0, mainOrigin, rowsPerHost, eventSamples);
|
|
541
|
+
const eventAppliedUs = (batchElapsedMs * 1_000) / eventSamples;
|
|
542
|
+
|
|
543
|
+
// Delete every saved host and read runs-index once to flush any stale merged-cache reference,
|
|
544
|
+
// then measure the retained heap delta cleanly without cross-cell drift.
|
|
545
|
+
for (const stub of stubs) {
|
|
546
|
+
await fetch(`${mainOrigin}/api/v1/hosts/${stub.hostId}`, { method: 'DELETE' });
|
|
547
|
+
}
|
|
548
|
+
await (await fetch(`${mainOrigin}/api/v1/hosts/runs-index`)).text();
|
|
549
|
+
const heapAfterDelete = await measureHeapUsed();
|
|
550
|
+
const memoryPerHostMb = heapWithHosts !== null && heapAfterDelete !== null
|
|
551
|
+
? Math.max(0, (heapWithHosts - heapAfterDelete) / (1024 * 1024) / hostsCount)
|
|
552
|
+
: null;
|
|
553
|
+
|
|
554
|
+
await server.shutdownForRestart();
|
|
555
|
+
|
|
556
|
+
return {
|
|
557
|
+
hosts: hostsCount,
|
|
558
|
+
rowsPerHost,
|
|
559
|
+
totalRows: hostsCount * rowsPerHost,
|
|
560
|
+
firstReadPerHostMs: firstReadTimes.reduce((a, b) => a + b, 0) / firstReadTimes.length,
|
|
561
|
+
snapshotInstallBlockMs: Math.max(...installBlocks),
|
|
562
|
+
eventAppliedUs,
|
|
563
|
+
getIndexColdMs,
|
|
564
|
+
getIndexWarmMs,
|
|
565
|
+
getIndexAfterUsageMs,
|
|
566
|
+
getIndexAfterUsageBlockMs,
|
|
567
|
+
getIndexBytes,
|
|
568
|
+
memoryPerHostMb,
|
|
569
|
+
};
|
|
570
|
+
} finally {
|
|
571
|
+
await harness.close();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
async function runTenKEventsMemoryBench(
|
|
576
|
+
rowsPerHost: number,
|
|
577
|
+
eventsCount: number,
|
|
578
|
+
): Promise<TenKEventsBenchResult> {
|
|
579
|
+
const harness = await createBenchHarness('hsq-bench-10k-', 1, rowsPerHost);
|
|
580
|
+
const { workspaceEvents, server, mainOrigin } = harness;
|
|
581
|
+
const stub = harness.stubs[0]!;
|
|
582
|
+
|
|
583
|
+
try {
|
|
584
|
+
const loadedPromise = waitForHostIndexLoaded(workspaceEvents, stub.hostId);
|
|
585
|
+
await addBenchHost(mainOrigin, stub.hostId, 'Host 0');
|
|
586
|
+
await loadedPromise;
|
|
587
|
+
stub.releasePayload();
|
|
588
|
+
|
|
589
|
+
const heapLoaded = await measureHeapUsed();
|
|
590
|
+
await sendAndAwaitAppliedBatch(stub, mainOrigin, rowsPerHost, eventsCount);
|
|
591
|
+
|
|
592
|
+
const heapAfterEvents = await measureHeapUsed();
|
|
593
|
+
await fetch(`${mainOrigin}/api/v1/hosts/${stub.hostId}`, { method: 'DELETE' });
|
|
594
|
+
await (await fetch(`${mainOrigin}/api/v1/hosts/runs-index`)).text();
|
|
595
|
+
const heapAfterDelete = await measureHeapUsed();
|
|
596
|
+
|
|
597
|
+
const memoryBeforeEventsMb = heapLoaded !== null && heapAfterDelete !== null
|
|
598
|
+
? Math.max(0, (heapLoaded - heapAfterDelete) / (1024 * 1024))
|
|
599
|
+
: null;
|
|
600
|
+
const memoryAfterEventsMb = heapAfterEvents !== null && heapAfterDelete !== null
|
|
601
|
+
? Math.max(0, (heapAfterEvents - heapAfterDelete) / (1024 * 1024))
|
|
602
|
+
: null;
|
|
603
|
+
const memoryDeltaMb = memoryBeforeEventsMb !== null && memoryAfterEventsMb !== null
|
|
604
|
+
? memoryAfterEventsMb - memoryBeforeEventsMb
|
|
605
|
+
: null;
|
|
606
|
+
|
|
607
|
+
await server.shutdownForRestart();
|
|
608
|
+
return { rowsPerHost, eventsApplied: eventsCount, memoryBeforeEventsMb, memoryAfterEventsMb, memoryDeltaMb };
|
|
609
|
+
} finally {
|
|
610
|
+
await harness.close();
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async function runRelayAndPerHostBench(
|
|
615
|
+
rowsPerHost: number,
|
|
616
|
+
httpClient: IsolatedHttpClient,
|
|
617
|
+
runningTasks = 5,
|
|
618
|
+
bursts = 100,
|
|
619
|
+
): Promise<RelayAndPerHostBenchResult> {
|
|
620
|
+
const harness = await createBenchHarness('hsq-bench-relay-', 2, rowsPerHost);
|
|
621
|
+
const { workspaceEvents, stubs, mainOrigin } = harness;
|
|
622
|
+
|
|
623
|
+
try {
|
|
624
|
+
for (const stub of stubs) {
|
|
625
|
+
const loadedPromise = waitForHostIndexLoaded(workspaceEvents, stub.hostId);
|
|
626
|
+
await addBenchHost(mainOrigin, stub.hostId, `Host ${stub.hostId}`);
|
|
627
|
+
await loadedPromise;
|
|
628
|
+
stub.releasePayload();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// Measure single-host GET /api/v1/hosts/runs-index?hostId=host-0 at 20,000 rows from the isolated client.
|
|
632
|
+
const perHostProbe = createEventLoopProbe();
|
|
633
|
+
await perHostProbe.start();
|
|
634
|
+
const perHostRes = await httpClient.get(`${mainOrigin}/api/v1/hosts/runs-index?hostId=host-0`);
|
|
635
|
+
const perHostGetMs = perHostRes.elapsedMs;
|
|
636
|
+
const perHostGetBlockMs = await perHostProbe.stopMs();
|
|
637
|
+
if (perHostRes.status !== 200) throw new Error(`GET ?hostId=host-0 failed: ${perHostRes.status}`);
|
|
638
|
+
const perHostGetBytes = perHostRes.bytes;
|
|
639
|
+
|
|
640
|
+
// Measure relaying a live workload for 1 host with `runningTasks` running tasks
|
|
641
|
+
// (`bursts` rounds x (`runningTasks` run-summary updates + 1 usage tick across all 5 running tasks)).
|
|
642
|
+
const sseClient = await openSummarySseClient(mainOrigin);
|
|
643
|
+
try {
|
|
644
|
+
const baseMs = Date.parse('2026-12-01T00:00:00.000Z');
|
|
645
|
+
const stub0 = stubs[0]!;
|
|
646
|
+
const totalSummaryEvents = bursts * runningTasks;
|
|
647
|
+
const totalUsageEvents = bursts;
|
|
648
|
+
const totalEvents = totalSummaryEvents + totalUsageEvents;
|
|
649
|
+
const allSummariesDone = sseClient.waitForEvent(HOST_RUN_SUMMARY_EVENT, totalSummaryEvents, 20_000);
|
|
650
|
+
const allUsageDone = sseClient.waitForEvent(HOST_USAGE_EVENT, totalUsageEvents, 20_000);
|
|
651
|
+
|
|
652
|
+
const t0 = performance.now();
|
|
653
|
+
let seq = 0;
|
|
654
|
+
for (let b = 0; b < bursts; b += 1) {
|
|
655
|
+
const usageMap: Record<string, { cpuPct: number; rssBytes: number; procCount: number }> = {};
|
|
656
|
+
for (let t = 0; t < runningTasks; t += 1) {
|
|
657
|
+
seq += 1;
|
|
658
|
+
const summary = makeRealisticSummary(0, t, baseMs);
|
|
659
|
+
summary.tokensUsed += seq;
|
|
660
|
+
stub0.sendSse('run-summary', {
|
|
661
|
+
project: 'project-0',
|
|
662
|
+
seq,
|
|
663
|
+
run: summary,
|
|
664
|
+
relationships: `rel-${seq}`,
|
|
665
|
+
});
|
|
666
|
+
usageMap[summary.id] = { cpuPct: 10 + ((b + t) % 40), rssBytes: (100 + b + t) * 1024 * 1024, procCount: 2 };
|
|
667
|
+
}
|
|
668
|
+
stub0.sendSse('usage', { project: 'project-0', usage: usageMap });
|
|
669
|
+
}
|
|
670
|
+
const [tSum, tUse] = await Promise.all([allSummariesDone, allUsageDone]);
|
|
671
|
+
const elapsedMs = Math.max(0.001, Math.max(tSum, tUse) - t0);
|
|
672
|
+
return {
|
|
673
|
+
rowsPerHost,
|
|
674
|
+
perHostGetMs,
|
|
675
|
+
perHostGetBlockMs,
|
|
676
|
+
perHostGetBytes,
|
|
677
|
+
runningTasks,
|
|
678
|
+
relayedEvents: totalEvents,
|
|
679
|
+
relayEventsPerSec: (totalEvents / elapsedMs) * 1_000,
|
|
680
|
+
relayPerEventUs: (elapsedMs * 1_000) / totalEvents,
|
|
681
|
+
};
|
|
682
|
+
} finally {
|
|
683
|
+
sseClient.close();
|
|
684
|
+
}
|
|
685
|
+
} finally {
|
|
686
|
+
await harness.close();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function formatMarkdownTable(results: readonly BenchRowResult[]): string {
|
|
691
|
+
const header = [
|
|
692
|
+
'| Hosts | Rows / host | Total rows | First read / host (ms) | Snapshot install block (ms) | Event applied (µs) | GET runs-index cold / warm (ms) | GET after usage tick (ms / block ms) | GET runs-index size | Memory / host (MiB) |',
|
|
693
|
+
'| ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',
|
|
694
|
+
];
|
|
695
|
+
const rows = results.map((r) => {
|
|
696
|
+
const sizeText = r.getIndexBytes >= 1024 * 1024
|
|
697
|
+
? `${(r.getIndexBytes / (1024 * 1024)).toFixed(2)} MiB (${r.getIndexBytes.toLocaleString('en-US')} B)`
|
|
698
|
+
: `${(r.getIndexBytes / 1024).toFixed(1)} KiB (${r.getIndexBytes.toLocaleString('en-US')} B)`;
|
|
699
|
+
const memText = r.memoryPerHostMb !== null ? r.memoryPerHostMb.toFixed(2) : 'n/a (--expose-gc)';
|
|
700
|
+
return `| ${r.hosts} | ${r.rowsPerHost.toLocaleString('en-US')} | ${r.totalRows.toLocaleString('en-US')} | ${r.firstReadPerHostMs.toFixed(1)} | ${r.snapshotInstallBlockMs.toFixed(1)} | ${r.eventAppliedUs.toFixed(1)} | ${r.getIndexColdMs.toFixed(1)} / ${r.getIndexWarmMs.toFixed(1)} | ${r.getIndexAfterUsageMs.toFixed(1)} / ${r.getIndexAfterUsageBlockMs.toFixed(1)} | ${sizeText} | ${memText} |`;
|
|
701
|
+
});
|
|
702
|
+
return [...header, ...rows].join('\n');
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
async function main(): Promise<void> {
|
|
706
|
+
const { values } = parseArgs({
|
|
707
|
+
args: process.argv.slice(2),
|
|
708
|
+
options: {
|
|
709
|
+
json: { type: 'boolean', default: false },
|
|
710
|
+
events: { type: 'string', default: '200' },
|
|
711
|
+
},
|
|
712
|
+
});
|
|
713
|
+
const eventSamples = Number(values.events);
|
|
714
|
+
if (!Number.isInteger(eventSamples) || eventSamples <= 0) {
|
|
715
|
+
throw new Error('--events must be a positive integer');
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const emptyPlugins = mkdtempSync(join(tmpdir(), 'hsq-bench-plugins-'));
|
|
719
|
+
const bootHome = mkdtempSync(join(tmpdir(), 'hsq-bench-boot-home-'));
|
|
720
|
+
const httpClient = createIsolatedHttpClient();
|
|
721
|
+
delete process.env.HSQ_REMOTE;
|
|
722
|
+
delete process.env.CEZ_REMOTE;
|
|
723
|
+
process.env.HSQ_HOME = process.env.CEZ_HOME = bootHome;
|
|
724
|
+
process.env.HSQ_DRY_RUN = process.env.CEZ_DRY_RUN = '1';
|
|
725
|
+
process.env.HSQ_PROJECT_WARMUP = process.env.CEZ_PROJECT_WARMUP = '0';
|
|
726
|
+
installWindowsIdentityStore();
|
|
727
|
+
try {
|
|
728
|
+
await bootRuntime({ pluginsDir: emptyPlugins });
|
|
729
|
+
// Brief warmup cell to settle JIT, plugin paths, and the child HTTP client before timed cells.
|
|
730
|
+
await runCell(1, 200, 20, httpClient);
|
|
731
|
+
|
|
732
|
+
const hostCounts = [1, 3, 8] as const;
|
|
733
|
+
const rowCounts = [1_000, 5_000, 20_000] as const;
|
|
734
|
+
const results: BenchRowResult[] = [];
|
|
735
|
+
// Run smallest row counts first so V8 old-space growth from 20,000-row cells does not mask
|
|
736
|
+
// heapUsed deltas of 1,000-row cells, then sort output by (hosts, rowsPerHost).
|
|
737
|
+
for (const rowsPerHost of rowCounts) {
|
|
738
|
+
for (const hosts of hostCounts) {
|
|
739
|
+
results.push(await runCell(hosts, rowsPerHost, eventSamples, httpClient));
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
results.sort((a, b) => a.hosts - b.hosts || a.rowsPerHost - b.rowsPerHost);
|
|
743
|
+
|
|
744
|
+
const tenKEvents = await runTenKEventsMemoryBench(20_000, 10_000);
|
|
745
|
+
const relayAndPerHost = await runRelayAndPerHostBench(20_000, httpClient, 5, 100);
|
|
746
|
+
|
|
747
|
+
if (values.json) {
|
|
748
|
+
console.log(JSON.stringify({ node: process.version, results, tenKEvents, relayAndPerHost }, null, 2));
|
|
749
|
+
} else {
|
|
750
|
+
console.log(`Node ${process.version}, event samples=${eventSamples}`);
|
|
751
|
+
console.log(formatMarkdownTable(results));
|
|
752
|
+
const beforeText = tenKEvents.memoryBeforeEventsMb !== null ? `${tenKEvents.memoryBeforeEventsMb.toFixed(2)} MiB` : 'n/a';
|
|
753
|
+
const afterText = tenKEvents.memoryAfterEventsMb !== null ? `${tenKEvents.memoryAfterEventsMb.toFixed(2)} MiB` : 'n/a';
|
|
754
|
+
const deltaText = tenKEvents.memoryDeltaMb !== null ? `${tenKEvents.memoryDeltaMb >= 0 ? '+' : ''}${tenKEvents.memoryDeltaMb.toFixed(2)} MiB` : 'n/a';
|
|
755
|
+
console.log(
|
|
756
|
+
`\n10,000 applied events (1 host x ${tenKEvents.rowsPerHost.toLocaleString('en-US')} rows): `
|
|
757
|
+
+ `before=${beforeText}, after=${afterText}, delta=${deltaText}`,
|
|
758
|
+
);
|
|
759
|
+
console.log(
|
|
760
|
+
`Per-host GET ?hostId=host-0 (${relayAndPerHost.rowsPerHost.toLocaleString('en-US')} rows): `
|
|
761
|
+
+ `${relayAndPerHost.perHostGetMs.toFixed(1)} ms (block ${relayAndPerHost.perHostGetBlockMs.toFixed(1)} ms), `
|
|
762
|
+
+ `${(relayAndPerHost.perHostGetBytes / (1024 * 1024)).toFixed(2)} MiB (${relayAndPerHost.perHostGetBytes.toLocaleString('en-US')} B)`,
|
|
763
|
+
);
|
|
764
|
+
console.log(
|
|
765
|
+
`Relayed delta events (1 host, ${relayAndPerHost.runningTasks} running tasks, ${relayAndPerHost.relayedEvents} events): `
|
|
766
|
+
+ `${relayAndPerHost.relayEventsPerSec.toFixed(0)} events/s, ${relayAndPerHost.relayPerEventUs.toFixed(1)} µs/event`,
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
} finally {
|
|
770
|
+
httpClient.close();
|
|
771
|
+
rmSync(emptyPlugins, { recursive: true, force: true });
|
|
772
|
+
rmSync(bootHome, { recursive: true, force: true });
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
await main();
|