Skip to content

Commit 34861e2

Browse files
committed
Allow to use per gRPC channel TCP connections (as an option) (#17857)
1 parent c715192 commit 34861e2

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

include/ydb-cpp-sdk/client/driver/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TDriverConfig {
5050
//! caCerts - The buffer containing the PEM encoded root certificates for SSL/TLS connections.
5151
//! If this parameter is empty, the default roots will be used.
5252
TDriverConfig& UseSecureConnection(const std::string& caCerts = std::string());
53+
TDriverConfig& SetUsePerChannelTcpConnection(bool usePerChannel);
5354
TDriverConfig& UseClientCertificate(const std::string& clientCert, const std::string& clientPrivateKey);
5455
//! Set token, this option can be overridden for client by ClientSettings
5556
TDriverConfig& SetAuthToken(const std::string& token);

src/client/driver/driver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TDriverConfig::TImpl : public IConnectionsParams {
3434
size_t GetClientThreadsNum() const override { return ClientThreadsNum; }
3535
size_t GetMaxQueuedResponses() const override { return MaxQueuedResponses; }
3636
TSslCredentials GetSslCredentials() const override { return SslCredentials; }
37+
bool GetUsePerChannelTcpConnection() const override { return UsePerChannelTcpConnection; }
3738
std::string GetDatabase() const override { return Database; }
3839
std::shared_ptr<ICredentialsProviderFactory> GetCredentialsProviderFactory() const override { return CredentialsProviderFactory; }
3940
EDiscoveryMode GetDiscoveryMode() const override { return DiscoveryMode; }
@@ -55,6 +56,7 @@ class TDriverConfig::TImpl : public IConnectionsParams {
5556
size_t ClientThreadsNum = 0;
5657
size_t MaxQueuedResponses = 0;
5758
TSslCredentials SslCredentials;
59+
bool UsePerChannelTcpConnection = false;
5860
std::string Database;
5961
std::shared_ptr<ICredentialsProviderFactory> CredentialsProviderFactory = CreateInsecureCredentialsProviderFactory();
6062
EDiscoveryMode DiscoveryMode = EDiscoveryMode::Sync;
@@ -114,6 +116,11 @@ TDriverConfig& TDriverConfig::UseSecureConnection(const std::string& cert) {
114116
return *this;
115117
}
116118

119+
TDriverConfig& TDriverConfig::SetUsePerChannelTcpConnection(bool usePerChannel) {
120+
Impl_->UsePerChannelTcpConnection = usePerChannel;
121+
return *this;
122+
}
123+
117124
TDriverConfig& TDriverConfig::UseClientCertificate(const std::string& clientCert, const std::string& clientPrivateKey) {
118125
Impl_->SslCredentials.Cert = clientCert;
119126
Impl_->SslCredentials.PrivateKey = clientPrivateKey;
@@ -254,7 +261,7 @@ TDriverConfig TDriver::GetConfig() const {
254261
config.SetMaxOutboundMessageSize(Impl_->MaxOutboundMessageSize_);
255262
config.SetMaxMessageSize(Impl_->MaxMessageSize_);
256263
config.Impl_->Log = Impl_->Log;
257-
264+
258265
return config;
259266
}
260267

src/client/impl/ydb_internal/grpc_connections/grpc_connections.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ TGRpcConnectionsImpl::TGRpcConnectionsImpl(std::shared_ptr<IConnectionsParams> p
161161
, ChannelPool_(TcpKeepAliveSettings_, SocketIdleTimeout_)
162162
#endif
163163
, NetworkThreadsNum_(params->GetNetworkThreadsNum())
164+
, UsePerChannelTcpConnection_(params->GetUsePerChannelTcpConnection())
164165
, GRpcClientLow_(NetworkThreadsNum_)
165166
, Log(params->GetLog())
166167
{

src/client/impl/ydb_internal/grpc_connections/grpc_connections.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class TGRpcConnectionsImpl
117117
}
118118
}
119119

120+
if (UsePerChannelTcpConnection_) {
121+
clientConfig.IntChannelParams[GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL] = 1;
122+
}
123+
120124
std::unique_ptr<TServiceConnection<TService>> conn;
121125
#ifndef YDB_GRPC_BYPASS_CHANNEL_POOL
122126
ChannelPool_.GetStubsHolderLocked(
@@ -733,6 +737,7 @@ class TGRpcConnectionsImpl
733737
IDiscoveryMutatorApi::TMutatorCb DiscoveryMutatorCb;
734738

735739
const size_t NetworkThreadsNum_;
740+
bool UsePerChannelTcpConnection_;
736741
// Must be the last member (first called destructor)
737742
NYdbGrpc::TGRpcClientLow GRpcClientLow_;
738743
TLog Log;

src/client/impl/ydb_internal/grpc_connections/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class IConnectionsParams {
1717
virtual size_t GetClientThreadsNum() const = 0;
1818
virtual size_t GetMaxQueuedResponses() const = 0;
1919
virtual TSslCredentials GetSslCredentials() const = 0;
20+
virtual bool GetUsePerChannelTcpConnection() const = 0;
2021
virtual std::string GetDatabase() const = 0;
2122
virtual std::shared_ptr<ICredentialsProviderFactory> GetCredentialsProviderFactory() const = 0;
2223
virtual EDiscoveryMode GetDiscoveryMode() const = 0;

0 commit comments

Comments
 (0)