@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.
- package/app.js +17 -6
- 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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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) =>
|
|
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(
|
|
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
|
}
|