python - 从 concurrent.futures 使用 ThreadPoolExecutor 时的 max_workers 数量?

标签 python python-3.x concurrent.futures

在从 concurrent.futures 中决定将 max_workers 设置为什么时,需要考虑哪些因素?

只要您期望 Python 3.5+ 可用,是否有任何理由不将 max_workers 设置为 None ,这将“默认为机器上的处理器数量,乘以 5”,如此处文档中所述? https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor

最佳答案

我不认为这个问题可以如此普遍地解决;这将取决于每个案例。

来自 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.

关于python - 从 concurrent.futures 使用 ThreadPoolExecutor 时的 max_workers 数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47498288/

相关文章:

python - 是否可以使用 webbrowser 或 Selenium 来获取浏览器中的当前 URL

python-3.x - 从 pandas 数据框到元组(对于半正矢模块)

DJANGO > 2.2 - 在外键 A、B 或外键 A、B、C 上唯一

python - 将 .lower() 函数应用于列表中所有单词大小写的字符串

python future 和元组解包

python - 在 Pandas 中以矢量化方式计算特定连续相等值的数量

python - 如何使用 Python 将目录更改回原来的工作目录?

python - 有没有更快的方法使用 pyglet 和线程在屏幕上绘图?

python - Pyhook 在按 6 次后停止捕获按键事件

python - ThreadPoolExecutor能否帮助单线程应用效率提升?