@nxtedition/lib 19.8.15 → 19.8.17
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 +30 -1
- package/couch.js +25 -11
- package/package.json +1 -2
package/app.js
CHANGED
|
@@ -7,7 +7,6 @@ import { Buffer } from 'node:buffer'
|
|
|
7
7
|
import { getDockerSecretsSync } from './docker-secrets.js'
|
|
8
8
|
import fp from 'lodash/fp.js'
|
|
9
9
|
import { isMainThread, parentPort, threadId } from 'node:worker_threads'
|
|
10
|
-
import toobusy from 'toobusy-js'
|
|
11
10
|
import deepstream from '@nxtedition/deepstream.io-client-js'
|
|
12
11
|
import { createLogger } from './logger.js'
|
|
13
12
|
import nconf from 'nconf'
|
|
@@ -216,7 +215,37 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
216
215
|
})
|
|
217
216
|
}
|
|
218
217
|
|
|
218
|
+
let toobusy
|
|
219
|
+
|
|
219
220
|
if (appConfig.toobusy) {
|
|
221
|
+
const { monitorEventLoopDelay } = require('node:perf_hooks')
|
|
222
|
+
|
|
223
|
+
const resolution = 10
|
|
224
|
+
const interval = 500
|
|
225
|
+
const maxLag = 70
|
|
226
|
+
|
|
227
|
+
let currentLag = 0
|
|
228
|
+
|
|
229
|
+
const histogram = monitorEventLoopDelay({ resolution })
|
|
230
|
+
histogram.enable()
|
|
231
|
+
|
|
232
|
+
setInterval(() => {
|
|
233
|
+
currentLag = Math.max(0, histogram.mean / 1e6 - resolution)
|
|
234
|
+
if (Number.isNaN(currentLag)) {
|
|
235
|
+
currentLag = Infinity
|
|
236
|
+
}
|
|
237
|
+
histogram.reset()
|
|
238
|
+
|
|
239
|
+
if (currentLag > 1e3) {
|
|
240
|
+
logger?.error({ currentLag }, 'lag')
|
|
241
|
+
} else {
|
|
242
|
+
logger?.warn({ currentLag }, 'lag')
|
|
243
|
+
}
|
|
244
|
+
}, interval).unref()
|
|
245
|
+
|
|
246
|
+
toobusy = () => currentLag > maxLag
|
|
247
|
+
toobusy.lag = () => currentLag
|
|
248
|
+
|
|
220
249
|
toobusy.onLag((currentLag) => {
|
|
221
250
|
if (currentLag > 1e3) {
|
|
222
251
|
logger.error({ currentLag }, 'lag')
|
package/couch.js
CHANGED
|
@@ -220,17 +220,31 @@ export function makeCouch(opts) {
|
|
|
220
220
|
const limit = options.limit
|
|
221
221
|
|
|
222
222
|
try {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
223
|
+
// Limit request duration to allow server to load balance.
|
|
224
|
+
const socketCount = 64 * 1024
|
|
225
|
+
let remaining = Number(limit) || Infinity
|
|
226
|
+
while (remaining > 0) {
|
|
227
|
+
let count = 0
|
|
228
|
+
for await (const changes of _changes({
|
|
229
|
+
batched,
|
|
230
|
+
live,
|
|
231
|
+
retry,
|
|
232
|
+
limit: Math.min(remaining, socketCount),
|
|
233
|
+
params,
|
|
234
|
+
method,
|
|
235
|
+
body,
|
|
236
|
+
signal: ac.signal,
|
|
237
|
+
client,
|
|
238
|
+
})) {
|
|
239
|
+
yield changes
|
|
240
|
+
count += changes.length
|
|
241
|
+
remaining -= changes.length
|
|
242
|
+
}
|
|
243
|
+
assert(remaining >= 0)
|
|
244
|
+
if (!live && count < socketCount) {
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
}
|
|
234
248
|
} finally {
|
|
235
249
|
ac.abort()
|
|
236
250
|
if (signal) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "19.8.
|
|
3
|
+
"version": "19.8.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -102,7 +102,6 @@
|
|
|
102
102
|
"request-target": "^1.0.2",
|
|
103
103
|
"smpte-timecode": "^1.3.6",
|
|
104
104
|
"split-string": "^6.0.0",
|
|
105
|
-
"toobusy-js": "^0.5.1",
|
|
106
105
|
"undici": "^6.19.2",
|
|
107
106
|
"url-join": "^5.0.0"
|
|
108
107
|
},
|