Option to disable keep alive for JSON-RPC http transport (#9848)
* Keep alive jsonrpc CLI option. * Update to latest json-rpc. * Keep alive flag.
This commit is contained in:
parent
3a6e04ba15
commit
59daf95859
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -1552,7 +1552,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-core"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1564,7 +1564,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-http-server"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"hyper 0.12.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
@ -1577,7 +1577,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-ipc-server"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
"jsonrpc-server-utils 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
@ -1590,7 +1590,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-macros"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
"jsonrpc-pubsub 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
@ -1600,7 +1600,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-pubsub"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1610,7 +1610,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-server-utils"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1626,7 +1626,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-tcp-server"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
"jsonrpc-server-utils 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
@ -1638,7 +1638,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "jsonrpc-ws-server"
|
||||
version = "9.0.0"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#207a277b098943864ecaf22dbab7a5e309866d6b"
|
||||
source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2#f8a54f46f7f1d68b4e7899ca1e929803bf966a5b"
|
||||
dependencies = [
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 9.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-2.2)",
|
||||
|
@ -467,6 +467,10 @@ usage! {
|
||||
"--no-jsonrpc",
|
||||
"Disable the HTTP JSON-RPC API server.",
|
||||
|
||||
FLAG flag_jsonrpc_no_keep_alive: (bool) = false, or |c: &Config| c.rpc.as_ref()?.keep_alive,
|
||||
"--jsonrpc-no-keep-alive",
|
||||
"Disable HTTP/1.1 keep alive header. Disabling keep alive will prevent re-using the same TCP connection to fire multiple requests, recommended when using one request per connection.",
|
||||
|
||||
ARG arg_jsonrpc_port: (u16) = 8545u16, or |c: &Config| c.rpc.as_ref()?.port.clone(),
|
||||
"--jsonrpc-port=[PORT]",
|
||||
"Specify the port portion of the HTTP JSON-RPC API server.",
|
||||
@ -1219,6 +1223,7 @@ struct Rpc {
|
||||
server_threads: Option<usize>,
|
||||
processing_threads: Option<usize>,
|
||||
max_payload: Option<usize>,
|
||||
keep_alive: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
@ -1676,6 +1681,7 @@ mod tests {
|
||||
// -- API and Console Options
|
||||
// RPC
|
||||
flag_no_jsonrpc: false,
|
||||
flag_jsonrpc_no_keep_alive: false,
|
||||
arg_jsonrpc_port: 8545u16,
|
||||
arg_jsonrpc_interface: "local".into(),
|
||||
arg_jsonrpc_cors: "null".into(),
|
||||
@ -1958,6 +1964,7 @@ mod tests {
|
||||
server_threads: None,
|
||||
processing_threads: None,
|
||||
max_payload: None,
|
||||
keep_alive: None,
|
||||
}),
|
||||
ipc: Some(Ipc {
|
||||
disable: None,
|
||||
|
@ -855,6 +855,7 @@ impl Configuration {
|
||||
Some(max) if max > 0 => max as usize,
|
||||
_ => 5usize,
|
||||
},
|
||||
keep_alive: !self.args.flag_jsonrpc_no_keep_alive,
|
||||
};
|
||||
|
||||
Ok(conf)
|
||||
|
@ -44,6 +44,7 @@ pub struct HttpConfiguration {
|
||||
pub server_threads: usize,
|
||||
pub processing_threads: usize,
|
||||
pub max_payload: usize,
|
||||
pub keep_alive: bool,
|
||||
}
|
||||
|
||||
impl Default for HttpConfiguration {
|
||||
@ -58,6 +59,7 @@ impl Default for HttpConfiguration {
|
||||
server_threads: 1,
|
||||
processing_threads: 4,
|
||||
max_payload: 5,
|
||||
keep_alive: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,6 +220,7 @@ pub fn new_http<D: rpc_apis::Dependencies>(
|
||||
rpc::RpcExtractor,
|
||||
conf.server_threads,
|
||||
conf.max_payload,
|
||||
conf.keep_alive,
|
||||
);
|
||||
|
||||
match start_result {
|
||||
|
@ -137,6 +137,7 @@ pub fn start_http<M, S, H, T>(
|
||||
extractor: T,
|
||||
threads: usize,
|
||||
max_payload: usize,
|
||||
keep_alive: bool,
|
||||
) -> ::std::io::Result<HttpServer> where
|
||||
M: jsonrpc_core::Metadata,
|
||||
S: jsonrpc_core::Middleware<M>,
|
||||
@ -145,6 +146,7 @@ pub fn start_http<M, S, H, T>(
|
||||
{
|
||||
let extractor = http_common::MetaExtractor::new(extractor);
|
||||
Ok(http::ServerBuilder::with_meta_extractor(handler, extractor)
|
||||
.keep_alive(keep_alive)
|
||||
.threads(threads)
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
@ -163,6 +165,7 @@ pub fn start_http_with_middleware<M, S, H, T, R>(
|
||||
middleware: R,
|
||||
threads: usize,
|
||||
max_payload: usize,
|
||||
keep_alive: bool,
|
||||
) -> ::std::io::Result<HttpServer> where
|
||||
M: jsonrpc_core::Metadata,
|
||||
S: jsonrpc_core::Middleware<M>,
|
||||
@ -172,6 +175,7 @@ pub fn start_http_with_middleware<M, S, H, T, R>(
|
||||
{
|
||||
let extractor = http_common::MetaExtractor::new(extractor);
|
||||
Ok(http::ServerBuilder::with_meta_extractor(handler, extractor)
|
||||
.keep_alive(keep_alive)
|
||||
.threads(threads)
|
||||
.cors(cors_domains.into())
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
|
@ -40,6 +40,7 @@ fn serve(handler: Option<MetaIoHandler<Metadata>>) -> Server<HttpServer> {
|
||||
},
|
||||
1,
|
||||
5,
|
||||
false,
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
|
@ -218,9 +218,10 @@ impl<M: core::Middleware<Metadata>> WsDispatcher<M> {
|
||||
|
||||
impl<M: core::Middleware<Metadata>> core::Middleware<Metadata> for WsDispatcher<M> {
|
||||
type Future = Either<
|
||||
core::FutureRpcResult<M::Future>,
|
||||
core::FutureRpcResult<M::Future, M::CallFuture>,
|
||||
core::FutureResponse,
|
||||
>;
|
||||
type CallFuture = core::middleware::NoopCallFuture;
|
||||
|
||||
fn on_request<F, X>(&self, request: core::Request, meta: Metadata, process: F)
|
||||
-> Either<Self::Future, X>
|
||||
|
@ -205,6 +205,7 @@ impl<T: ActivityNotifier> Middleware<T> {
|
||||
|
||||
impl<M: core::Metadata, T: ActivityNotifier> core::Middleware<M> for Middleware<T> {
|
||||
type Future = core::FutureResponse;
|
||||
type CallFuture = core::middleware::NoopCallFuture;
|
||||
|
||||
fn on_request<F, X>(&self, request: core::Request, meta: M, process: F) -> Either<Self::Future, X> where
|
||||
F: FnOnce(core::Request, M) -> X,
|
||||
|
Loading…
Reference in New Issue
Block a user