If this is for nodejs, will there be a simple monitor stream? I donβt know how to get information about the internals of the event queue, but you can put the tracer in the event queue to control that threads are running in a timely manner. (This does not measure the load on the number of threads that are not already running, but on the fact that the threads start on time. The same thing, sort of.)
The monitoring thread can reorder itself and verify that it is called at least every 10 milliseconds (or any possible cumulative blocking ms is allowed). Since nodej starts round-robin threads, if the monitor thread was started on time, it tells us that all the other threads got the opportunity to start in 10 ms in the same window. Something like (in node):
// like Date.now(), but with higher precision // the extra precision is needed to be able to track small delays function dateNow() { var t = process.hrtime(); return (t[0] + t[1] * 1e-9) * 1000; } var _lastTimestamp = dateNow(); // when healthMonitor ran last, in ms var _maxAllowedDelay = 10.0; // max ms delay we allow for our task to run function healthMonitor() { var now = dateNow(); var delay = now - _lastTimestamp; if (delaly > _maxAllowedDelay) { console.log("healthMonitor was late:", delay, " > ", _maxAllowedDelay); } _lastTimestamp = now; setTimeout(healthMonitor, 1); } // launch the health monitor and run it forever // note: the node process will never exit, it will have to be killed healthMonitor();
Throttling warning messages and supporting clean shutdown is an exercise left to the reader.
Andras
source share