@nxtedition/lib 26.1.0 → 26.3.1

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 CHANGED
@@ -317,13 +317,9 @@ export function makeApp(appConfig, onTerminate) {
317
317
 
318
318
  let affinity = null
319
319
 
320
- if (
321
- process.platform === 'linux' &&
322
- (isMainThread || appConfig.numa != null) &&
323
- appConfig.numa !== false
324
- ) {
320
+ if (process.platform === 'linux' && appConfig.numa != null && appConfig.numa !== '') {
325
321
  let numa = appConfig.numa
326
- if (numa == null || numa === true) {
322
+ if (numa == 'auto' || numa === true) {
327
323
  numa = hashString(JSON.stringify({ serviceName, serviceModule }))
328
324
  }
329
325
 
@@ -673,6 +669,7 @@ export function makeApp(appConfig, onTerminate) {
673
669
  underPressure: underPressure?.isUnderPressure() ? underPressure.getPressure() : null,
674
670
  cpu,
675
671
  memory,
672
+ affinity: globalThis.__nxt_sched_affinity,
676
673
  resourceLimits,
677
674
  utilization: performance.eventLoopUtilization?.(elu2, elu1),
678
675
  heap: v8.getHeapStatistics(),
package/numa.js CHANGED
@@ -3,7 +3,17 @@ import path from 'node:path'
3
3
 
4
4
  import { sched_setaffinity } from '@nxtedition/sched'
5
5
 
6
+ /**
7
+ *
8
+ * @param {number|number[]} numa
9
+ * @returns {number[]}
10
+ */
6
11
  export function setAffinity(numa) {
12
+ const indices = Array.from(new Set([numa].flat()))
13
+ if (indices.some((x) => !Number.isInteger(x) || x < 0)) {
14
+ throw new Error('NUMA node must be a non-negative integer')
15
+ }
16
+
7
17
  const allNodes = []
8
18
  for (const entry of fs.readdirSync('/sys/devices/system/node')) {
9
19
  if (!entry.startsWith('node')) {
@@ -31,12 +41,11 @@ export function setAffinity(numa) {
31
41
  throw new Error('No NUMA nodes found')
32
42
  }
33
43
 
34
- if (!Number.isInteger(numa) || numa < 0) {
35
- throw new Error('NUMA node must be a non-negative integer')
36
- }
37
-
38
- const indices = [numa % allNodes.length]
39
- const affinity = indices.flatMap((i) => allNodes[i] ?? [])
44
+ const affinity = indices.flatMap((i) => allNodes[i % allNodes.length] ?? [])
40
45
  sched_setaffinity(0, affinity)
46
+ globalThis.__nxt_sched_affinity = {
47
+ cpulist: affinity,
48
+ nodelist: indices,
49
+ }
41
50
  return affinity
42
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "26.1.0",
3
+ "version": "26.3.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { first, timeout as rxTimeout } from 'rxjs'
1
+ import * as rxjs from 'rxjs'
2
2
  import withAbortSignal from './withAbortSignal.js'
3
3
 
4
4
  export default function firstValueFrom(x$, config) {
@@ -11,8 +11,8 @@ export default function firstValueFrom(x$, config) {
11
11
  }
12
12
 
13
13
  if (timeout) {
14
- x$ = x$.pipe(rxTimeout(timeout))
14
+ x$ = x$.pipe(rxjs.timeout(timeout))
15
15
  }
16
16
 
17
- return x$.pipe(first(hasConfig ? config.defaultValue : undefined)).toPromise()
17
+ return rxjs.firstValueFrom(x$, config)
18
18
  }
@@ -150,16 +150,22 @@ class ObservableEntry {
150
150
  this.value = kEmpty
151
151
  this.error = null
152
152
  this.refresh = refresh
153
+ this.sync = true
153
154
  this.subscription = observable.subscribe({
154
155
  next: (value) => {
155
156
  this.value = value
156
- this.refresh()
157
+ if (!this.sync) {
158
+ this.refresh()
159
+ }
157
160
  },
158
161
  error: (err) => {
159
162
  this.error = err
160
- this.refresh()
163
+ if (!this.sync) {
164
+ this.refresh()
165
+ }
161
166
  },
162
167
  })
168
+ this.sync = false
163
169
  }
164
170
 
165
171
  dispose() {