tikv/grpc-rs

Question: The same target want to build multi channel, independent link, not reused.

Closed this issue · 3 comments

Question: Can I build multi channel with the same target? The same target-server with two clients with different responsibilities.
有两个不同职责的客户端而对应的相同的服务端,可以同一个目标地址,而产生两个不同链接的 Channel 吗?

let env = Arc::new(grpcio::Environment::new(2));
let channel = grpcio::ChannelBuilder::new(env)
    .reuse_port(false) // same target build multi channel, independent link, not reused.
    .connect(target.as_str());

grpcio = 0.11

目前效果如下:

  1. target 一样,虽然使用 ChannelBuilder 构建了两次,而得到的链接是同一个。

image

  1. target 不一样,使用 ChannelBuilder 构建了两次,得到的链接是不同。

image

期望效果

无论 target 是否一样,使用 ChannelBuilder 构建了两次,得到两个不同的链接。

Channel is different from connection. By default, gRPC c core tends to reuse connections, connection pool more specifically, instead of one connection per channel. If you really want to use different connections for different channels object, you can set GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL to 1 by builder = builder.raw_cfg_int(grpcio_sys::GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL.into(), 1).

Channel is different from connection. By default, gRPC c core tends to reuse connections, connection pool more specifically, instead of one connection per channel. If you really want to use different connections for different channels object, you can set GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL to 1 by builder = builder.raw_cfg_int(grpcio_sys::GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL.into(), 1).

Thanks, I will try later.

.use_local_subchannel_pool(true) is useful, thanks.

let channel = grpcio::ChannelBuilder::new(env)
    .use_local_subchannel_pool(true) // same target-addr build multi sub-channel, independent link, not reused.
    .connect(target.as_str());