diff --git a/substrate/client/cli/src/commands/run_cmd.rs b/substrate/client/cli/src/commands/run_cmd.rs index 9ef14cfa02..3e5823ef73 100644 --- a/substrate/client/cli/src/commands/run_cmd.rs +++ b/substrate/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/substrate/client/cli/src/config.rs b/substrate/client/cli/src/config.rs index a21a79afe9..62afc849c0 100644 --- a/substrate/client/cli/src/config.rs +++ b/substrate/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/substrate/client/rpc-servers/src/lib.rs b/substrate/client/rpc-servers/src/lib.rs index be6abea67b..cb2704efc8 100644 --- a/substrate/client/rpc-servers/src/lib.rs +++ b/substrate/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/substrate/client/service/src/config.rs b/substrate/client/service/src/config.rs index 5d8ee89225..f2c5f2c6ed 100644 --- a/substrate/client/service/src/config.rs +++ b/substrate/client/service/src/config.rs @@ -89,6 +89,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/substrate/client/service/src/lib.rs b/substrate/client/service/src/lib.rs index ae2cfbc8b8..51ee0965eb 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -381,6 +381,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), diff --git a/substrate/client/service/test/src/lib.rs b/substrate/client/service/test/src/lib.rs index a80c53a8c2..3999b852ac 100644 --- a/substrate/client/service/test/src/lib.rs +++ b/substrate/client/service/test/src/lib.rs @@ -262,6 +262,7 @@ fn node_config