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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With