@nxtedition/lib 21.0.9 → 21.0.10
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 +18 -18
- package/couch.js +25 -18
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -255,9 +255,9 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
255
255
|
|
|
256
256
|
const lagMap = new LRUCache({ ttl: 10e3, max: 1024 })
|
|
257
257
|
|
|
258
|
-
const
|
|
258
|
+
const lagBC = new BroadcastChannel('nxt:lag')
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
lagBC.onmessage = ({ data }) => {
|
|
261
261
|
lagMap.set(data.id, data.currentLag)
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -267,7 +267,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
267
267
|
}
|
|
268
268
|
})
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
setInterval(() => {
|
|
271
271
|
let currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
|
|
272
272
|
if (Number.isNaN(currentLag)) {
|
|
273
273
|
currentLag = 0
|
|
@@ -281,8 +281,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
currentLag$.next(currentLag)
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
lagBC.postMessage({ id, currentLag })
|
|
286
285
|
process.send?.({ type: 'nxt:lag', id, currentLag })
|
|
287
286
|
|
|
288
287
|
let appLag = currentLag$.value ?? 0
|
|
@@ -292,11 +291,6 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
292
291
|
appLag$.next(appLag)
|
|
293
292
|
}, interval).unref()
|
|
294
293
|
|
|
295
|
-
destroyers.unshift(() => {
|
|
296
|
-
clearInterval(intervalHandle)
|
|
297
|
-
bc.postMessage({ id, currentLag: null })
|
|
298
|
-
})
|
|
299
|
-
|
|
300
294
|
toobusy = () => currentLag$.value > maxLag
|
|
301
295
|
toobusy.lag = () => currentLag$.value
|
|
302
296
|
toobusy.lag$ = currentLag$
|
|
@@ -471,6 +465,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
471
465
|
rx.pairwise(),
|
|
472
466
|
rx.map(([elu1, elu2]) => {
|
|
473
467
|
const memory = process.memoryUsage()
|
|
468
|
+
const cpu = process.cpuUsage()
|
|
474
469
|
|
|
475
470
|
let totalMemory
|
|
476
471
|
if (memoryUsageMap) {
|
|
@@ -494,6 +489,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
494
489
|
couch: couch?.stats,
|
|
495
490
|
lag: toobusy?.lag(),
|
|
496
491
|
version: process.version,
|
|
492
|
+
cpu,
|
|
497
493
|
memory,
|
|
498
494
|
totalMemory,
|
|
499
495
|
utilization: performance.eventLoopUtilization?.(elu2, elu1),
|
|
@@ -569,14 +565,18 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
569
565
|
rx.repeatWhen((complete$) => complete$.pipe(rx.delay(10e3))),
|
|
570
566
|
),
|
|
571
567
|
toobusy?.appLag$.pipe(
|
|
572
|
-
rx.map((lag) =>
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
568
|
+
rx.map((lag) =>
|
|
569
|
+
lag == null
|
|
570
|
+
? []
|
|
571
|
+
: [
|
|
572
|
+
{
|
|
573
|
+
id: 'app:toobusy_lag',
|
|
574
|
+
level: lag > 1e3 ? 50 : lag > toobusy.maxLag ? 40 : 30,
|
|
575
|
+
code: 'NXT_LAG',
|
|
576
|
+
msg: `Lag: ${lag.toFixed(2)} ms`,
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
),
|
|
580
580
|
) ?? rxjs.of([]),
|
|
581
581
|
couch
|
|
582
582
|
? rxjs.timer(0, 10e3).pipe(
|
package/couch.js
CHANGED
|
@@ -948,29 +948,36 @@ class StreamOutput extends stream.Readable {
|
|
|
948
948
|
lines[0] = this.#str + lines[0]
|
|
949
949
|
this.#str = lines.pop() ?? ''
|
|
950
950
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
if (this.#state === 0) {
|
|
957
|
-
if (line.endsWith('[')) {
|
|
958
|
-
this.#state = 1
|
|
959
|
-
} else {
|
|
960
|
-
throw new Error('unexpected data')
|
|
951
|
+
try {
|
|
952
|
+
let ret = true
|
|
953
|
+
for (const line of lines) {
|
|
954
|
+
if (!line) {
|
|
955
|
+
continue
|
|
961
956
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
957
|
+
if (this.#state === 0) {
|
|
958
|
+
if (/\[\s*$/.test(line)) {
|
|
959
|
+
this.#state = 1
|
|
960
|
+
} else {
|
|
961
|
+
throw Object.assign('expected [ at end of line')
|
|
962
|
+
}
|
|
963
|
+
} else if (this.#state === 1) {
|
|
964
|
+
if (/^\s*\]/.test(line)) {
|
|
965
|
+
this.#state = 2
|
|
966
|
+
} else {
|
|
967
|
+
const row = JSON.parse(line.slice(0, line.lastIndexOf('}') + 1))
|
|
968
|
+
if (!this.push(row)) {
|
|
969
|
+
ret = false
|
|
970
|
+
}
|
|
969
971
|
}
|
|
970
972
|
}
|
|
971
973
|
}
|
|
974
|
+
return ret
|
|
975
|
+
} catch (err) {
|
|
976
|
+
throw Object.assign(new Error('invalid data'), {
|
|
977
|
+
data: lines.join('\n') + this.#str,
|
|
978
|
+
cause: err,
|
|
979
|
+
})
|
|
972
980
|
}
|
|
973
|
-
return ret
|
|
974
981
|
}
|
|
975
982
|
|
|
976
983
|
onComplete() {
|