简体   繁体   中英

What is the benefit of having multiple thread pools versus a single one?

Under what conditions is it considered best practice to have multiple thread pools versus a single one?

I'm developing on Windows using the Microsoft threadpool for processing work items where the documentation states:

Each process can create multiple isolated pools with different characteristics as necessary. 
There is also a default pool for each process.

At initial consideration it seems like having one thread pool for the process is the preferable option so that threads are not being spun up unnecessarily when there might be existing unused threads available in other thread pools.

Obviously one exception is that noted in the documentation - when different characteristics are needed for the thread pools. What other conditions should I be considering when determining whether or not I should be using multiple thread pools versus the single default pool?

All of this assumes that all threads need the same characteristics:

Normally, a single pool is best.

Sometimes, you architecturally want different components of the app to not know of each other. In that case they should not know of the thread pool of each other. So that would be an architectural decision.

In particular, if you load 3rd party components it will be hard to share pools.

One more reason would be to isolate some workload from another one if one of them is at risk of flooding the pool and interrupting the other workload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM