@nxtedition/lib 28.0.7 → 28.0.9
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 +44 -29
- package/package.json +2 -2
- package/sequence.js +5 -9
- package/shared.js +12 -1
package/app.js
CHANGED
|
@@ -635,19 +635,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
635
635
|
stats$ = rxjs.timer(0, 10e3).pipe(rx.map(() => ({})))
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
let memoryUsageMap
|
|
641
|
-
if (isMainThread) {
|
|
642
|
-
memoryUsageMap = new Map()
|
|
643
|
-
memoryUsageBC.onmessage = ({ data: { data, id } }) => {
|
|
644
|
-
memoryUsageMap.set(id, data)
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
setInterval(() => {
|
|
649
|
-
memoryUsageBC.postMessage({ data: process.memoryUsage(), id: serviceWorkerId })
|
|
650
|
-
}, 1e3).unref()
|
|
638
|
+
let statsMap
|
|
651
639
|
|
|
652
640
|
const startTime = Date.now()
|
|
653
641
|
stats$ = stats$.pipe(
|
|
@@ -679,12 +667,27 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
679
667
|
totalArrayBuffers: 0,
|
|
680
668
|
}
|
|
681
669
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
670
|
+
const http = {
|
|
671
|
+
userAgent,
|
|
672
|
+
pending: globalThis._nxt_lib_http_pending?.size,
|
|
673
|
+
totalPending: 0,
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const undici = {
|
|
677
|
+
sockets: globalThis.__undici_sockets?.size ?? 0,
|
|
678
|
+
totalSockets: 0,
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
if (statsMap) {
|
|
682
|
+
for (const stats of statsMap.values()) {
|
|
683
|
+
memory.totalHeapTotal += stats.memory?.heapTotal ?? 0
|
|
684
|
+
memory.totalHeapUsed += stats.memory?.heapUsed ?? 0
|
|
685
|
+
memory.totalExternal += stats.memory?.external ?? 0
|
|
686
|
+
memory.totalArrayBuffers += stats.memory?.arrayBuffers ?? 0
|
|
687
|
+
|
|
688
|
+
http.totalPending += stats.http?.pending ?? 0
|
|
689
|
+
|
|
690
|
+
undici.totalSockets += stats.undici?.sockets ?? 0
|
|
688
691
|
}
|
|
689
692
|
}
|
|
690
693
|
|
|
@@ -700,13 +703,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
700
703
|
resourceLimits,
|
|
701
704
|
utilization: performance.eventLoopUtilization?.(elu2, elu1),
|
|
702
705
|
heap: v8.getHeapStatistics(),
|
|
703
|
-
http
|
|
704
|
-
|
|
705
|
-
pending: globalThis._nxt_lib_http_pending?.size,
|
|
706
|
-
},
|
|
707
|
-
undici: {
|
|
708
|
-
sockets: globalThis.__undici_sockets?.size ?? 0,
|
|
709
|
-
},
|
|
706
|
+
http,
|
|
707
|
+
undici,
|
|
710
708
|
}
|
|
711
709
|
}),
|
|
712
710
|
),
|
|
@@ -726,11 +724,20 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
726
724
|
rx.refCount(),
|
|
727
725
|
)
|
|
728
726
|
|
|
727
|
+
const statsBC = new BroadcastChannel('nxt:app:stats').unref()
|
|
728
|
+
if (isMainThread) {
|
|
729
|
+
statsMap = new Map()
|
|
730
|
+
statsBC.onmessage = ({ data: { data, id } }) => {
|
|
731
|
+
statsMap.set(id, data)
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
729
735
|
monitorProviders.stats$ = stats$
|
|
730
736
|
|
|
731
737
|
if (process.env.NODE_ENV === 'production') {
|
|
732
738
|
appDestroyers.unshift(
|
|
733
739
|
stats$.pipe(rx.auditTime(10e3)).subscribe((stats) => {
|
|
740
|
+
statsBC.postMessage({ id: threadId, data: stats })
|
|
734
741
|
logger.debug(stats, 'STATS')
|
|
735
742
|
}),
|
|
736
743
|
)
|
|
@@ -779,7 +786,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
779
786
|
rx.repeatWhen((complete$) => complete$.pipe(rx.delay(10e3))),
|
|
780
787
|
),
|
|
781
788
|
stats$.pipe(
|
|
782
|
-
rx.map(({ memory, heap, utilization, undici }) => {
|
|
789
|
+
rx.map(({ memory, heap, utilization, undici, http }) => {
|
|
783
790
|
const messages = []
|
|
784
791
|
|
|
785
792
|
if (memory?.containerLimit) {
|
|
@@ -812,8 +819,16 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
812
819
|
if (undici) {
|
|
813
820
|
messages.push({
|
|
814
821
|
id: 'app:undici_upstream_sockets',
|
|
815
|
-
level: undici.
|
|
816
|
-
msg: `Undici: ${undici.
|
|
822
|
+
level: undici.totalSockets > 8192 ? 50 : undici.totalSockets > 4096 ? 40 : 30,
|
|
823
|
+
msg: `Undici: ${undici.totalSockets} upstream connected`,
|
|
824
|
+
})
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
if (http) {
|
|
828
|
+
messages.push({
|
|
829
|
+
id: 'app:http_pending_requests',
|
|
830
|
+
level: http.totalPending > 8192 ? 50 : http.totalPending > 4096 ? 40 : 30,
|
|
831
|
+
msg: `HTTP: ${http.totalPending} pending requests`,
|
|
817
832
|
})
|
|
818
833
|
}
|
|
819
834
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "28.0.
|
|
3
|
+
"version": "28.0.9",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"pino": ">=7.0.0",
|
|
93
93
|
"rxjs": "^7.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "c387129cb7a362f64690cfef28d51ee98f0ab87c"
|
|
96
96
|
}
|
package/sequence.js
CHANGED
|
@@ -98,8 +98,8 @@ export class Sequence {
|
|
|
98
98
|
this.#identity = identity
|
|
99
99
|
for (const part of value) {
|
|
100
100
|
if (typeof part === 'string') {
|
|
101
|
-
const [sequenceStr, id] = part.split(ID_SEP)
|
|
102
|
-
const sequence =
|
|
101
|
+
const [sequenceStr, id] = part.split(ID_SEP, 2)
|
|
102
|
+
const sequence = Number(sequenceStr)
|
|
103
103
|
this.#parts.push(id, sequence)
|
|
104
104
|
this.#identity = null
|
|
105
105
|
this.#count += part
|
|
@@ -116,15 +116,15 @@ export class Sequence {
|
|
|
116
116
|
}
|
|
117
117
|
assert(this.#identity === 0 || this.#parts.length > 0)
|
|
118
118
|
} else if (typeof value === 'string') {
|
|
119
|
-
const [countStr, token] = value.split('-')
|
|
119
|
+
const [countStr, token] = value.split('-', 2)
|
|
120
120
|
if (token) {
|
|
121
121
|
for (const str of token.split('_')) {
|
|
122
122
|
const [sequenceStr, id] = str.split(ID_SEP)
|
|
123
|
-
const sequence =
|
|
123
|
+
const sequence = Number(sequenceStr)
|
|
124
124
|
this.#parts.push(id, sequence)
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
this.#count =
|
|
127
|
+
this.#count = Number(countStr)
|
|
128
128
|
this.#value = value
|
|
129
129
|
} else if (value instanceof Sequence) {
|
|
130
130
|
this.#count = value.#count
|
|
@@ -139,10 +139,6 @@ export class Sequence {
|
|
|
139
139
|
throw new Error('invalid sequence count')
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
if (!Array.isArray(this.#parts)) {
|
|
143
|
-
throw new Error('invalid sequence parts')
|
|
144
|
-
}
|
|
145
|
-
|
|
146
142
|
{
|
|
147
143
|
let count = 0
|
|
148
144
|
for (let n = 0; n < this.#parts.length; n += 2) {
|
package/shared.js
CHANGED
|
@@ -18,11 +18,22 @@ const HWM_COUNT = 1024 // 1024 items
|
|
|
18
18
|
* @returns {{sharedState: SharedArrayBuffer, sharedBuffer: SharedArrayBuffer}}
|
|
19
19
|
*/
|
|
20
20
|
export function alloc(size) {
|
|
21
|
+
if (!Number.isInteger(size)) {
|
|
22
|
+
throw new TypeError('size must be a positive integer')
|
|
23
|
+
}
|
|
24
|
+
if (size <= 0) {
|
|
25
|
+
throw new RangeError('size must be a positive integer')
|
|
26
|
+
}
|
|
27
|
+
if (size >= 2 ** 31 - 8) {
|
|
28
|
+
throw new RangeError('size exceeds maximum of 2GB minus header size')
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
return {
|
|
22
32
|
// A small buffer for sharing state (read/write pointers).
|
|
23
33
|
sharedState: new SharedArrayBuffer(128),
|
|
24
34
|
// The main buffer for transferring data.
|
|
25
|
-
|
|
35
|
+
// We need another 8 bytes for entry headers.
|
|
36
|
+
sharedBuffer: new SharedArrayBuffer(size + 8),
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
|