From 6760c1188152027ddd1c5acc847297317eba409a Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 31 Dec 2021 01:45:03 +0100 Subject: [PATCH] Disabled why-is-node-running to assess OOM. --- config/default.js | 1 + src/app.js | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/config/default.js b/config/default.js index 61e44d46d..4227312e0 100644 --- a/config/default.js +++ b/config/default.js @@ -318,6 +318,7 @@ module.exports = { missingDateLimit: 3, memorySampling: { enabled: false, + sampleDuration: 300000, // 5 minutes snapshotIntervals: [], }, media: { diff --git a/src/app.js b/src/app.js index 430308922..85d1d8d8f 100644 --- a/src/app.js +++ b/src/app.js @@ -2,7 +2,7 @@ const config = require('config'); const util = require('util'); -const log = require('why-is-node-running'); +// const log = require('why-is-node-running'); const Inspector = require('inspector-api'); const fs = require('fs').promises; const dayjs = require('dayjs'); @@ -25,6 +25,7 @@ const getFileEntries = require('./utils/file-entries'); const inspector = new Inspector(); let done = false; +/* function logActive() { setTimeout(() => { log(); @@ -34,10 +35,11 @@ function logActive() { } }, typeof argv.logActive === 'number' ? argv.logActive : 60000); } +*/ -async function snapshotMemory() { +async function snapshotMemory(trigger) { const profile = await inspector.heap.takeSnapshot(); - const filepath = `traxxx_snapshot_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapprofile`; + const filepath = `traxxx_snapshot_${trigger}M_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapsnapshot`; logger.info(`Starting heap snapshot, memory usage: ${process.memoryUsage.rss() / 1000000} MB`); @@ -48,9 +50,10 @@ async function snapshotMemory() { } async function stopMemorySample(snapshotTriggers) { + const usage = process.memoryUsage.rss() / 1000000; + const profile = await inspector.heap.stopSampling(); const filepath = `traxxx_sample_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapprofile`; - const usage = process.memoryUsage.rss() / 1000000; await inspector.heap.disable(); await fs.writeFile(filepath, JSON.stringify(profile)); @@ -58,7 +61,7 @@ async function stopMemorySample(snapshotTriggers) { logger.info(`Saved heap sample to ${filepath}`); if (usage > snapshotTriggers[0]) { - await snapshotMemory(); + await snapshotMemory(snapshotTriggers[0]); return snapshotTriggers.slice(1); } @@ -79,22 +82,22 @@ async function startMemorySample(snapshotTriggers = []) { if (!done) { await startMemorySample(newSnapshotTriggers); } - }, 30000); + }, config.memorySampling.sampleDuration); } async function init() { try { + if (argv.server) { + await initServer(); + return; + } + if (argv.sampleMemory) { await startMemorySample(config.memorySampling.snapshotIntervals); } if (argv.logActive) { - logActive(); - } - - if (argv.server) { - await initServer(); - return; + // logActive(); } if (argv.updateSearch) {