Как синхронизировать потоковые сообщения с Python gRPC
В качестве ответа на вопрос: how-do-i-handle-streaming-messages-with-python-grpc, @Nathaniel предоставляет решение для обработки запросов и ответов.
Но когда я хочу получить статистику времени обработки каждого ответа, это выглядит неправильно. Например, я сплю 200 мс в своем
stream_iter
, но
tr
даже меньше 200. Мой код:
t0 = time.time()
for rsp in stub.Process(stream_iter()):
tr = (time.time() - t0) * 1000
print(tr)
t0 = time.time()
...
Итак, я хочу знать, как рассчитать время?
1 ответ
It's hard to tell what is wrong with the given snippet. I would recommend to create a complete reproduction case as an issue to https://github.com/grpc/grpc/issues.
Here are some possibilities:
- Flow control, the client/server might buffer messages it received, hence you might see small burst in certain scenarios.
- Bug in iterator, e.g., we want to sleep in
__next__
, but might accidentally injected sleep in__iter__
.
Generally, if you tune up the scale and throughput, the noise should go away. What you have for measuring the latency of each response is good.