@hadoku/game-server 0.1.157 → 0.1.158

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.
@@ -128,6 +128,15 @@ export declare function pidIsStandingInRun(pid: number, run: string): boolean;
128
128
  * decides.
129
129
  */
130
130
  export declare function pidIsRunning(pid: number): boolean;
131
+ /**
132
+ * The work a process has done so far, as `/proc/<pid>/stat` counts it: CPU time (user + system,
133
+ * in clock ticks) and major page faults (pages it waited to read back, from swap or disk). Two
134
+ * readings apart say whether it is getting anywhere; `null` once it has exited, or without `/proc`.
135
+ */
136
+ export declare function pidWork(pid: number): {
137
+ cpuTicks: number;
138
+ majorFaults: number;
139
+ } | null;
131
140
  /** How long a kill will spin waiting for a SIGKILL to land. Measured at 0 ms. */
132
141
  export declare const REAP_CONFIRM_MS = 100;
133
142
  /** How often an attached process (which is nobody's child, so has no `exit` event) is checked for. */
@@ -209,6 +209,22 @@ export function pidIsRunning(pid) {
209
209
  return false; // no /proc entry: it has exited
210
210
  }
211
211
  }
212
+ /**
213
+ * The work a process has done so far, as `/proc/<pid>/stat` counts it: CPU time (user + system,
214
+ * in clock ticks) and major page faults (pages it waited to read back, from swap or disk). Two
215
+ * readings apart say whether it is getting anywhere; `null` once it has exited, or without `/proc`.
216
+ */
217
+ export function pidWork(pid) {
218
+ try {
219
+ const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
220
+ // After the `(comm)`, fields[0] is field 3 (state): majflt is field 12, utime 14, stime 15.
221
+ const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
222
+ return { cpuTicks: Number(fields[11]) + Number(fields[12]), majorFaults: Number(fields[9]) };
223
+ }
224
+ catch {
225
+ return null;
226
+ }
227
+ }
212
228
  /** How long a kill will spin waiting for a SIGKILL to land. Measured at 0 ms. */
213
229
  export const REAP_CONFIRM_MS = 100;
214
230
  /** How often an attached process (which is nobody's child, so has no `exit` event) is checked for. */
@@ -121,7 +121,7 @@
121
121
  export { bridgeDiagnostics } from './diagnostics.js';
122
122
  import type { JvmLauncher } from './jvm-transport.js';
123
123
  import { type JvmHostConfig } from './local-jvm.js';
124
- export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, type JvmAvailability, type JvmHostConfig, } from './local-jvm.js';
124
+ export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_JVM_FLAGS, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, type JvmAvailability, type JvmHostConfig, } from './local-jvm.js';
125
125
  export interface SeatSpec {
126
126
  /** Forge's player name. Shown to both seats, so never an identity. */
127
127
  name: string;
package/dist/play/host.js CHANGED
@@ -124,7 +124,7 @@ import { join } from 'node:path';
124
124
  import { jsonLogger } from '@wolffm/service-kernel/log';
125
125
  export { bridgeDiagnostics } from './diagnostics.js';
126
126
  import { JVM_HEAP_MB, MATCHES_PER_JVM, localJvmLauncher, writeFileAtomic } from './local-jvm.js';
127
- export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, } from './local-jvm.js';
127
+ export { BRIDGE_CACHE_MAX_AGE_MS, BRIDGE_JVM_FLAGS, CRASH_RECORD_FILES, CRASH_RECORD_MAX_AGE_MS, CRASH_RECORDS_KEPT, FORGE_HEARTBEAT_TIMEOUT_S, FORGE_JVM_FLAGS, FORGE_PREFERENCES, JVM_HEAP_MB, MATCHES_PER_JVM, bridgeLaunch, bridgeVersion, jvmHostConfig, liveJvmCount, stageRunDir, sweepRunDirs, writeFileAtomic, } from './local-jvm.js';
128
128
  const LIFECYCLE_T = new Set(['ready', 'fatal', 'frame', 'snapshot']);
129
129
  /** Narrows any engine's line onto the four the host itself understands. See {@link HostLifecycleLine}. */
