Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libuv worker threads or work queue health check?

In libuv, you can end up tying up the worker threads with too much work or buggy code. Is there a simple function that can check the health of the worker threads or thread queue? It doesn't have to be 100% deterministic, after all it would be impossible to determine whether the worker thread is hanging on slow code or an infinite loop.

So any of the following heuristics would be good:

  • Number of queued items not yet worked on. If this is too large, it could mean the worker threads are busy or hung.

  • Does libuv have any thread killing mechanism where if the worker thread doesn't check back in n seconds, it gets terminated?

like image 294
Glen Low Avatar asked Dec 12 '13 23:12

Glen Low


1 Answers

That function does not exist in libuv itself, and I am not aware of any OSS that provides something like that.

In terms of a killing mechanism, there is none baked into libuv, but http://nikhilm.github.io/uvbook/threads.html#core-thread-operations suggests:

A well designed program would have a way to terminate long running workers that have already started executing. Such a worker could periodically check for a variable that only the main process sets to signal termination.

like image 51
Jonathan Wiepert Avatar answered Oct 04 '22 01:10

Jonathan Wiepert