fluxion-ts 0.6.1 → 0.8.2

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/README.md CHANGED
@@ -286,7 +286,7 @@ interface FluxionOptions {
286
286
  nativeWatcher?: boolean;
287
287
  injections?: InjectionConfig[];
288
288
  moduleDir?: string;
289
- workerOptions?: Partial<WorkerOptions>;
289
+ workerOptions?: WorkerOptions;
290
290
  maxRequestBytes?: number;
291
291
  logger?: 'one-line' | 'json-line' | InjectionConfig;
292
292
  apiExts?: string[];
@@ -393,24 +393,46 @@ globalThis[Symbol.for('fluxion.injection')]
393
393
 
394
394
  ### `workerOptions`
395
395
 
396
- Runtime tuning options:
396
+ Worker pool tuning: how many workers to spawn, and when to proactively recycle one.
397
397
 
398
398
  ```ts
399
399
  interface WorkerOptions {
400
- maxWorkerCount: number;
401
- requestTimeoutMs: number;
402
- maxInflight: number;
403
- memorySoftLimitMb: number;
404
- memoryHardLimitMb: number;
405
- memorySampleIntervalMs: number;
406
- maxOldGenerationSizeMb: number;
407
- maxYoungGenerationSizeMb: number;
408
- stackSizeMb: number;
409
- maxResponseBytes: number;
400
+ maxWorkerCount?: number;
401
+ restartWhen?: Partial<WorkerRestartWhen>;
402
+ }
403
+
404
+ interface WorkerRestartWhen {
405
+ /** Recycle when RSS exceeds this many MB. Infinity (default) = disabled. */
406
+ memoryUsageGreaterThan: number;
407
+ /** Recycle when no Ping answer within this many ms. Default 30000. */
408
+ healthzTimeout: number;
409
+ /** Recycle after this many ms of uptime (scheduled rotation). Infinity (default) = disabled. */
410
+ uptimeGreaterThan: number;
410
411
  }
411
412
  ```
412
413
 
413
- Current implementation uses `maxWorkerCount` for process count and reports CPU/memory telemetry from workers.
414
+ - `maxWorkerCount` defaults to `4`, clamped to the CPU count (minimum 1).
415
+ - `restartWhen` lets the primary proactively recycle an unhealthy worker. The worker is hard-killed and immediately respawned when **any** configured condition is met (OR semantics):
416
+ - `memoryUsageGreaterThan` — RSS growth / native leak, caught before the OS OOM-killer. Disabled by default.
417
+ - `healthzTimeout` — a wedged event loop (worker stopped answering Ping: infinite loop, deadlock, GC storm). **Defaults to `30000`ms.**
418
+ - `uptimeGreaterThan` — scheduled rotation to reclaim slow growth / fragmentation. Disabled by default.
419
+ - Conditions are evaluated by the primary against the telemetry it already collects (RSS from stats every ~2s, liveness from Ping every 5s, uptime).
420
+ - A shared **anti-storm guard** bounds recycling: a given slot is restarted at most 3 times per rolling 60s, after which further restarts are suppressed and alerted instead of fork-bombing.
421
+ - Independently of `restartWhen`, **any worker exit — crash, OOM, or proactive recycle — triggers a respawn**, so the pool stays at `maxWorkerCount`.
422
+
423
+ ```ts
424
+ fluxion({
425
+ // ...
426
+ workerOptions: {
427
+ maxWorkerCount: 4,
428
+ restartWhen: {
429
+ memoryUsageGreaterThan: 256, // MB; recycle a leaking worker at 256MB RSS
430
+ // healthzTimeout defaults to 30000 — recycle wedged workers after 30s
431
+ // uptimeGreaterThan: 6 * 3600_000, // optionally rotate every 6h
432
+ },
433
+ },
434
+ });
435
+ ```
414
436
 
415
437
  ### `https`
416
438
 
@@ -525,24 +547,46 @@ globalThis[Symbol.for('fluxion.injection')]
525
547
 
526
548
  ### `workerOptions`
527
549
 
528
- Runtime tuning options:
550
+ Worker pool tuning: how many workers to spawn, and when to proactively recycle one.
529
551
 
530
552
  ```ts
531
553
  interface WorkerOptions {
532
- maxWorkerCount: number;
533
- requestTimeoutMs: number;
534
- maxInflight: number;
535
- memorySoftLimitMb: number;
536
- memoryHardLimitMb: number;
537
- memorySampleIntervalMs: number;
538
- maxOldGenerationSizeMb: number;
539
- maxYoungGenerationSizeMb: number;
540
- stackSizeMb: number;
541
- maxResponseBytes: number;
554
+ maxWorkerCount?: number;
555
+ restartWhen?: Partial<WorkerRestartWhen>;
556
+ }
557
+
558
+ interface WorkerRestartWhen {
559
+ /** Recycle when RSS exceeds this many MB. Infinity (default) = disabled. */
560
+ memoryUsageGreaterThan: number;
561
+ /** Recycle when no Ping answer within this many ms. Default 30000. */
562
+ healthzTimeout: number;
563
+ /** Recycle after this many ms of uptime (scheduled rotation). Infinity (default) = disabled. */
564
+ uptimeGreaterThan: number;
542
565
  }
543
566
  ```
544
567
 
545
- Current implementation uses `maxWorkerCount` for process count and reports CPU/memory telemetry from workers.
568
+ - `maxWorkerCount` defaults to `4`, clamped to the CPU count (minimum 1).
569
+ - `restartWhen` lets the primary proactively recycle an unhealthy worker. The worker is hard-killed and immediately respawned when **any** configured condition is met (OR semantics):
570
+ - `memoryUsageGreaterThan` — RSS growth / native leak, caught before the OS OOM-killer. Disabled by default.
571
+ - `healthzTimeout` — a wedged event loop (worker stopped answering Ping: infinite loop, deadlock, GC storm). **Defaults to `30000`ms.**
572
+ - `uptimeGreaterThan` — scheduled rotation to reclaim slow growth / fragmentation. Disabled by default.
573
+ - Conditions are evaluated by the primary against the telemetry it already collects (RSS from stats every ~2s, liveness from Ping every 5s, uptime).
574
+ - A shared **anti-storm guard** bounds recycling: a given slot is restarted at most 3 times per rolling 60s, after which further restarts are suppressed and alerted instead of fork-bombing.
575
+ - Independently of `restartWhen`, **any worker exit — crash, OOM, or proactive recycle — triggers a respawn**, so the pool stays at `maxWorkerCount`.
576
+
577
+ ```ts
578
+ fluxion({
579
+ // ...
580
+ workerOptions: {
581
+ maxWorkerCount: 4,
582
+ restartWhen: {
583
+ memoryUsageGreaterThan: 256, // MB; recycle a leaking worker at 256MB RSS
584
+ // healthzTimeout defaults to 30000 — recycle wedged workers after 30s
585
+ // uptimeGreaterThan: 6 * 3600_000, // optionally rotate every 6h
586
+ },
587
+ },
588
+ });
589
+ ```
546
590
 
547
591
  ## Build and Test
548
592