我正在编写一个简单的脚本,在每次运行中用pyspark python处理一些订单(从1000-2000不等(,每个订单大约需要3 seconds
(它包括API调用、D/B读取、D/B更新和其他处理(
为了减少整个脚本时间,我用Future
和ThreadPoolExecutor
更新了脚本,因为要处理的订单之间没有依赖关系
目前,我已经创建了一个由20个线程组成的ThreadPool,并提交了我的所有任务(1000个订单(,并且运行良好
我想知道我可以安全地向ThreadPoolExecution提交多少任务?是否有一个点数/数字,在该点数/数字之后,任务将被拒绝
from concurrent.futures import ThreadPoolExecutor
import time
futuresList = []
executor = ThreadPoolExecutor(20)
start_seconds = time.time()
for tempOrder in membership_orders_to_processList:
future = executor.submit(processOrder, (tempOrder))
futuresList.append(future)
for tempFuture in futuresList:
try:
print("result",tempFuture.result())
except Exception as inst:
print("Exception occurred in future result",inst)
executor.shutdown(wait=True)
好问题,每台计算机(处理器、操作系统(都不一样。根据我的经验,没有限制,因为限制是,有多少人可以处理操作系统。