Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Option to disable keep alive for JSON-RPC http transport (#9848)
Browse files Browse the repository at this point in the history
* Keep alive jsonrpc CLI option.

* Update to latest json-rpc.

* Keep alive flag.
  • Loading branch information
tomusdrw authored and sorpaas committed Nov 5, 2018
1 parent 3a6e04b commit 59daf95
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 9 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -1958,6 +1964,7 @@ mod tests {
server_threads: None,
processing_threads: None,
max_payload: None,
keep_alive: None,
}),
ipc: Some(Ipc {
disable: None,
Expand Down
1 change: 1 addition & 0 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions parity/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -58,6 +59,7 @@ impl Default for HttpConfiguration {
server_threads: 1,
processing_threads: 4,
max_payload: 5,
keep_alive: true,
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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())
Expand All @@ -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>,
Expand All @@ -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())
Expand Down
1 change: 1 addition & 0 deletions rpc/src/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn serve(handler: Option<MetaIoHandler<Metadata>>) -> Server<HttpServer> {
},
1,
5,
false,
).unwrap())
}

Expand Down
3 changes: 2 additions & 1 deletion rpc/src/v1/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions rpc/src/v1/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 59daf95

Please sign in to comment.