Created
November 24, 2016 20:10
-
-
Save OzieWest/8941353e4a11b6f756e9d6a07c4f0c1e to your computer and use it in GitHub Desktop.
Node.js - Monitoring the event loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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