@nxtedition/lib 26.0.29 → 26.0.31
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 +15 -6
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -317,7 +317,11 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
let affinity = null
|
|
320
|
-
if (
|
|
320
|
+
if (
|
|
321
|
+
process.platform === 'linux' &&
|
|
322
|
+
(isMainThread || appConfig.affinity != null) &&
|
|
323
|
+
appConfig.affinity !== false
|
|
324
|
+
) {
|
|
321
325
|
const allNodes = []
|
|
322
326
|
for (const entry of fs.readdirSync('/sys/devices/system/node')) {
|
|
323
327
|
if (!entry.startsWith('node')) {
|
|
@@ -341,28 +345,33 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
341
345
|
allNodes.push(cpus)
|
|
342
346
|
}
|
|
343
347
|
|
|
344
|
-
|
|
345
|
-
|
|
348
|
+
let indices = []
|
|
349
|
+
if (Number.isInteger(appConfig.affinity)) {
|
|
350
|
+
indices = [appConfig.affinity % allNodes.length]
|
|
346
351
|
} else if (appConfig.affinity == null) {
|
|
347
|
-
|
|
352
|
+
indices = [hashString(serviceName) % allNodes.length]
|
|
348
353
|
} else {
|
|
349
354
|
throw new Error('invalid affinity configuration: ' + appConfig.affinity)
|
|
350
355
|
}
|
|
351
356
|
|
|
357
|
+
affinity = indices.flatMap((i) => allNodes[i] ?? [])
|
|
352
358
|
affinity = fp.uniq(affinity)
|
|
353
359
|
affinity = fp.intersection(affinity, sched_getaffinity(0))
|
|
354
360
|
|
|
355
361
|
if (
|
|
356
362
|
!Array.isArray(affinity) ||
|
|
357
363
|
affinity.length === 0 ||
|
|
358
|
-
affinity.some((x) =>
|
|
364
|
+
affinity.some((x) => !Number.isInteger(x) || x < 0)
|
|
359
365
|
) {
|
|
360
366
|
throw new Error('invalid affinity configuration: ' + appConfig.affinity)
|
|
361
367
|
}
|
|
362
368
|
|
|
363
369
|
try {
|
|
364
370
|
sched_setaffinity(0, affinity)
|
|
365
|
-
logger.debug(
|
|
371
|
+
logger.debug(
|
|
372
|
+
{ data: { value: appConfig.affinity, affinity, indices } },
|
|
373
|
+
'sched_setaffinity succeeded',
|
|
374
|
+
)
|
|
366
375
|
} catch (err) {
|
|
367
376
|
logger.error({ err }, 'sched_setaffinity failed')
|
|
368
377
|
}
|