From cf3d1b1ea2a63de69e7f19d29ffd225e66ec63fd Mon Sep 17 00:00:00 2001 From: Pxl Date: Thu, 11 Jul 2024 15:53:34 +0800 Subject: [PATCH] [Feature](rpc) support set brpc_idle_timeout_sec and enable thrift socket keep alive (#37333) ## Proposed changes In some special circumstances (such as network instability), the brpc server will always retain many tcp connections. --- be/src/common/config.cpp | 3 +++ be/src/common/config.h | 1 + be/src/service/brpc_service.cpp | 1 + be/src/util/thrift_server.cpp | 1 + 4 files changed, 6 insertions(+) diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp index 17bca94a459cef..eee9148e4951ec 100644 --- a/be/src/common/config.cpp +++ b/be/src/common/config.cpp @@ -67,6 +67,9 @@ DEFINE_mString(public_access_ip, ""); // the number of bthreads for brpc, the default value is set to -1, // which means the number of bthreads is #cpu-cores DEFINE_Int32(brpc_num_threads, "256"); +// the time of brpc server keep idle connection, setting this value too small may cause rpc between backends to fail, +// the default value is set to -1, which means never close idle connection. +DEFINE_Int32(brpc_idle_timeout_sec, "-1"); // Declare a selection strategy for those servers have many ips. // Note that there should at most one ip match this list. diff --git a/be/src/common/config.h b/be/src/common/config.h index 5fa5b23e977a8b..b0f369f4c817e1 100644 --- a/be/src/common/config.h +++ b/be/src/common/config.h @@ -108,6 +108,7 @@ DECLARE_mString(public_access_ip); // the number of bthreads for brpc, the default value is set to -1, // which means the number of bthreads is #cpu-cores DECLARE_Int32(brpc_num_threads); +DECLARE_Int32(brpc_idle_timeout_sec); // Declare a selection strategy for those servers have many ips. // Note that there should at most one ip match this list. diff --git a/be/src/service/brpc_service.cpp b/be/src/service/brpc_service.cpp index 57219f584ec753..6f2dc7aea38e50 100644 --- a/be/src/service/brpc_service.cpp +++ b/be/src/service/brpc_service.cpp @@ -63,6 +63,7 @@ Status BRpcService::start(int port, int num_threads) { if (num_threads != -1) { options.num_threads = num_threads; } + options.idle_timeout_sec = config::brpc_idle_timeout_sec; if (config::enable_https) { auto sslOptions = options.mutable_ssl_options(); diff --git a/be/src/util/thrift_server.cpp b/be/src/util/thrift_server.cpp index 7844f7daa1e0d4..84173300bd1aeb 100644 --- a/be/src/util/thrift_server.cpp +++ b/be/src/util/thrift_server.cpp @@ -377,6 +377,7 @@ Status ThriftServer::start() { server_socket = new apache::thrift::transport::TServerSocket( BackendOptions::get_service_bind_address_without_bracket(), _port); fe_server_transport.reset(server_socket); + server_socket->setKeepAlive(true); if (transport_factory == nullptr) { transport_factory.reset(new apache::thrift::transport::TBufferedTransportFactory());