@nxtedition/lib 23.9.15 → 23.9.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 +36 -23
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -524,23 +524,27 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
524
524
|
rx.map(() => performance.eventLoopUtilization?.()),
|
|
525
525
|
rx.pairwise(),
|
|
526
526
|
rx.map(([elu1, elu2]) => {
|
|
527
|
-
const
|
|
527
|
+
const mem = process.memoryUsage()
|
|
528
528
|
const cpu = process.cpuUsage()
|
|
529
529
|
|
|
530
|
-
|
|
530
|
+
const memory = {
|
|
531
|
+
rss: mem.rss,
|
|
532
|
+
heapTotal: mem.heapTotal,
|
|
533
|
+
heapUsed: mem.heapUsed,
|
|
534
|
+
external: mem.external,
|
|
535
|
+
arrayBuffers: mem.arrayBuffers,
|
|
536
|
+
totalHeapTotal: 0,
|
|
537
|
+
totalHeapUsed: 0,
|
|
538
|
+
totalExternal: 0,
|
|
539
|
+
totalArrayBuffers: 0,
|
|
540
|
+
}
|
|
541
|
+
|
|
531
542
|
if (memoryUsageMap) {
|
|
532
|
-
totalMemory = {
|
|
533
|
-
rss: memory.rss,
|
|
534
|
-
heapTotal: 0,
|
|
535
|
-
heapUsed: 0,
|
|
536
|
-
external: 0,
|
|
537
|
-
arrayBuffers: 0,
|
|
538
|
-
}
|
|
539
543
|
for (const memoryUsage of memoryUsageMap.values()) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
+
memory.totalHeapTotal += memoryUsage.heapTotal
|
|
545
|
+
memory.totalHeapUsed += memoryUsage.heapUsed
|
|
546
|
+
memory.totalExternal += memoryUsage.external
|
|
547
|
+
memory.totalArrayBuffers += memoryUsage.arrayBuffers
|
|
544
548
|
}
|
|
545
549
|
}
|
|
546
550
|
|
|
@@ -552,7 +556,6 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
552
556
|
underPressure: underPressure?.isUnderPressure() ? underPressure.getPressure() : null,
|
|
553
557
|
cpu,
|
|
554
558
|
memory,
|
|
555
|
-
totalMemory,
|
|
556
559
|
resourceLimits,
|
|
557
560
|
utilization: performance.eventLoopUtilization?.(elu2, elu1),
|
|
558
561
|
heap: v8.getHeapStatistics(),
|
|
@@ -1009,20 +1012,28 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
1009
1012
|
const utilsBC = new BroadcastChannel('nxt:utils')
|
|
1010
1013
|
utilsBC.unref()
|
|
1011
1014
|
|
|
1015
|
+
function writeHeapSnapshot() {
|
|
1016
|
+
const snapshotPath = `${os.tmpdir()}/heap-${Date.now()}-${serviceName}-${serviceModule}-${serviceInstanceId}-${serviceWorkerId}.heapsnapshot`
|
|
1017
|
+
v8.writeHeapSnapshot(snapshotPath)
|
|
1018
|
+
logger.info({ snapshotPath }, 'heap snapshot')
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function gc() {
|
|
1022
|
+
if (global.gc) {
|
|
1023
|
+
global.gc()
|
|
1024
|
+
logger.debug('gc')
|
|
1025
|
+
} else {
|
|
1026
|
+
logger.warn('gc not available')
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1012
1030
|
utilsBC.onmessage = ({ data }) => {
|
|
1013
1031
|
const { type } = data
|
|
1014
1032
|
try {
|
|
1015
1033
|
if (type === 'utils:gc') {
|
|
1016
|
-
|
|
1017
|
-
global.gc()
|
|
1018
|
-
logger.debug('gc')
|
|
1019
|
-
} else {
|
|
1020
|
-
logger.warn('gc not available')
|
|
1021
|
-
}
|
|
1034
|
+
gc()
|
|
1022
1035
|
} else if (type === 'utils:writeHeapSnapshot') {
|
|
1023
|
-
|
|
1024
|
-
v8.writeHeapSnapshot(snapshotPath)
|
|
1025
|
-
logger.info({ snapshotPath }, 'heap snapshot')
|
|
1036
|
+
writeHeapSnapshot()
|
|
1026
1037
|
}
|
|
1027
1038
|
} catch (err) {
|
|
1028
1039
|
logger.error({ err, type })
|
|
@@ -1049,12 +1060,14 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
1049
1060
|
}
|
|
1050
1061
|
|
|
1051
1062
|
if (req.method === 'POST' && req.url === '/gc') {
|
|
1063
|
+
gc()
|
|
1052
1064
|
utilsBC.postMessage({ type: 'utils:gc' })
|
|
1053
1065
|
res.end()
|
|
1054
1066
|
return
|
|
1055
1067
|
}
|
|
1056
1068
|
|
|
1057
1069
|
if (req.method === 'POST' && req.url === '/writeHeapSnapshot') {
|
|
1070
|
+
writeHeapSnapshot()
|
|
1058
1071
|
utilsBC.postMessage({ type: 'utils:writeHeapSnapshot' })
|
|
1059
1072
|
res.end()
|
|
1060
1073
|
return
|