Sharing Channels in gRPC Ruby Client

71 views
Skip to first unread message

Jason Liu

unread,
Sep 19, 2017, 2:10:46 PM9/19/17
to grpc.io
Hey everyone,

Looking through the gRPC ruby guide, I noticed that the channel isn't created separately from the Stub like in other examples (such as Java). After digging into gRPC, I found that the ClientStub takes a channel_override parameter, which may allow us to share channels across many stubs.

1. How do I properly instantiate a GRPC::Core::Channel object? The documentation for this pattern doesn't exist. I've currently got something like:

ssl_creds = GRPC::Core::ChannelCredentials.new("ca_file_path")
grpc_channel = GRPC::Core::Channel.new("url", {}, ssl_creds)
client = MyService::Stub.new("url", nil, :channel_override => grpc_channel)


Also, 
2. Is sharing channels in gRPC ruby recommended? An older discussion here recommends it, but I found a commit here on gitlab, which suggests that many stubs sharing a single channel may not be stable.


Thanks,
Jason

apo...@google.com

unread,
Sep 26, 2017, 7:25:40 PM9/26/17
to grpc.io
Hi,

There is an example of using the "channel_override" for stub creation in these tests: https://github.com/grpc/grpc/blob/master/src/ruby/spec/generic/rpc_server_spec.rb#L318.
And a brief example of creating a GRPC::Core::Channel with credentials is in https://github.com/grpc/grpc/blob/master/src/ruby/spec/channel_spec.rb#L86. What you have posted here looks like it should work.


I would indeed recommend sharing the same channel across multiple channels as a way to reduce resource usage and make fewer connections. If you are seeing problems when sharing the same channel across the same stub, I would recommend reporting the problem or filing an issue, as this kind of use of the "channel_override" parameter should work.

thanks
Reply all
Reply to author
Forward
0 new messages