From 93c807524f6de924d31bff1fafb9599ff2591448 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 8 Dec 2020 10:24:09 +0530 Subject: [PATCH 1/2] update offset debugging info --- lib/workers/db-worker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/workers/db-worker.js b/lib/workers/db-worker.js index d871bcb97..7f45dfaa2 100644 --- a/lib/workers/db-worker.js +++ b/lib/workers/db-worker.js @@ -230,8 +230,10 @@ const computeIndexFromOffset = function (channelName, offset, cb) { var diff = new_start - start; Env.Log.info('WORKER_OFFSET_UPDATE', { channel: channelName, - old_start: start, - new_start: new_start, + start: start, + startMB: start / 1024 / 1024, + update: new_start, + updateMB: new_start / 1024 / 1024, diff: diff, diffMB: diff / 1024 / 1024, }); From 93d56e5e3d71f05471a6cfb9f8688900a417365e Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 8 Dec 2020 10:44:46 +0530 Subject: [PATCH 2/2] profile worker commands by total running time in seconds --- lib/commands/admin-rpc.js | 6 ++++++ lib/env.js | 1 + lib/workers/index.js | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index d7f22825d..826c73491 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -56,6 +56,11 @@ var getCacheStats = function (env, server, cb) { }); }; +// CryptPad_AsyncStore.rpc.send('ADMIN', ['GET_WORKER_PROFILES'], console.log) +var getWorkerProfiles = function (Env, Server, cb) { + cb(void 0, Env.commandTimers); +}; + var getActiveSessions = function (Env, Server, cb) { var stats = Server.getSessionStats(); cb(void 0, [ @@ -315,6 +320,7 @@ var commands = { INSTANCE_STATUS: instanceStatus, GET_LIMITS: getLimits, SET_LAST_EVICTION: setLastEviction, + GET_WORKER_PROFILES: getWorkerProfiles, }; Admin.command = function (Env, safeKey, data, _cb, Server) { diff --git a/lib/env.js b/lib/env.js index b1fc6680b..3a876f1f7 100644 --- a/lib/env.js +++ b/lib/env.js @@ -94,6 +94,7 @@ module.exports.create = function (config) { disableIntegratedEviction: config.disableIntegratedEviction || false, lastEviction: +new Date(), evictionReport: {}, + commandTimers: {}, }; (function () { diff --git a/lib/workers/index.js b/lib/workers/index.js index fe868e250..c422a9f54 100644 --- a/lib/workers/index.js +++ b/lib/workers/index.js @@ -14,6 +14,14 @@ const DEFAULT_QUERY_TIMEOUT = 60000 * 15; // increased from three to fifteen min Workers.initialize = function (Env, config, _cb) { var cb = Util.once(Util.mkAsync(_cb)); + var incrementTime = function (command, start) { + if (!command) { return; } + var end = +new Date(); + var T = Env.commandTimers; + var diff = (end - start); + T[command] = (T[command] || 0) + (diff / 1000); + }; + const workers = []; const response = Util.response(function (errLabel, info) { @@ -112,7 +120,9 @@ Workers.initialize = function (Env, config, _cb) { } const txid = guid(); + var start = +new Date(); var cb = Util.once(Util.mkAsync(Util.both(_cb, function (err /*, value */) { + incrementTime(msg && msg.command, start); if (err !== 'TIMEOUT') { return; } Log.debug("WORKER_TIMEOUT_CAUSE", msg); // in the event of a timeout the user will receive an error