Added centralized movie page fetcher. Added memory heap dump.
This commit is contained in:
29
src/app.js
29
src/app.js
@@ -34,33 +34,40 @@ function logActive() {
|
||||
}, typeof argv.logActive === 'number' ? argv.logActive : 60000);
|
||||
}
|
||||
|
||||
/*
|
||||
function monitorMemory() {
|
||||
logger.debug(`Memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
|
||||
async function snapshotMemory() {
|
||||
const profile = await inspector.heap.takeSnapshot();
|
||||
const filepath = `${dayjs().format('traxxx_snapshot_YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
||||
|
||||
if (!done) {
|
||||
setTimeout(() => monitorMemory(), 10000);
|
||||
}
|
||||
logger.info(`Start heap snapshots, memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
|
||||
|
||||
await inspector.heap.disable();
|
||||
await fs.writeFile(filepath, JSON.stringify(profile));
|
||||
|
||||
logger.info(`Saved heap dump to ${filepath}`);
|
||||
}
|
||||
*/
|
||||
|
||||
async function stopMemorySample() {
|
||||
const profile = await inspector.heap.stopSampling();
|
||||
const filepath = `${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
||||
const filepath = `${dayjs().format('traxxx_sample_YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
||||
const usage = process.memoryUsage.rss() / 1000000;
|
||||
|
||||
await inspector.heap.disable();
|
||||
await fs.writeFile(filepath, JSON.stringify(profile));
|
||||
|
||||
logger.info(`Saved heap sample to ${filepath}`);
|
||||
|
||||
if (usage > 1000) {
|
||||
await snapshotMemory();
|
||||
}
|
||||
}
|
||||
|
||||
async function startMemorySample() {
|
||||
await inspector.heap.enable();
|
||||
await inspector.heap.startSampling();
|
||||
|
||||
// monitorMemory();
|
||||
const usage = process.memoryUsage.rss() / 1000000;
|
||||
|
||||
logger.info(`Start heap sampling, memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
|
||||
logger.info(`Start heap sampling, memory usage: ${usage} MB`);
|
||||
|
||||
setTimeout(async () => {
|
||||
await stopMemorySample();
|
||||
@@ -73,7 +80,7 @@ async function startMemorySample() {
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
if (argv.memory) {
|
||||
if (argv.sampleMemory) {
|
||||
await startMemorySample();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user