Number of max_workers when using ThreadPoolExecutor from concurrent.futures?

做~自己de王妃 提交于 2019-12-08 15:02:35

问题


What are the factors to consider when deciding what to set max_workers to in ThreadPoolExecutor from concurrent.futures?

As long as you can expect Python 3.5+ to be available, is there any reason not to set max_workers to None which will then "default to the number of processors on the machine, multiplied by 5" as described in the docs here? https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor


回答1:


I don't think this question can be so generically solved; it will depend on each case.

From this answer:

The more threads you use, the higher concurrency you'll achieve (up to a point), but the less CPU cycles you'll get (as there will be context switches). You have to instrument your application under typical workloads to see what works best for you. There is no universally optimal solution for this.



来源:https://stackoverflow.com/questions/47498288/number-of-max-workers-when-using-threadpoolexecutor-from-concurrent-futures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!