Skip to content

Commit f0a7362

Browse files
yhmohaorenfsaclaude
authored
feat: set grpc keepalive interval to 10s with 5s timeout (#444) (#446)
- Reduce keepalive_time_ms default from 55s to 10s for faster dead connection detection - Reduce keepalive_timeout_ms default from 20s to 5s - Enable keepalive_without_calls by default - Add unit tests for keepalive defaults and setters/builders Signed-off-by: Ren Haofeng <haofeng.ren@zilliz.com> Signed-off-by: haorenfsa <haorenfsa@gmail.com> Co-authored-by: shaoyue <haorenfsa@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8628150 commit f0a7362

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/include/milvus/types/ConnectParam.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ class ConnectParam {
340340
std::string uri_ = "http://localhost:19530";
341341

342342
uint64_t connect_timeout_ms_ = 10000; // the same with pymilvus
343-
uint64_t keepalive_time_ms_ = 55000; // the same with pymilvus
344-
uint64_t keepalive_timeout_ms_ = 20000; // the same with java sdk
345-
bool keepalive_without_calls_ = false; // the same with java sdk
343+
uint64_t keepalive_time_ms_ = 10000; // Send keepalive pings every 10 seconds
344+
uint64_t keepalive_timeout_ms_ = 5000; // Keepalive ping timeout after 5 seconds
345+
bool keepalive_without_calls_ = true; // Allow keepalive pings when there are no gRPC calls
346346
uint64_t rpc_deadline_ms_ = 0; // the same with java sdk
347347

348348
bool tls_{false};

test/ut/v1/TestConnectParam.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,30 @@ TEST_F(ConnectParamTest, GeneralTesting) {
4747
param.DisableTls();
4848
EXPECT_FALSE(param.TlsEnabled());
4949
}
50+
51+
TEST_F(ConnectParamTest, KeepaliveDefaults) {
52+
milvus::ConnectParam param{"localhost", 19530};
53+
54+
EXPECT_EQ(param.KeepaliveTimeMs(), 10000);
55+
EXPECT_EQ(param.KeepaliveTimeoutMs(), 5000);
56+
EXPECT_TRUE(param.KeepaliveWithoutCalls());
57+
}
58+
59+
TEST_F(ConnectParamTest, KeepaliveSettersAndBuilders) {
60+
milvus::ConnectParam param{"localhost", 19530};
61+
62+
param.SetKeepaliveTimeMs(20000);
63+
EXPECT_EQ(param.KeepaliveTimeMs(), 20000);
64+
65+
param.SetKeepaliveTimeoutMs(8000);
66+
EXPECT_EQ(param.KeepaliveTimeoutMs(), 8000);
67+
68+
param.SetKeepaliveWithoutCalls(false);
69+
EXPECT_FALSE(param.KeepaliveWithoutCalls());
70+
71+
// Test builder pattern
72+
auto& ref = param.WithKeepaliveTimeMs(30000).WithKeepaliveTimeoutMs(10000).WithKeepaliveWithoutCalls(true);
73+
EXPECT_EQ(ref.KeepaliveTimeMs(), 30000);
74+
EXPECT_EQ(ref.KeepaliveTimeoutMs(), 10000);
75+
EXPECT_TRUE(ref.KeepaliveWithoutCalls());
76+
}

0 commit comments

Comments
 (0)