Skip to content

Instantly share code, notes, and snippets.

@OzieWest
Created November 24, 2016 20:10
Show Gist options
  • Select an option

  • Save OzieWest/8941353e4a11b6f756e9d6a07c4f0c1e to your computer and use it in GitHub Desktop.

Select an option

Save OzieWest/8941353e4a11b6f756e9d6a07c4f0c1e to your computer and use it in GitHub Desktop.
Node.js - Monitoring the event loop
import Heavy from 'heavy';
const heavy_instance = new Heavy({
sampleInterval: 1000,
});
const min_time_between_log_messages = 1000;
const event_loop_logging_threshold = 5;
let logging_interval;
function logIfAboveThreshold({ heavy, logger }) {
if (!heavy || !heavy.load || !logger) {
return;
}
if (heavy.load.eventLoopDelay > event_loop_logging_threshold) {
logger.info({
threshold: event_loop_logging_threshold,
event_loop_delay: heavy.load.eventLoopDelay,
heap_used: heavy.load.heapUsed,
rss: heavy.load.rss,
}, 'Event loop delay above threshold');
}
}
export default {
startLoggingPerformance({ logger }) {
heavy_instance.start();
if (logging_interval) {
clearInterval(logging_interval);
}
logging_interval = setInterval(() => {
logIfAboveThreshold({ heavy: heavy_instance, logger: logger });
}, min_time_between_log_messages);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment