限制数量的任务同时运行数量、任务

2023-09-06 21:55:49 作者:烈酒撩人

我要运行约150任务。现在的应用程序使用每个核心只有25个线程,我需要的是一个较大的数字。是否有可能增加该限制?

I have to run about 150 tasks. Right now the app is using only 25 threads per core and I need that to be a higher number. Is it possible to increase that limit ?

推荐答案

要控制将实际创建的线程的实际数量的唯一途径是实现自己的 的TaskScheduler 子类,你可以控制的建立和计划在其上执行任务的线程。默认实现使用线程池中的线程以及若干启发确定的最大线程数每个核心调度。

The only way to control the actual number of threads that will actually be created is to implement your own TaskScheduler subclass where you can control the creation and scheduling of the threads on which to execute tasks. The default implementation uses thread pool threads along with several heuristics to determine the maximum number of threads to schedule per core.

说实话,我很惊讶,如果你能击败默认的实现。你在做任何I / O完成这些任务?您是否使用异步I / O?

Honestly, I'd be amazed if you can beat the default implementation. Are you doing any I/O in these tasks? Are you using async I/O?