Skip to content

Instantly share code, notes, and snippets.

@hlolli
Created August 31, 2018 19:21
Show Gist options
  • Save hlolli/d6be198862f828d41ce5664b8e24d4ee to your computer and use it in GitHub Desktop.
Save hlolli/d6be198862f828d41ce5664b8e24d4ee to your computer and use it in GitHub Desktop.
detect thread block in nodejs
(defn detectBlock []
(let [interval 500
blockDelta 5]
(js/setInterval
(fn []
(let [last (.hrtime js/process)]
(js/setImmediate
(fn []
(let [delta (* 1e-6 (aget (.hrtime js/process last) 1))]
(when (< blockDelta delta)
(js/console.log "node.eventloop_blocked" delta)))))))
interval)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment