From e6ec891d9a8d31be2a05a8198fe96d4721c62edd Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 30 Mar 2020 18:26:04 -0400 Subject: [PATCH] improve admin rpc for diagnosing memory used by the cache --- lib/commands/admin-rpc.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 32e9b9947..ed1d5b8a4 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -20,22 +20,36 @@ var getFileDescriptorLimit = function (env, server, cb) { }; var getCacheStats = function (env, server, cb) { + var metaSize = 0; + var channelSize = 0; var metaCount = 0; var channelCount = 0; - var meta = env.metadata_cache; - for (var x in meta) { - if (meta.hasOwnProperty(x)) { metaCount++; } - } - - var channels = env.channel_cache; - for (var y in channels) { - if (channels.hasOwnProperty(y)) { channelCount++; } + try { + var meta = env.metadata_cache; + for (var x in meta) { + if (meta.hasOwnProperty(x)) { + metaCount++; + metaSize += JSON.stringify(meta[x]).length; + } + } + + var channels = env.channel_cache; + for (var y in channels) { + if (channels.hasOwnProperty(y)) { + channelCount++; + channelSize += JSON.stringify(channels[y]).length; + } + } + } catch (err) { + return void cb(err && err.message); } cb(void 0, { metadata: metaCount, + metaSize: metaSize, channel: channelCount, + channelSize: channelSize, }); };