Skip to content

Commit a0abdba

Browse files
author
maladetska
committed
.
1 parent 550844a commit a0abdba

File tree

7 files changed

+38
-16
lines changed

7 files changed

+38
-16
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ class TDriverConfig {
105105
//! default: true, 30, 5, 10 for linux, and true and OS default for others POSIX
106106
TDriverConfig& SetTcpKeepAliveSettings(bool enable, size_t idle, size_t count, size_t interval);
107107

108+
//! Set TCP_NODELAY socket option
109+
//! enable - if true TCP_NODELAY is enabled (default, no Nagle algorithm, low latency, packet fragmentation)
110+
//! - if false TCP_NODELAY is disabled (Nagle algorithm enabled, reduced packet fragmentation)
111+
//! NOTE: This affects network performance. Disable only if you want to reduce packet fragmentation.
112+
//! default: true
113+
TDriverConfig& SetTcpNoDelay(bool enable);
114+
108115
//! Enable or disable drain of client logic (e.g. session pool drain) during dtor call
109116
TDriverConfig& SetDrainOnDtors(bool allowed);
110117

@@ -117,6 +124,7 @@ class TDriverConfig {
117124
//! Params is a optionally field to set policy settings
118125
//! default: EBalancingPolicy::UsePreferableLocation
119126
TDriverConfig& SetBalancingPolicy(EBalancingPolicy policy, const std::string& params = "");
127+
120128
//! Set grpc level keep alive. If keepalive ping was delayed more than given timeout
121129
//! internal grpc routine fails request with TRANSIENT_FAILURE or TRANSPORT_UNAVAILABLE error
122130
//! Note: this timeout should not be too small to prevent fail due to
@@ -126,6 +134,11 @@ class TDriverConfig {
126134
TDriverConfig& SetGRpcKeepAliveTimeout(TDuration timeout);
127135
TDriverConfig& SetGRpcKeepAlivePermitWithoutCalls(bool permitWithoutCalls);
128136

137+
//! Set grpc load balancing policy
138+
//! policy - name of the load balancing policy, see grpc documentation for available policies
139+
//! default: "round_robin"
140+
TDriverConfig& SetGRpcLoadBalancingPolicy(const std::string& policy);
141+
129142
//! Set inactive socket timeout.
130143
//! Used to close connections, that were inactive for given time.
131144
//! Closes unused connections every 1/10 of timeout, so deletion time is approximate.

src/client/driver/driver.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ class TDriverConfig::TImpl : public IConnectionsParams {
4040
EDiscoveryMode GetDiscoveryMode() const override { return DiscoveryMode; }
4141
size_t GetMaxQueuedRequests() const override { return MaxQueuedRequests; }
4242
TTcpKeepAliveSettings GetTcpKeepAliveSettings() const override { return TcpKeepAliveSettings; }
43+
bool GetTcpNoDelay() const override { return TcpNoDelay; }
4344
bool GetDrinOnDtors() const override { return DrainOnDtors; }
4445
TBalancingPolicy::TImpl GetBalancingSettings() const override { return BalancingSettings; }
4546
TDuration GetGRpcKeepAliveTimeout() const override { return GRpcKeepAliveTimeout; }
4647
bool GetGRpcKeepAlivePermitWithoutCalls() const override { return GRpcKeepAlivePermitWithoutCalls; }
48+
std::string GetGRpcLoadBalancingPolicy() const override { return GRpcLoadBalancingPolicy; }
4749
TDuration GetSocketIdleTimeout() const override { return SocketIdleTimeout; }
4850
uint64_t GetMemoryQuota() const override { return MemoryQuota; }
4951
uint64_t GetMaxInboundMessageSize() const override { return MaxInboundMessageSize; }
@@ -71,10 +73,12 @@ class TDriverConfig::TImpl : public IConnectionsParams {
7173
TCP_KEEPALIVE_COUNT,
7274
TCP_KEEPALIVE_INTERVAL
7375
};
76+
bool TcpNoDelay = true;
7477
bool DrainOnDtors = true;
7578
TBalancingPolicy::TImpl BalancingSettings = TBalancingPolicy::TImpl::UsePreferableLocation(std::nullopt);
7679
TDuration GRpcKeepAliveTimeout = TDuration::Seconds(10);
7780
bool GRpcKeepAlivePermitWithoutCalls = true;
81+
std::string GRpcLoadBalancingPolicy = "round_robin";
7882
TDuration SocketIdleTimeout = TDuration::Minutes(6);
7983
uint64_t MemoryQuota = 0;
8084
uint64_t MaxInboundMessageSize = 0;
@@ -174,6 +178,11 @@ TDriverConfig& TDriverConfig::SetTcpKeepAliveSettings(bool enable, size_t idle,
174178
return *this;
175179
}
176180

181+
TDriverConfig& TDriverConfig::SetTcpNoDelay(bool enable) {
182+
Impl_->TcpNoDelay = enable;
183+
return *this;
184+
}
185+
177186
TDriverConfig& TDriverConfig::SetGrpcMemoryQuota(uint64_t bytes) {
178187
Impl_->MemoryQuota = bytes;
179188
return *this;
@@ -203,6 +212,11 @@ TDriverConfig& TDriverConfig::SetGRpcKeepAlivePermitWithoutCalls(bool permitWith
203212
return *this;
204213
}
205214

215+
TDriverConfig& TDriverConfig::SetGRpcLoadBalancingPolicy(const std::string& policy) {
216+
Impl_->GRpcLoadBalancingPolicy = policy;
217+
return *this;
218+
}
219+
206220
TDriverConfig& TDriverConfig::SetSocketIdleTimeout(TDuration timeout) {
207221
Impl_->SocketIdleTimeout = timeout;
208222
return *this;
@@ -285,10 +299,12 @@ TDriverConfig TDriver::GetConfig() const {
285299
Impl_->TcpKeepAliveSettings_.Count,
286300
Impl_->TcpKeepAliveSettings_.Interval
287301
);
302+
config.SetTcpNoDelay(Impl_->TcpNoDelay_);
288303
config.SetDrainOnDtors(Impl_->DrainOnDtors_);
289304
config.SetBalancingPolicy(std::make_unique<TBalancingPolicy::TImpl>(Impl_->BalancingSettings_));
290305
config.SetGRpcKeepAliveTimeout(std::chrono::duration_cast<std::chrono::microseconds>(Impl_->GRpcKeepAliveTimeout_));
291306
config.SetGRpcKeepAlivePermitWithoutCalls(Impl_->GRpcKeepAlivePermitWithoutCalls_);
307+
config.SetGRpcLoadBalancingPolicy(Impl_->GRpcLoadBalancingPolicy_);
292308
config.SetSocketIdleTimeout(std::chrono::duration_cast<std::chrono::microseconds>(Impl_->SocketIdleTimeout_));
293309
config.SetMaxInboundMessageSize(Impl_->MaxInboundMessageSize_);
294310
config.SetMaxOutboundMessageSize(Impl_->MaxOutboundMessageSize_);

src/client/impl/internal/grpc_connections/grpc_connections.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class TGRpcConnectionsImpl
108108
clientConfig.MaxOutboundMessageSize = MaxOutboundMessageSize_;
109109
}
110110

111-
clientConfig.LoadBalancingPolicy = "round_robin";
111+
clientConfig.LoadBalancingPolicy = GRpcLoadBalancingPolicy;
112112

113113
if (dbState->DiscoveryMode != EDiscoveryMode::Off) {
114114
if (std::is_same<TService,Ydb::Discovery::V1::DiscoveryService>()
@@ -709,13 +709,15 @@ class TGRpcConnectionsImpl
709709
const TBalancingPolicy::TImpl BalancingSettings_;
710710
const TDeadline::Duration GRpcKeepAliveTimeout_;
711711
const bool GRpcKeepAlivePermitWithoutCalls_;
712+
const std::string GRpcLoadBalancingPolicy_;
712713
const std::uint64_t MemoryQuota_;
713714
const std::uint64_t MaxInboundMessageSize_;
714715
const std::uint64_t MaxOutboundMessageSize_;
715716
const std::uint64_t MaxMessageSize_;
716717

717718
std::atomic_int64_t QueuedRequests_;
718719
const NYdbGrpc::TTcpKeepAliveSettings TcpKeepAliveSettings_;
720+
const bool TcpNoDelay_;
719721
const TDeadline::Duration SocketIdleTimeout_;
720722
#ifndef YDB_GRPC_BYPASS_CHANNEL_POOL
721723
NYdbGrpc::TChannelPool ChannelPool_;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ class IConnectionsParams {
3333
virtual EDiscoveryMode GetDiscoveryMode() const = 0;
3434
virtual size_t GetMaxQueuedRequests() const = 0;
3535
virtual NYdbGrpc::TTcpKeepAliveSettings GetTcpKeepAliveSettings() const = 0;
36+
virtual bool GetTcpNoDelay() const = 0;
3637
virtual bool GetDrinOnDtors() const = 0;
3738
virtual TBalancingPolicy::TImpl GetBalancingSettings() const = 0;
3839
virtual TDuration GetGRpcKeepAliveTimeout() const = 0;
3940
virtual bool GetGRpcKeepAlivePermitWithoutCalls() const = 0;
41+
virtual std::string GetGRpcLoadBalancingPolicy() const = 0;
4042
virtual TDuration GetSocketIdleTimeout() const = 0;
4143
virtual const TLog& GetLog() const = 0;
4244
virtual uint64_t GetMemoryQuota() const = 0;

src/client/table/impl/table_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TTableClient::TImpl::TImpl(std::shared_ptr<TGRpcConnectionsImpl>&& connections,
4242

4343
TTableClient::TImpl::~TImpl() {
4444
if (Connections_->GetDrainOnDtors()) {
45-
Drain().Wait();
45+
Drain().Wait(DRAIN_TIMEOUT);
4646
}
4747
}
4848

src/client/table/impl/table_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ namespace NTable {
3030
//How ofter run host scan to perform session balancing
3131
constexpr TDeadline::Duration HOSTSCAN_PERIODIC_ACTION_INTERVAL = std::chrono::seconds(2);
3232
constexpr TDuration KEEP_ALIVE_CLIENT_TIMEOUT = TDuration::Seconds(5);
33+
// Max wait time for Drain() to complete. Sessions are being closed with 2 seconds
34+
// timeout each (in parallel), plus up to 10 seconds for discovery if needed.
35+
constexpr TDuration DRAIN_TIMEOUT = TDuration::Seconds(30);
3336

3437
TDuration GetMinTimeToTouch(const TSessionPoolSettings& settings);
3538
TDuration GetMaxTimeToTouch(const TSessionPoolSettings& settings);

tests/unit/client/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,3 @@ add_ydb_test(NAME client-ydb_query_metrics_ut GTEST
115115
LABELS
116116
unit
117117
)
118-
119-
add_ydb_test(NAME client-ydb_query_spans_ut GTEST
120-
INCLUDE_DIRS
121-
${YDB_SDK_SOURCE_DIR}
122-
SOURCES
123-
query/query_spans_ut.cpp
124-
LINK_LIBRARIES
125-
yutil
126-
impl-observability
127-
client-types
128-
client-trace
129-
LABELS
130-
unit
131-
)

0 commit comments

Comments
 (0)