Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: set tcp_nodelay == true by default and explicit APIs #1263

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [v0.21.0] - 2023-12-11
## [v0.21.0] - 2023-12-13

This release contains big changes and let's go over the main ones:

Expand Down Expand Up @@ -100,6 +100,7 @@ and [@venugopv](https://github.com/venugopv) who contributed to this release.
- refactor(server): change ws ping API ([#1248](https://github.com/paritytech/jsonrpsee/pull/1248))
- refactor(ws client): generic over data stream ([#1168](https://github.com/paritytech/jsonrpsee/pull/1168))
- refactor(client): unify ws ping/pong API with the server ([#1258](https://github.com/paritytech/jsonrpsee/pull/1258)
- refactor: set `tcp_nodelay == true` by default ([#1263])(https://github.com/paritytech/jsonrpsee/pull/1263)

### [Added]
- feat(client): add `disconnect_reason` API ([#1246](https://github.com/paritytech/jsonrpsee/pull/1246))
Expand Down
38 changes: 25 additions & 13 deletions client/http-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::fmt;
use std::sync::Arc;
use std::time::Duration;

use crate::transport::{self, Error as TransportError, HttpBackend, HttpTransportClient};
use crate::transport::{self, Error as TransportError, HttpBackend, HttpTransportClient, HttpTransportClientBuilder};
use crate::types::{NotificationSer, RequestSer, Response};
use async_trait::async_trait;
use hyper::body::HttpBody;
Expand All @@ -49,7 +49,7 @@ use tower::layer::util::Identity;
use tower::{Layer, Service};
use tracing::instrument;

/// Http Client Builder.
/// HTTP client builder.
///
/// # Examples
///
Expand Down Expand Up @@ -83,6 +83,7 @@ pub struct HttpClientBuilder<L = Identity> {
max_log_length: u32,
headers: HeaderMap,
service_builder: tower::ServiceBuilder<L>,
tcp_no_delay: bool,
}

impl<L> HttpClientBuilder<L> {
Expand Down Expand Up @@ -160,6 +161,14 @@ impl<L> HttpClientBuilder<L> {
self
}

/// Configure `TCP_NODELAY` on the socket to the supplied value `nodelay`.
///
/// Default is `true`.
pub fn set_tcp_no_delay(mut self, no_delay: bool) -> Self {
self.tcp_no_delay = no_delay;
self
}

/// Set custom tower middleware.
pub fn set_http_middleware<T>(self, service_builder: tower::ServiceBuilder<T>) -> HttpClientBuilder<T> {
HttpClientBuilder {
Expand All @@ -172,6 +181,7 @@ impl<L> HttpClientBuilder<L> {
max_response_size: self.max_response_size,
service_builder,
request_timeout: self.request_timeout,
tcp_no_delay: self.tcp_no_delay,
}
}
}
Expand All @@ -196,19 +206,20 @@ where
headers,
max_log_length,
service_builder,
..
tcp_no_delay,
} = self;

let transport = HttpTransportClient::new(
max_request_size,
target,
max_response_size,
certificate_store,
max_log_length,
headers,
service_builder,
)
.map_err(|e| Error::Transport(e.into()))?;
let transport = HttpTransportClientBuilder::new()
.max_request_size(max_request_size)
.max_response_size(max_response_size)
.set_headers(headers)
.set_tcp_no_delay(tcp_no_delay)
.set_max_logging_length(max_log_length)
.set_service(service_builder)
.set_certification_store(certificate_store)
.build(target)
.map_err(|e| Error::Transport(e.into()))?;

Ok(HttpClient {
transport,
id_manager: Arc::new(RequestIdManager::new(max_concurrent_requests, id_kind)),
Expand All @@ -229,6 +240,7 @@ impl Default for HttpClientBuilder<Identity> {
max_log_length: 4096,
headers: HeaderMap::new(),
service_builder: tower::ServiceBuilder::new(),
tcp_no_delay: true,
}
}
}
Expand Down
Loading
Loading