Merge 'vector_store_client: disable Nagle's algorithm on the http client' from Pawel Pery
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 change sets `TCP_NODELAY` on every socket created by the `http_client`. Checking for dead peers or network is helpful in maintaining a lifetime of the http client. This change also sets TCP_KEEPALIVE option on the http client's socket. Fixes: VECTOR-169 Closes scylladb/scylladb#25401 * github.com:scylladb/scylladb: vector_store_client: set keepalive for the http client's socket vector_store_client: disable Nagle's algorithm on the http client
This commit is contained in:
@@ -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
|
||||
@@ -211,6 +214,27 @@ 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<connected_socket> 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;
|
||||
}
|
||||
};
|
||||
|
||||
class http_client {
|
||||
|
||||
host_port _host_port;
|
||||
@@ -222,7 +246,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<client_connection_factory>(socket_address(addr, _host_port.port))) {
|
||||
}
|
||||
|
||||
bool connects_to(inet_address const& a, port_number p) const {
|
||||
|
||||
Reference in New Issue
Block a user