@nxtedition/lib 27.0.1 → 27.0.3

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.
Files changed (3) hide show
  1. package/app.js +57 -17
  2. package/numa.js +8 -1
  3. package/package.json +2 -2
package/app.js CHANGED
@@ -363,22 +363,6 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
363
363
  }
364
364
  }
365
365
 
366
- let affinity = null
367
-
368
- if (process.platform === 'linux' && appConfig.numa != null && appConfig.numa !== '') {
369
- let numa = appConfig.numa
370
- if (numa == 'auto' || numa === true) {
371
- numa = hashString(JSON.stringify({ serviceName, serviceModule }))
372
- }
373
-
374
- try {
375
- affinity = setAffinity(numa)
376
- logger.debug({ data: { numa: appConfig.numa, affinity } }, 'set numa affinity succeeded')
377
- } catch (err) {
378
- logger.error({ err, data: { numa: appConfig.numa } }, 'set numa affinity failed')
379
- }
380
- }
381
-
382
366
  if (appConfig.toobusy) {
383
367
  const resolution = appConfig.toobusy.resolution ?? 10
384
368
  const interval = appConfig.toobusy.interval ?? 500
@@ -576,6 +560,63 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
576
560
  appDestroyers.unshift(() => ds.close())
577
561
  }
578
562
 
563
+ if (process.platform === 'linux' && appConfig.numa != null && appConfig.numa !== '') {
564
+ let numa = appConfig.numa
565
+ if (numa == 'auto' || numa === true) {
566
+ numa = hashString(
567
+ JSON.stringify({ serviceName, serviceModule, serviceInstanceId, serviceWorkerId }),
568
+ )
569
+ }
570
+
571
+ if (numa === 'net') {
572
+ if (config.hostname) {
573
+ if (!ds) {
574
+ throw new Error('deepstream is required for net numa')
575
+ }
576
+ ds.record
577
+ .observe(`${config.hostname}:monitor.stats?`, ds.record.PROVIDER)
578
+ .pipe(
579
+ rxjs.map((stats) => stats?.net?.bonding?.[0]?.numaNode ?? null),
580
+ rxjs.filter((n) => Number.isInteger(n) && n >= 0),
581
+ rxjs.timeout({
582
+ first: 10e3,
583
+ with: () => rxjs.of(null),
584
+ }),
585
+ rxjs.distinctUntilChanged(),
586
+ rxjs.retry({
587
+ resetOnSuccess: true,
588
+ delay(err, retryCount) {
589
+ logger.error({ err, retryCount }, 'net numa failed')
590
+ return rxjs.timer(10e3)
591
+ },
592
+ }),
593
+ )
594
+ .subscribe((numaNode) => {
595
+ if (numaNode != null) {
596
+ try {
597
+ const affinity = numa.setAffinity(numaNode)
598
+ logger.debug(
599
+ { hostname: config.hostname, numaNode, affinity },
600
+ 'net numa succeeded',
601
+ )
602
+ } catch (err) {
603
+ logger.error({ err, hostname: config.hostname, numaNode }, 'net numa failed')
604
+ }
605
+ } else {
606
+ logger.warn({ hostname: config.hostname, numaNode }, 'net numa missing')
607
+ }
608
+ })
609
+ }
610
+ } else {
611
+ try {
612
+ const affinity = setAffinity(numa)
613
+ logger.debug({ data: { numa: appConfig.numa, affinity } }, 'set numa affinity succeeded')
614
+ } catch (err) {
615
+ logger.error({ err, data: { numa: appConfig.numa } }, 'set numa affinity failed')
616
+ }
617
+ }
618
+ }
619
+
579
620
  if (appConfig.compiler) {
580
621
  compiler = makeTemplateCompiler({ ds, logger, ...appConfig.compiler })
581
622
  }
@@ -1289,6 +1330,5 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
1289
1330
  serviceInstanceId,
1290
1331
  serviceWorkerId,
1291
1332
  signal: ac.signal,
1292
- affinity,
1293
1333
  })
1294
1334
  }
package/numa.js CHANGED
@@ -4,10 +4,17 @@ import path from 'node:path'
4
4
  import { sched_setaffinity } from '@nxtedition/sched'
5
5
 
6
6
  function parseRange(value) {
7
+ if (typeof value !== 'string') {
8
+ throw new Error('CPU range must be a string')
9
+ }
10
+
7
11
  const range = []
8
12
  for (const part of value.split(',')) {
9
13
  if (part.includes('-')) {
10
- const [start, end] = part.split('-').map(Number)
14
+ const [start, end, ...rest] = part.split('-').map(Number)
15
+ if (rest.length > 0) {
16
+ throw new Error('Invalid CPU range')
17
+ }
11
18
  for (let i = start; i <= end; i++) {
12
19
  range.push(i)
13
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "27.0.1",
3
+ "version": "27.0.3",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -87,5 +87,5 @@
87
87
  "pino": ">=7.0.0",
88
88
  "rxjs": "^7.0.0"
89
89
  },
90
- "gitHead": "18e2d636f4420547cee8ac6ea96e32554d75a1eb"
90
+ "gitHead": "383b7fe1d10a8b7d80aa80ea81e7828f415d248d"
91
91
  }