【发布时间】:2018-06-24 04:29:46
【问题描述】:
由于 gevent/grpc 兼容性问题已经修复,我正在尝试使用它。
我用一个示例脚本对其进行了测试
from gevent import monkey
monkey.patch_all()
import grpc._cython.cygrpc
grpc._cython.cygrpc.init_grpc_gevent()
import grpc
import time
import sys
channel = grpc.insecure_channel('localhost:5000')
stub =hello_word_pb2_grpc.HelloWordStub(channel)
data = hellow_word_pb2.HelloWorld()
num_requests=3000
start=time.time()
futures = []
# Make async requests
for i in range (num_requests):
futures.append(stub.HelloWorld.future(req))
# Wait for the requests to complete
for i in range (num_requests):
try:
result = futures[i].result()
# Do something with the result
except Exception as e:
print(e)
end = time.time()
print(end - start)
现在没有这个补丁
import grpc._cython.cygrpc
grpc._cython.cygrpc.init_grpc_gevent()
完成 3000 个请求需要 0.456701040268 秒
现在有了补丁
import grpc._cython.cygrpc
grpc._cython.cygrpc.init_grpc_gevent()
需要 1.06 秒。
关于兼容性补丁可能出现什么问题的任何建议。
显然,如果我将请求数减少到 1000,并在每次调用中使用 1000 个异步请求进行 3 次调用,则总共 3000 个请求所需的时间小于 1.06。但我想知道是什么原因导致打补丁这么慢?
我在这里发现了类似的东西 - https://github.com/grpc/grpc/blob/master/src/python/grpcio_tests/commands.py#L115
有关系吗?
【问题讨论】: