setInterval(() => { if (count > 0) { console.log(broker.nodeID, ":", padStart(Number(count.toFixed(0)).toLocaleString(), 8), "req/s"); count = 0; } }, 1000);
function color(text, pad, value, green, red) { let c; if (value <= green) c = kleur.green().bold; else if (value >= red) c = kleur.red().bold; else c = kleur.yellow().bold; return c(padStart(text, pad)); }
broker.start() .then(() => broker.waitForServices("perf")) .then(() => { setTimeout(() => { let startTime = Date.now(); work(); setInterval(() => { if (callCount > 0) { let rps = callCount / ((Date.now() - startTime) / 1000); let queueSize = broker.transit.pendingRequests.size; let latency = sumTime/callCount; console.log(broker.nodeID, ":", padStart(Number(rps.toFixed(0)).toLocaleString(), 8), "req/s", " Q:", color(Number(queueSize.toFixed(0)).toLocaleString(), 5, queueSize, 100, flood ? flood*.8 : 100), " E:", color(Number(errorCount.toFixed(0)).toLocaleString(), 5, errorCount, 0, 1), " L:", color(humanize(latency), 6, latency, 500, 5000), " ML:", color(humanize(maxTime), 6, maxTime, 1000, 5000) ); callCount = 0; sumTime = 0; maxTime = 0; startTime = Date.now(); } }, 1000); }, 1000); });
/** * Convert number to bit string with predefined length * * @param {string} decimal * @param {number} length * @returns String */ const toBits = (decimal, length) => padStart(toBN(decimal).toString(2), length, '0')
/** * Ensure the hex length is even number, 2, 4, 6, 8 * * @param {string} hex * @param {number} length * @returns {string} hex */ const toStrictHex = (hex, length) => { const str = hex.replace(/^0x/i, ''); if (typeof length === 'number' && length % 2 === 0) { return padStart(hex, length, '0'); } return str.length % 2 === 0 ? str : `0${str}`; }
/** * @private * When running in Kubernetes and attaching to logs, there is a five * minute timeout if there is no console output. This tick handler * ensures that output continues during that time. * * @param {number} milliseconds Milliseconds since the build wait started */ indexBuildTickHandler(milliseconds) { let secs = milliseconds / 1000; let secsPart = padStart(Math.floor(secs % 60).toString(10), 2, '0'); let minsPart = Math.floor(secs / 60); this.options.logger.log(chalk.greenBright( `Building ${minsPart}m${secsPart}s...` )); }