Reputation: 21855
We have an application with some time constrains, say that we need to execute an action every 500 ms, it is a kind of watchdog so if we don't send a message before 500 ms bad things happen.
The application uses quite heavily the ThreadPool and this watchdog thing interacts with the ThreadPool.
We have found that on some low end machines and sometimes when we queue a new workitem it takes about 800ms to execute it so the watchdog fires. We guess it is related with the ThreadPool running out of threads / creating new ones.
Is there a way to avoid this like forcing the ThreadPool to create the threads in advance or in a different thread so the watchdog never has to wait until the ThreadPool can execute the request?
Upvotes: 0
Views: 1760
Reputation: 23214
The reply from lawliet29 can help to some extent. But even with many threads, the thread pool can become saturated and some tasks might be queued up at the end of the global task queue.
We have the same issue inside Akka.NET where we have system actors that must execute even under heavy load.
We are now moving those sensitive tasks into it's own dedicated threadpool, so that those tasks will not end up on the end of the global pool queue.
https://github.com/helios-io/DedicatedThreadPool
We can schedule tasks onto this queue using a special task scheduler.
Upvotes: 3