Skip to content

Commit

Permalink
Add memory usage logging to apiHubLauncher
Browse files Browse the repository at this point in the history
This update integrates a memory usage logger that records detailed memory stats at one-minute intervals. This will help in monitoring and diagnosing memory-related issues in primary cluster processes.
  • Loading branch information
skutner committed Nov 1, 2024
1 parent 66468eb commit bdc1c03
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion psknode/bin/scripts/apiHubLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ require(path.join(__dirname, '../../../builds/output/pskWebServer.js'));
const logger = $$.getLogger("Launcher", "logger");

const fs = require('fs');

const cluster = require("cluster");

if (cluster.isPrimary) {
function logMemoryUsage() {
setInterval(() => {
const memoryUsage = process.memoryUsage();
const formattedMemoryUsage = {
timestamp: new Date().toISOString(),
rss: (memoryUsage.rss / (1024 * 1024)).toFixed(2) + ' MB',
heapTotal: (memoryUsage.heapTotal / (1024 * 1024)).toFixed(2) + ' MB',
heapUsed: (memoryUsage.heapUsed / (1024 * 1024)).toFixed(2) + ' MB',
external: (memoryUsage.external / (1024 * 1024)).toFixed(2) + ' MB',
arrayBuffers: (memoryUsage.arrayBuffers / (1024 * 1024)).toFixed(2) + ' MB'
};

console.info(0x666, formattedMemoryUsage);
}, 60000);
}

logMemoryUsage();
}

path = require("swarmutils").path;
const API_HUB = require('apihub');

Expand All @@ -20,7 +43,6 @@ if (!process.env.PSK_CONFIG_LOCATION) {

let config = API_HUB.getServerConfig();

const cluster = require("cluster");
const {cpus} = require("os");
const numCPUs = config.workers || 1 || cpus().length;

Expand Down

0 comments on commit bdc1c03

Please sign in to comment.