From 227c3120eba675fd8b878f80b75302b1ce7d1be9 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 24 May 2021 10:48:22 +0200 Subject: [PATCH 1/2] Add optional `rpc-http-threads` cli arg --- client/cli/src/commands/run_cmd.rs | 8 ++++++++ client/cli/src/config.rs | 8 ++++++++ client/service/src/config.rs | 2 ++ client/service/test/src/lib.rs | 1 + test-utils/test-runner/src/utils.rs | 1 + utils/browser/src/lib.rs | 1 + 6 files changed, 21 insertions(+) diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index 9ef14cfa02b82..3e5823ef733aa 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -122,6 +122,10 @@ pub struct RunCmd { #[structopt(long = "ws-max-connections", value_name = "COUNT")] pub ws_max_connections: Option, + /// Size of the RPC HTTP server thread pool. + #[structopt(long = "rpc-http-threads", value_name = "COUNT")] + pub rpc_http_threads: Option, + /// Specify browser Origins allowed to access the HTTP & WS RPC servers. /// /// A comma-separated list of origins (protocol://domain or special `null` @@ -376,6 +380,10 @@ impl CliConfiguration for RunCmd { Ok(self.ws_max_connections) } + fn rpc_http_threads(&self) -> Result> { + Ok(self.rpc_http_threads) + } + fn rpc_cors(&self, is_dev: bool) -> Result>> { Ok(self .rpc_cors diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index a21a79afe9fdb..62afc849c09fb 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -358,6 +358,13 @@ pub trait CliConfiguration: Sized { Ok(None) } + /// Get the RPC HTTP thread pool size (`None` for a default 4-thread pool config). + /// + /// By default this is `None`. + fn rpc_http_threads(&self) -> Result> { + Ok(None) + } + /// Get the RPC cors (`None` if disabled) /// /// By default this is `Some(Vec::new())`. @@ -526,6 +533,7 @@ pub trait CliConfiguration: Sized { rpc_ipc: self.rpc_ipc()?, rpc_methods: self.rpc_methods()?, rpc_ws_max_connections: self.rpc_ws_max_connections()?, + rpc_http_threads: self.rpc_http_threads()?, rpc_cors: self.rpc_cors(is_dev)?, prometheus_config: self.prometheus_config(DCV::prometheus_listen_port())?, telemetry_endpoints, diff --git a/client/service/src/config.rs b/client/service/src/config.rs index f82a877545e8c..a733dc94ed39c 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -85,6 +85,8 @@ pub struct Configuration { pub rpc_ipc: Option, /// Maximum number of connections for WebSockets RPC server. `None` if default. pub rpc_ws_max_connections: Option, + /// Size of the RPC HTTP server thread pool. `None` if default. + pub rpc_http_threads: Option, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, /// RPC methods to expose (by default only a safe subset or all of them). diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index a80c53a8c21c5..3999b852ac74c 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -262,6 +262,7 @@ fn node_config Date: Mon, 24 May 2021 10:49:27 +0200 Subject: [PATCH 2/2] Update `http::ServerBuilder`threads --- client/rpc-servers/src/lib.rs | 6 +++++- client/service/src/lib.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index be6abea67b055..cb2704efc82ab 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -33,6 +33,9 @@ pub const MAX_PAYLOAD: usize = 15 * 1024 * 1024; /// Default maximum number of connections for WS RPC servers. const WS_MAX_CONNECTIONS: usize = 100; +/// Default thread pool size for RPC HTTP servers. +const HTTP_THREADS: usize = 4; + /// The RPC IoHandler containing all requested APIs. pub type RpcHandler = pubsub::PubSubHandler; @@ -79,11 +82,12 @@ mod inner { /// **Note**: Only available if `not(target_os = "unknown")`. pub fn start_http( addr: &std::net::SocketAddr, + thread_pool_size: Option, cors: Option<&Vec>, io: RpcHandler, ) -> io::Result { http::ServerBuilder::new(io) - .threads(4) + .threads(thread_pool_size.unwrap_or(HTTP_THREADS)) .health_api(("/health", "system_health")) .allowed_hosts(hosts_filtering(cors.is_some())) .rest_api(if cors.is_some() { diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 0e47b775e4a43..adecff014c4dc 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -431,6 +431,7 @@ fn start_rpc_servers< config.rpc_http, |address| sc_rpc_server::start_http( address, + config.rpc_http_threads, config.rpc_cors.as_ref(), gen_handler( deny_unsafe(&address, &config.rpc_methods),