130
130
  export function isLifecycle(line) {
@@ -87,12 +87,23 @@ import type { JvmLauncher } from './jvm-transport.js';
87
87
  */
88
88
  export declare const FORGE_HEARTBEAT_TIMEOUT_S = 86400;
89
89
  /**
90
- * Flags every bridge JVM gets, before the heap cap and the operator's `jvmOpts` (so a later flag
91
- * of theirs wins). `ExitOnOutOfMemoryError`: G1 has no GC-overhead limit, and without this a JVM
92
- * out of heap never exits — its games die of `OutOfMemoryError` and the JVM limps on
93
- * (hosting-test-plan B4: 62 % GC, act p99 14.6 s). With it the JVM exits (code 3), which fails
94
- * every match on it through the exit path.
90
+ * After this long without a GC, an idle JVM's G1 runs one on its own (JEP 346). That returns
91
+ * the committed heap a busy spell left behind, and walks the live set, so a quiet JVM keeps
92
+ * its live set paged in. Measured on the pool JVM, 2026-11-28: 190 MB live in 1.1–1.75 GB
93
+ * committed that was never handed back, and after a quiet spell 1.67 GB of it was in the
94
+ * cgroup's swap; with this, 340 MB committed, and one periodic GC paged 230 MB back from swap.
95
+ * A JVM doing work collects far more often than this, so it never fires there.
95
96
  */
97
+ export declare const JVM_IDLE_GC_MS = 300000;
98
+ /**
99
+ * Flags every Forge JVM gets (match bridges and the pool service), before its heap cap and the
100
+ * operator's `jvmOpts` (so a later flag of theirs wins). `ExitOnOutOfMemoryError`: G1 has no
101
+ * GC-overhead limit, and without this a JVM out of heap never exits — its games die of
102
+ * `OutOfMemoryError` and the JVM limps on (hosting-test-plan B4: 62 % GC, act p99 14.6 s). With
103
+ * it the JVM exits (code 3), which fails everything on it through the exit path.
104
+ */
105
+ export declare const FORGE_JVM_FLAGS: readonly string[];
106
+ /** {@link FORGE_JVM_FLAGS}, and Forge's client timeout far past any pause. */
96
107
  export declare const BRIDGE_JVM_FLAGS: readonly string[];
97
108
  export interface JvmHostConfig {
98
109
  java: string;
@@ -145,8 +156,9 @@ export declare const MATCHES_PER_JVM = 25;
145
156
  /**
146
157
  * Each JVM's heap cap: the budget for {@link MATCHES_PER_JVM} matches. A JVM is ~172 MB live idle
147
158
  * and ~10 MB per match (Wave 9 lane D; 4–9 MB in hosting-test-plan B3), so 25 matches live in
148
- * ~420 MB of a 2 GB heap. G1 does not hand committed heap back, so a JVM's RSS is budgeted at its
149
- * peak: ~2.3 GB with metaspace, code cache and Netty.
159
+ * ~420 MB of a 2 GB heap. G1 hands committed heap back only once the JVM is idle
160
+ * ({@link JVM_IDLE_GC_MS}), so a JVM's RSS is budgeted at its peak: ~2.3 GB with metaspace, code
161
+ * cache and Netty.
150
162
  */
151
163
  export declare const JVM_HEAP_MB = 2048;
152
164
  export type JvmAvailability = {
@@ -93,13 +93,24 @@ import { CRASH_MARKER, IN_FIFO, JVM_TMP_DIR, OUT_FIFO, PID_POLL_MS, REAP_CONFIRM
93
93
  */
94
94
  export const FORGE_HEARTBEAT_TIMEOUT_S = 86_400;
95
95
  /**
96
- * Flags every bridge JVM gets, before the heap cap and the operator's `jvmOpts` (so a later flag
97
- * of theirs wins). `ExitOnOutOfMemoryError`: G1 has no GC-overhead limit, and without this a JVM
98
- * out of heap never exits — its games die of `OutOfMemoryError` and the JVM limps on
99
- * (hosting-test-plan B4: 62 % GC, act p99 14.6 s). With it the JVM exits (code 3), which fails
100
- * every match on it through the exit path.
96
+ * After this long without a GC, an idle JVM's G1 runs one on its own (JEP 346). That returns
97
+ * the committed heap a busy spell left behind, and walks the live set, so a quiet JVM keeps
98
+ * its live set paged in. Measured on the pool JVM, 2026-11-28: 190 MB live in 1.1–1.75 GB
99
+ * committed that was never handed back, and after a quiet spell 1.67 GB of it was in the
100
+ * cgroup's swap; with this, 340 MB committed, and one periodic GC paged 230 MB back from swap.
101
+ * A JVM doing work collects far more often than this, so it never fires there.
101
102
  */
102
- export const BRIDGE_JVM_FLAGS = ['-XX:+ExitOnOutOfMemoryError', `-Dforge.net.heartbeatTimeout=${FORGE_HEARTBEAT_TIMEOUT_S}`];
103
+ export const JVM_IDLE_GC_MS = 300_000;
104
+ /**
105
+ * Flags every Forge JVM gets (match bridges and the pool service), before its heap cap and the
106
+ * operator's `jvmOpts` (so a later flag of theirs wins). `ExitOnOutOfMemoryError`: G1 has no
107
+ * GC-overhead limit, and without this a JVM out of heap never exits — its games die of
108
+ * `OutOfMemoryError` and the JVM limps on (hosting-test-plan B4: 62 % GC, act p99 14.6 s). With
109
+ * it the JVM exits (code 3), which fails everything on it through the exit path.
110
+ */
111
+ export const FORGE_JVM_FLAGS = ['-XX:+ExitOnOutOfMemoryError', `-XX:G1PeriodicGCInterval=${JVM_IDLE_GC_MS}`];
112
+ /** {@link FORGE_JVM_FLAGS}, and Forge's client timeout far past any pause. */
113
+ export const BRIDGE_JVM_FLAGS = [...FORGE_JVM_FLAGS, `-Dforge.net.heartbeatTimeout=${FORGE_HEARTBEAT_TIMEOUT_S}`];
103
114
  const AI_FLAT_MC_LEVELS = ['off', 'base', 'lite', 'max'];
104
115
  /** `CARDTABLE_AI_FLAT_MC`'s default. See docs/planning/flat-mc-ai.md for the measurement behind it. */
105
116
  export const AI_FLAT_MC = 'off';
@@ -123,8 +134,9 @@ export const MATCHES_PER_JVM = 25;
123
134
  /**
124
135
  * Each JVM's heap cap: the budget for {@link MATCHES_PER_JVM} matches. A JVM is ~172 MB live idle
125
136
  * and ~10 MB per match (Wave 9 lane D; 4–9 MB in hosting-test-plan B3), so 25 matches live in
126
- * ~420 MB of a 2 GB heap. G1 does not hand committed heap back, so a JVM's RSS is budgeted at its
127
- * peak: ~2.3 GB with metaspace, code cache and Netty.
137
+ * ~420 MB of a 2 GB heap. G1 hands committed heap back only once the JVM is idle
138
+ * ({@link JVM_IDLE_GC_MS}), so a JVM's RSS is budgeted at its peak: ~2.3 GB with metaspace, code
139
+ * cache and Netty.
128
140
  */
129
141
  export const JVM_HEAP_MB = 2048;
130
142
  /** Where compiled bridges are kept, shared by every tree on the host (keyed by `bridgeVersion`). */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-server",
3
- "version": "0.1.157",
4
- "gitHead": "dee59ea337ea7bd28ff9cf988fd38a539c43cbaa",
3
+ "version": "0.1.158",
4
+ "gitHead": "c0edfe5c5672ea00e058c777deeccc8963eba558",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any hosted game shares, above the kernel: the app config and edge auth, the room core (identity, seats, sessions, membership, the room list, the generic room routes), match hosting (the host contract, local and remote JVMs, placement, the start queue, recordings, the in-process and relay runtimes), streams, erase, telemetry and usage. Knows no game; Magic plugs in from apps/server. MIT; imports only node built-ins, express, socket.io, @wolffm/* and the platform packages.",
@@ -17,9 +17,9 @@
17
17
  "play/remote/"
18
18
  ],
19
19
  "dependencies": {
20
- "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.157",
21
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.157",
22
- "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.190",
20
+ "@wolffm/host-wire": "npm:@hadoku/host-wire@0.1.158",
21
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.158",
22
+ "@wolffm/service-kernel": "npm:@hadoku/service-kernel@0.1.191",
23
23
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
24
24
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.143",
25
25
  "@wolffm/rooms-server": "npm:@hadoku/rooms-server@^0.45.143",