Reputation: 136141
I'm building a gRPC service in Python, and trying to improve the latency metrics. I went through the Python gRPC Performance Best Practices and found the following:
(Experimental) An experimental single-threaded unary-stream implementation is available via the SingleThreadedUnaryStream channel option, which can save up to 7% latency per message.
The problem is that the link points to a class located in an experimental
folder, without any usage instructions. I searched the manual (and Github repos in general), but found no reference as to how to enable this feature
How can I use or call the SingleThreadedUnaryStream
channel option feature in my code?
Upvotes: 4
Views: 1751
Reputation: 136141
After a deep dive in the gRPC source code, the following seems to work:
from grpc import experimental
channel_options = [(experimental.ChannelOptions.SingleThreadedUnaryStream, 1)]
with grpc.insecure_channel(f"{HOST}:{PORT}", options=channel_options) as channel:
stub = xxx_pb2_grpc.XxxStub(channel)
However, there was no impact on the latency or thoroughput.
Upvotes: 2