@nxtedition/lib 26.0.30 → 26.0.32

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 (2) hide show
  1. package/app.js +17 -6
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -345,28 +345,39 @@ export function makeApp(appConfig, onTerminate) {
345
345
  allNodes.push(cpus)
346
346
  }
347
347
 
348
- if (Number.isInteger(appConfig.affinity) && appConfig.affinity >= 0) {
349
- affinity = allNodes[appConfig.affinity % allNodes.length]
350
- } else if (appConfig.affinity == null) {
351
- affinity = allNodes[hashString(serviceName) % allNodes.length]
348
+ let indices = []
349
+ if (Number.isInteger(appConfig.affinity)) {
350
+ indices = [appConfig.affinity % allNodes.length]
351
+ } else if (
352
+ appConfig.affinity == null ||
353
+ appConfig.affinity === true ||
354
+ appConfig.affinity === 'auto' ||
355
+ appConfig.affinity === 'hash' ||
356
+ appConfig.affinity === 'default'
357
+ ) {
358
+ indices = [hashString(serviceName) % allNodes.length]
352
359
  } else {
353
360
  throw new Error('invalid affinity configuration: ' + appConfig.affinity)
354
361
  }
355
362
 
363
+ affinity = indices.flatMap((i) => allNodes[i] ?? [])
356
364
  affinity = fp.uniq(affinity)
357
365
  affinity = fp.intersection(affinity, sched_getaffinity(0))
358
366
 
359
367
  if (
360
368
  !Array.isArray(affinity) ||
361
369
  affinity.length === 0 ||
362
- affinity.some((x) => typeof x !== 'number' || x < 0)
370
+ affinity.some((x) => !Number.isInteger(x) || x < 0)
363
371
  ) {
364
372
  throw new Error('invalid affinity configuration: ' + appConfig.affinity)
365
373
  }
366
374
 
367
375
  try {
368
376
  sched_setaffinity(0, affinity)
369
- logger.debug({ data: { value: appConfig.affinity, affinity } }, 'sched_setaffinity succeeded')
377
+ logger.debug(
378
+ { data: { value: appConfig.affinity, affinity, indices } },
379
+ 'sched_setaffinity succeeded',
380
+ )
370
381
  } catch (err) {
371
382
  logger.error({ err }, 'sched_setaffinity failed')
372
383
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "26.0.30",
3
+ "version": "26.0.32",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",