From ffa523bced432ddbd92f29e6f3ed2871e09768ca Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Tue, 23 Jun 2015 10:51:48 +0100 Subject: [PATCH] added monitoring of event loop time should indicate if node is blocking on libuv threads as described in https://nodejs.org/api/dns.html#dns_dns_lookup --- libraries/metrics/event_loop.coffee | 18 ++++++++++++++++++ libraries/metrics/metrics.coffee | 1 + 2 files changed, 19 insertions(+) create mode 100644 libraries/metrics/event_loop.coffee diff --git a/libraries/metrics/event_loop.coffee b/libraries/metrics/event_loop.coffee new file mode 100644 index 0000000000..ab6955afc7 --- /dev/null +++ b/libraries/metrics/event_loop.coffee @@ -0,0 +1,18 @@ +seconds = 1000 + +module.exports = EventLoopMonitor = + monitor: (logger) -> + interval = setInterval () -> + EventLoopMonitor.Delay() + , 1 * seconds + Metrics = require "./metrics" + Metrics.registerDestructor () -> + clearInterval(interval) + + Delay: () -> + Metrics = require "./metrics" + t1 = process.hrtime() + setImmediate () -> + delta = process.hrtime(t1) + responseTime = delta[0]*1e6 + delta[1]*1e-3 + Metrics.timing("event-loop-microsec", responseTime) diff --git a/libraries/metrics/metrics.coffee b/libraries/metrics/metrics.coffee index 59e4ee9899..a0cd3070fb 100644 --- a/libraries/metrics/metrics.coffee +++ b/libraries/metrics/metrics.coffee @@ -39,6 +39,7 @@ module.exports = mongodb: require "./mongodb" http: require "./http" open_sockets: require "./open_sockets" + event_loop: require "./event_loop" close: () -> for func in destructors