从ThreadPoolExecutor使用Python gRPC客户端
我希望通过从Python客户机发送多个gRPC请求并等待响应来加快处理速度。似乎从ThreadPoolExecutor使用Python gRPC客户端,python,python-multithreading,grpc,concurrent.futures,Python,Python Multithreading,Grpc,Concurrent.futures,我希望通过从Python客户机发送多个gRPC请求并等待响应来加快处理速度。似乎concurrent.futures.ThreadPoolExecutor非常适合,因为这主要是IO工作。但gRPC客户端似乎从未释放GIL,我无法实现任何加速 我的代码是这样的 def do_call(): return stub.Call(something) futures = [] thread_pool = concurrent.futures.ThreadPoolExecutor(workers
concurrent.futures.ThreadPoolExecutor
非常适合,因为这主要是IO工作。但gRPC客户端似乎从未释放GIL,我无法实现任何加速
我的代码是这样的
def do_call():
return stub.Call(something)
futures = []
thread_pool = concurrent.futures.ThreadPoolExecutor(workers=10)
for _ in range(100):
futures.append(thread_pool.submit(do_call))
for future in concurrent.futures.as_completed(futures):
print(future.result())
最后,这比同步调用该方法100次要慢。我可能做错了什么?我尝试使用一个通道,并为每个请求创建一个单独的存根,但这并没有改变任何事情
我知道存根有一个stub.Call.future()
方法,我可以使用它。我的问题是do_call()
函数实际上相当复杂,我希望避免在将来将所有处理重写为回调
有什么想法吗