threads.js icon indicating copy to clipboard operation
threads.js copied to clipboard

[QUESTION] Task execution timeout

Open Deadly0 opened this issue 4 years ago • 2 comments

Hi, is it possible to set timeout for task execution by which the task will be forcibly terminated?

Deadly0 avatar May 07 '21 15:05 Deadly0

Hi! I suppose you're talking about thread pools. No, there is currently no out-of-the-box solution to this.

Do you mean killing the whole worker and spawning a new one if some task runs longer than the timeout? That feels a bit radical… 😅

I wonder if it's not usually a better idea to let the worker make sure to not spend an infinite amount of time on anything it does.

andywer avatar May 08 '21 18:05 andywer

I have the following use case: I use threads.js inside a Node.js server (based on Express.js) to execute several client requests in parallel. Unfortunately, the complexity of the request is defined by request parameters in a pretty complex way, which doesn't allow me to predict processing time in advance. Moreover, most time the processing in threads happens inside third-party JS libraries, which prevents stopping processing from inside the thread...

So, the only solution for my use case I see is to kill a thread with too long request and spawn a new one. I agree that it's pretty radical behaviour. Also, it leads to some overall performance degradation because of thread spawning overhead.

aparshin avatar Sep 01 '21 12:09 aparshin