@nxtedition/lib 19.11.0 → 19.12.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 +17 -9
- package/package.json +4 -2
package/app.js
CHANGED
|
@@ -23,6 +23,8 @@ import compose from 'koa-compose'
|
|
|
23
23
|
import { createServer } from './http.js'
|
|
24
24
|
import { json } from 'node:stream/consumers'
|
|
25
25
|
import { monitorEventLoopDelay } from 'node:perf_hooks'
|
|
26
|
+
import { LRUCache } from 'lru-cache'
|
|
27
|
+
import xuid from 'xuid'
|
|
26
28
|
|
|
27
29
|
export function makeApp(appConfig, onTerminate) {
|
|
28
30
|
let ds
|
|
@@ -240,6 +242,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
240
242
|
const resolution = 10
|
|
241
243
|
const interval = 500
|
|
242
244
|
const maxLag = 70
|
|
245
|
+
const id = xuid()
|
|
243
246
|
|
|
244
247
|
const currentLag$ = new rxjs.BehaviorSubject(0)
|
|
245
248
|
const appLag$ = new rxjs.BehaviorSubject(0)
|
|
@@ -247,17 +250,20 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
247
250
|
const histogram = monitorEventLoopDelay({ resolution })
|
|
248
251
|
histogram.enable()
|
|
249
252
|
|
|
253
|
+
const lagMap = new LRUCache({ ttl: 10e3 })
|
|
254
|
+
|
|
250
255
|
const bc = new BroadcastChannel('nxt:lag')
|
|
251
256
|
|
|
252
|
-
const lagMap = new Map()
|
|
253
257
|
bc.onmessage = ({ data }) => {
|
|
254
|
-
|
|
255
|
-
lagMap.set(data.threadId, data.currentLag)
|
|
256
|
-
} else {
|
|
257
|
-
lagMap.delete(data.threadId)
|
|
258
|
-
}
|
|
258
|
+
lagMap.set(data.id, data.currentLag)
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
process.on('message', (data) => {
|
|
262
|
+
if (data?.type === 'nxt:lag') {
|
|
263
|
+
lagMap.set(data.id, data.currentLag)
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
|
|
261
267
|
const intervalHandle = setInterval(() => {
|
|
262
268
|
let currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
|
|
263
269
|
if (Number.isNaN(currentLag)) {
|
|
@@ -272,18 +278,20 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
272
278
|
}
|
|
273
279
|
|
|
274
280
|
currentLag$.next(currentLag)
|
|
275
|
-
bc.postMessage({
|
|
281
|
+
bc.postMessage({ id, currentLag })
|
|
282
|
+
|
|
283
|
+
process.send({ type: 'nxt:lag', id, currentLag })
|
|
276
284
|
|
|
277
285
|
let appLag = currentLag$.value
|
|
278
286
|
for (const lag of lagMap.values()) {
|
|
279
|
-
appLag = Math.max(appLag, lag)
|
|
287
|
+
appLag = Math.max(appLag, lag ?? 0)
|
|
280
288
|
}
|
|
281
289
|
appLag$.next(appLag)
|
|
282
290
|
}, interval).unref()
|
|
283
291
|
|
|
284
292
|
destroyers.unshift(() => {
|
|
285
293
|
clearInterval(intervalHandle)
|
|
286
|
-
bc.postMessage({
|
|
294
|
+
bc.postMessage({ id, currentLag: null })
|
|
287
295
|
})
|
|
288
296
|
|
|
289
297
|
toobusy = () => currentLag$.value > maxLag
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.12.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"json5": "^2.2.3",
|
|
66
66
|
"koa-compose": "^4.1.0",
|
|
67
67
|
"lodash": "^4.17.21",
|
|
68
|
+
"lru-cache": "^11.0.0",
|
|
68
69
|
"mime": "^4.0.4",
|
|
69
70
|
"moment-timezone": "^0.5.45",
|
|
70
71
|
"nconf": "^0.12.1",
|
|
@@ -77,7 +78,8 @@
|
|
|
77
78
|
"smpte-timecode": "^1.3.6",
|
|
78
79
|
"split-string": "^6.0.0",
|
|
79
80
|
"undici": "^6.19.7",
|
|
80
|
-
"url-join": "^5.0.0"
|
|
81
|
+
"url-join": "^5.0.0",
|
|
82
|
+
"xuid": "^4.1.3"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
83
85
|
"@nxtedition/deepstream.io-client-js": ">=25.6.3",
|