From 4b459c6855f10bc4559d24ba927347e6ef034d34 Mon Sep 17 00:00:00 2001 From: Pawel Pery Date: Thu, 7 Aug 2025 16:22:46 +0200 Subject: [PATCH 1/2] vector_store_client: disable Nagle's algorithm on the http client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nagle’s algorithm and Delayed ACK’s algorithm are enabled by default on sockets in Linux. As a result we can experience 40ms latency on simply waiting for ACK on the client side. Disabling the Nagle’s algorithm (using TCP_NODELAY) should fix the issue (client won’t wait 40ms for ACKs). This patch sets `TCP_NODELAY` on every socket created by the `http_client`. --- service/vector_store_client.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/service/vector_store_client.cc b/service/vector_store_client.cc index 8eea20f700..df14478957 100644 --- a/service/vector_store_client.cc +++ b/service/vector_store_client.cc @@ -211,6 +211,21 @@ auto read_ann_json(rjson::value const& json, schema_ptr const& schema) -> std::e return std::move(keys); } +class client_connection_factory : public http::experimental::connection_factory { + socket_address _addr; + +public: + explicit client_connection_factory(socket_address addr) + : _addr(addr) { + } + + future make([[maybe_unused]] abort_source* as) override { + auto socket = co_await seastar::connect(_addr, {}, transport::TCP); + socket.set_nodelay(true); + co_return socket; + } +}; + class http_client { host_port _host_port; @@ -222,7 +237,7 @@ public: http_client(host_port host_port_, inet_address addr) : _host_port(std::move(host_port_)) , _addr(std::move(addr)) - , impl(socket_address(addr, _host_port.port)) { + , impl(std::make_unique(socket_address(addr, _host_port.port))) { } bool connects_to(inet_address const& a, port_number p) const { From 509f5ddb89d93ea6fbf241d35721f9308d1a3ad5 Mon Sep 17 00:00:00 2001 From: Pawel Pery Date: Thu, 7 Aug 2025 16:53:41 +0200 Subject: [PATCH 2/2] vector_store_client: set keepalive for the http client's socket Checking for dead peers or network is helpful in maintaining a lifetime of the http client. This patch sets TCP_KEEPALIVE option on the http client's socket. --- service/vector_store_client.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/service/vector_store_client.cc b/service/vector_store_client.cc index df14478957..f8a85b0572 100644 --- a/service/vector_store_client.cc +++ b/service/vector_store_client.cc @@ -31,6 +31,8 @@ namespace { +using namespace std::chrono_literals; + using ann_error = service::vector_store_client::ann_error; using configuration_exception = exceptions::configuration_exception; using duration = lowres_clock::duration; @@ -46,6 +48,7 @@ using port_number = service::vector_store_client::port_number; using primary_key = service::vector_store_client::primary_key; using primary_keys = service::vector_store_client::primary_keys; using service_reply_format_error = service::vector_store_client::service_reply_format_error; +using tcp_keepalive_params = net::tcp_keepalive_params; using time_point = lowres_clock::time_point; // Wait time before retrying after an exception occurred @@ -222,6 +225,12 @@ public: future make([[maybe_unused]] abort_source* as) override { auto socket = co_await seastar::connect(_addr, {}, transport::TCP); socket.set_nodelay(true); + socket.set_keepalive_parameters(tcp_keepalive_params{ + .idle = 60s, + .interval = 60s, + .count = 10, + }); + socket.set_keepalive(true); co_return socket; } };