@platformatic/runtime 3.19.0 → 3.20.0

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/config.d.ts CHANGED
@@ -39,6 +39,7 @@ export type PlatformaticRuntimeConfig = {
39
39
  maxHeapUsed?: number | string;
40
40
  maxHeapTotal?: number | string;
41
41
  maxYoungGeneration?: number | string;
42
+ codeRangeSize?: number | string;
42
43
  };
43
44
  dependencies?: string[];
44
45
  arguments?: string[];
@@ -200,6 +201,7 @@ export type PlatformaticRuntimeConfig = {
200
201
  maxHeapUsed?: number | string;
201
202
  maxHeapTotal?: number | string;
202
203
  maxYoungGeneration?: number | string;
204
+ codeRangeSize?: number | string;
203
205
  };
204
206
  undici?: {
205
207
  agentOptions?: {
package/index.d.ts CHANGED
@@ -57,7 +57,7 @@ export module symbols {
57
57
  export declare const kHealthCheckTimer: unique symbol
58
58
  export declare const kHealthMetricsTimer: unique symbol
59
59
  export declare const kLastHealthCheckELU: unique symbol
60
- export declare const kLastVerticalScalerELU: unique symbol
60
+ export declare const kLastWorkerScalerELU: unique symbol
61
61
  export declare const kWorkerStatus: unique symbol
62
62
  export declare const kWorkerHealthSignals: unique symbol
63
63
  export declare const kStderrMarker: string
package/index.js CHANGED
@@ -63,7 +63,10 @@ export async function loadConfiguration (configOrRoot, sourceOrConfig, context)
63
63
  const { root, source } = await resolve(configOrRoot, sourceOrConfig, 'runtime')
64
64
 
65
65
  // First of all, load the configuration without any validation
66
- const config = await utilsLoadConfiguration(source)
66
+ const config = await utilsLoadConfiguration(source, null, {
67
+ root,
68
+ envFile: context?.envFile
69
+ })
67
70
  const mod = extractModuleFromSchemaUrl(config)
68
71
  if (mod?.module !== '@platformatic/runtime') {
69
72
  return wrapInRuntimeConfig(config, context)
package/lib/runtime.js CHANGED
@@ -24,7 +24,6 @@ import SonicBoom from 'sonic-boom'
24
24
  import { Agent, request, interceptors as undiciInterceptors } from 'undici'
25
25
  import { createThreadInterceptor } from 'undici-thread-interceptor'
26
26
  import { pprofCapturePreloadPath } from './config.js'
27
- import { DynamicWorkersScaler } from './dynamic-workers-scaler.js'
28
27
  import {
29
28
  ApplicationAlreadyStartedError,
30
29
  ApplicationNotFoundError,
@@ -45,6 +44,7 @@ import { startPrometheusServer } from './prom-server.js'
45
44
  import { startScheduler } from './scheduler.js'
46
45
  import { createSharedStore } from './shared-http-cache.js'
47
46
  import { version } from './version.js'
47
+ import { DynamicWorkersScaler } from './worker-scaler.js'
48
48
  import { HealthSignalsQueue } from './worker/health-signals.js'
49
49
  import { sendMultipleViaITC, sendViaITC, waitEventFromITC } from './worker/itc.js'
50
50
  import { RoundRobinMap } from './worker/round-robin-map.js'
@@ -206,7 +206,7 @@ export class Runtime extends EventEmitter {
206
206
  if (this.#config.workers.dynamic) {
207
207
  if (this.#config.workers.dynamic === false) {
208
208
  this.logger.warn(
209
- `Vertical scaler disabled because the "workers" configuration is set to ${this.#config.workers.static}.`
209
+ `Worker scaler disabled because the "workers" configuration is set to ${this.#config.workers.static}.`
210
210
  )
211
211
  } else {
212
212
  this.#dynamicWorkersScaler = new DynamicWorkersScaler(this, this.#config.workers)
@@ -698,7 +698,9 @@ export class Runtime extends EventEmitter {
698
698
 
699
699
  // TODO: Remove in next major version
700
700
  startCollectingMetrics () {
701
- this.logger.warn('startCollectingMetrics() is deprecated and no longer collects metrics. Metrics are now polled on-demand by the management API.')
701
+ this.logger.warn(
702
+ 'startCollectingMetrics() is deprecated and no longer collects metrics. Metrics are now polled on-demand by the management API.'
703
+ )
702
704
  }
703
705
 
704
706
  // TODO: Remove in next major version
@@ -1449,26 +1451,20 @@ export class Runtime extends EventEmitter {
1449
1451
  workerEnv.NODE_OPTIONS = `${originalNodeOptions} ${applicationConfig.nodeOptions}`.trim()
1450
1452
  }
1451
1453
 
1452
- let resourceLimits
1453
-
1454
- {
1455
- const maxHeapTotal =
1456
- typeof health.maxHeapTotal === 'string' ? parseMemorySize(health.maxHeapTotal) : health.maxHeapTotal
1457
- const maxYoungGeneration =
1458
- typeof health.maxYoungGeneration === 'string'
1459
- ? parseMemorySize(health.maxYoungGeneration)
1460
- : health.maxYoungGeneration
1454
+ const maxHeapTotal =
1455
+ typeof health.maxHeapTotal === 'string' ? parseMemorySize(health.maxHeapTotal) : health.maxHeapTotal
1456
+ const maxYoungGeneration =
1457
+ typeof health.maxYoungGeneration === 'string'
1458
+ ? parseMemorySize(health.maxYoungGeneration)
1459
+ : health.maxYoungGeneration
1460
+ const codeRangeSize =
1461
+ typeof health.codeRangeSize === 'string' ? parseMemorySize(health.codeRangeSize) : health.codeRangeSize
1461
1462
 
1462
- const maxOldGenerationSizeMb = maxHeapTotal ? Math.floor((maxYoungGeneration > 0 ? maxHeapTotal - maxYoungGeneration : maxHeapTotal) / (1024 * 1024)) : undefined
1463
- const maxYoungGenerationSizeMb = maxYoungGeneration ? Math.floor(maxYoungGeneration / (1024 * 1024)) : undefined
1464
-
1465
- if (maxOldGenerationSizeMb || maxYoungGenerationSizeMb) {
1466
- resourceLimits = {
1467
- maxOldGenerationSizeMb,
1468
- maxYoungGenerationSizeMb
1469
- }
1470
- }
1471
- }
1463
+ const maxOldGenerationSizeMb = Math.floor(
1464
+ (maxYoungGeneration > 0 ? maxHeapTotal - maxYoungGeneration : maxHeapTotal) / (1024 * 1024)
1465
+ )
1466
+ const maxYoungGenerationSizeMb = maxYoungGeneration ? Math.floor(maxYoungGeneration / (1024 * 1024)) : undefined
1467
+ const codeRangeSizeMb = codeRangeSize ? Math.floor(codeRangeSize / (1024 * 1024)) : undefined
1472
1468
 
1473
1469
  const worker = new Worker(kWorkerFile, {
1474
1470
  workerData: {
@@ -1492,7 +1488,11 @@ export class Runtime extends EventEmitter {
1492
1488
  argv: applicationConfig.arguments,
1493
1489
  execArgv,
1494
1490
  env: workerEnv,
1495
- resourceLimits,
1491
+ resourceLimits: {
1492
+ maxOldGenerationSizeMb,
1493
+ maxYoungGenerationSizeMb,
1494
+ codeRangeSizeMb
1495
+ },
1496
1496
  stdout: true,
1497
1497
  stderr: true
1498
1498
  })
@@ -10,7 +10,7 @@ export const kWorkerHealthSignals = Symbol.for('plt.runtime.worker.healthSignals
10
10
  export const kWorkerStartTime = Symbol.for('plt.runtime.worker.startTime')
11
11
  export const kInterceptors = Symbol.for('plt.runtime.worker.interceptors')
12
12
  export const kLastHealthCheckELU = Symbol.for('plt.runtime.worker.lastHealthCheckELU')
13
- export const kLastVerticalScalerELU = Symbol.for('plt.runtime.worker.lastVerticalScalerELU')
13
+ export const kLastWorkerScalerELU = Symbol.for('plt.runtime.worker.lastWorkerScalerELU')
14
14
 
15
15
  // This string marker should be safe to use since it belongs to Unicode private area
16
16
  export const kStderrMarker = '\ue002'
@@ -2,7 +2,7 @@ import { features } from '@platformatic/foundation'
2
2
  import { availableParallelism } from 'node:os'
3
3
  import { getMemoryInfo } from './metrics.js'
4
4
  import { ScalingAlgorithm, scaleUpELUThreshold } from './scaling-algorithm.js'
5
- import { kApplicationId, kId, kLastVerticalScalerELU, kWorkerStartTime, kWorkerStatus } from './worker/symbols.js'
5
+ import { kApplicationId, kId, kLastWorkerScalerELU, kWorkerStartTime, kWorkerStatus } from './worker/symbols.js'
6
6
 
7
7
  const healthCheckInterval = 1000
8
8
  export const kOriginalWorkers = Symbol('plt.runtime.application.dynamicWorkersScalerOriginalWorkers')
@@ -135,13 +135,13 @@ export class DynamicWorkersScaler {
135
135
  }
136
136
 
137
137
  try {
138
- const health = await this.#runtime.getWorkerHealth(worker, { previousELU: worker[kLastVerticalScalerELU] })
138
+ const health = await this.#runtime.getWorkerHealth(worker, { previousELU: worker[kLastWorkerScalerELU] })
139
139
 
140
140
  if (!health) {
141
141
  continue
142
142
  }
143
143
 
144
- worker[kLastVerticalScalerELU] = health.currentELU
144
+ worker[kLastWorkerScalerELU] = health.currentELU
145
145
 
146
146
  this.#algorithm.addWorkerHealthInfo({
147
147
  workerId: worker[kId],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.19.0",
3
+ "version": "3.20.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -35,14 +35,14 @@
35
35
  "typescript": "^5.5.4",
36
36
  "undici-oidc-interceptor": "^0.5.0",
37
37
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "3.19.0",
39
- "@platformatic/db": "3.19.0",
40
- "@platformatic/gateway": "3.19.0",
41
- "@platformatic/node": "3.19.0",
42
- "@platformatic/service": "3.19.0",
43
- "@platformatic/sql-mapper": "3.19.0",
44
- "@platformatic/sql-graphql": "3.19.0",
45
- "@platformatic/wattpm-pprof-capture": "3.19.0"
38
+ "@platformatic/composer": "3.20.0",
39
+ "@platformatic/db": "3.20.0",
40
+ "@platformatic/gateway": "3.20.0",
41
+ "@platformatic/service": "3.20.0",
42
+ "@platformatic/sql-graphql": "3.20.0",
43
+ "@platformatic/sql-mapper": "3.20.0",
44
+ "@platformatic/node": "3.20.0",
45
+ "@platformatic/wattpm-pprof-capture": "3.20.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@fastify/accepts": "^5.0.0",
@@ -71,12 +71,12 @@
71
71
  "undici": "^7.0.0",
72
72
  "undici-thread-interceptor": "^0.15.0",
73
73
  "ws": "^8.16.0",
74
- "@platformatic/basic": "3.19.0",
75
- "@platformatic/generators": "3.19.0",
76
- "@platformatic/foundation": "3.19.0",
77
- "@platformatic/telemetry": "3.19.0",
78
- "@platformatic/itc": "3.19.0",
79
- "@platformatic/metrics": "3.19.0"
74
+ "@platformatic/itc": "3.20.0",
75
+ "@platformatic/foundation": "3.20.0",
76
+ "@platformatic/generators": "3.20.0",
77
+ "@platformatic/metrics": "3.20.0",
78
+ "@platformatic/basic": "3.20.0",
79
+ "@platformatic/telemetry": "3.20.0"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.19.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.20.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",
@@ -187,6 +187,17 @@
187
187
  "type": "string"
188
188
  }
189
189
  ]
190
+ },
191
+ "codeRangeSize": {
192
+ "anyOf": [
193
+ {
194
+ "type": "number",
195
+ "minimum": 0
196
+ },
197
+ {
198
+ "type": "string"
199
+ }
200
+ ]
190
201
  }
191
202
  },
192
203
  "additionalProperties": false
@@ -469,6 +480,17 @@
469
480
  "type": "string"
470
481
  }
471
482
  ]
483
+ },
484
+ "codeRangeSize": {
485
+ "anyOf": [
486
+ {
487
+ "type": "number",
488
+ "minimum": 0
489
+ },
490
+ {
491
+ "type": "string"
492
+ }
493
+ ]
472
494
  }
473
495
  },
474
496
  "additionalProperties": false
@@ -749,6 +771,17 @@
749
771
  "type": "string"
750
772
  }
751
773
  ]
774
+ },
775
+ "codeRangeSize": {
776
+ "anyOf": [
777
+ {
778
+ "type": "number",
779
+ "minimum": 0
780
+ },
781
+ {
782
+ "type": "string"
783
+ }
784
+ ]
752
785
  }
753
786
  },
754
787
  "additionalProperties": false
@@ -1029,6 +1062,17 @@
1029
1062
  "type": "string"
1030
1063
  }
1031
1064
  ]
1065
+ },
1066
+ "codeRangeSize": {
1067
+ "anyOf": [
1068
+ {
1069
+ "type": "number",
1070
+ "minimum": 0
1071
+ },
1072
+ {
1073
+ "type": "string"
1074
+ }
1075
+ ]
1032
1076
  }
1033
1077
  },
1034
1078
  "additionalProperties": false
@@ -1626,7 +1670,8 @@
1626
1670
  {
1627
1671
  "type": "string"
1628
1672
  }
1629
- ]
1673
+ ],
1674
+ "default": 4294967296
1630
1675
  },
1631
1676
  "maxYoungGeneration": {
1632
1677
  "anyOf": [
@@ -1637,7 +1682,20 @@
1637
1682
  {
1638
1683
  "type": "string"
1639
1684
  }
1640
- ]
1685
+ ],
1686
+ "default": 134217728
1687
+ },
1688
+ "codeRangeSize": {
1689
+ "anyOf": [
1690
+ {
1691
+ "type": "number",
1692
+ "minimum": 0
1693
+ },
1694
+ {
1695
+ "type": "string"
1696
+ }
1697
+ ],
1698
+ "default": 268435456
1641
1699
  }
1642
1700
  },
1643
1701
  "additionalProperties": false