rpc-http-threads cli arg (#8890)

* Add optional `rpc-http-threads` cli arg

* Update `http::ServerBuilder`threads
This commit is contained in:
tgmichel
2021-06-08 13:18:57 +02:00
committed by GitHub
parent 74793a83a5
commit a4bfd40a1b
8 changed files with 27 additions and 1 deletions
@@ -122,6 +122,10 @@ pub struct RunCmd {
#[structopt(long = "ws-max-connections", value_name = "COUNT")]
pub ws_max_connections: Option<usize>,
/// Size of the RPC HTTP server thread pool.
#[structopt(long = "rpc-http-threads", value_name = "COUNT")]
pub rpc_http_threads: Option<usize>,
/// 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<Option<usize>> {
Ok(self.rpc_http_threads)
}
fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {
Ok(self
.rpc_cors
+8
View File
@@ -358,6 +358,13 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: 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<Option<usize>> {
Ok(None)
}
/// Get the RPC cors (`None` if disabled)
///
/// By default this is `Some(Vec::new())`.
@@ -526,6 +533,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: 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,
+5 -1
View File
@@ -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<T> = pubsub::PubSubHandler<T, RpcMiddleware>;
@@ -79,11 +82,12 @@ mod inner {
/// **Note**: Only available if `not(target_os = "unknown")`.
pub fn start_http<M: pubsub::PubSubMetadata + Default>(
addr: &std::net::SocketAddr,
thread_pool_size: Option<usize>,
cors: Option<&Vec<String>>,
io: RpcHandler<M>,
) -> io::Result<http::Server> {
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() {
+2
View File
@@ -89,6 +89,8 @@ pub struct Configuration {
pub rpc_ipc: Option<String>,
/// Maximum number of connections for WebSockets RPC server. `None` if default.
pub rpc_ws_max_connections: Option<usize>,
/// Size of the RPC HTTP server thread pool. `None` if default.
pub rpc_http_threads: Option<usize>,
/// CORS settings for HTTP & WS servers. `None` if all origins are allowed.
pub rpc_cors: Option<Vec<String>>,
/// RPC methods to expose (by default only a safe subset or all of them).
+1
View File
@@ -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),
+1
View File
@@ -262,6 +262,7 @@ fn node_config<G: RuntimeGenesis + 'static, E: ChainSpecExtension + Clone + 'sta
rpc_ipc: None,
rpc_ws: None,
rpc_ws_max_connections: None,
rpc_http_threads: None,
rpc_cors: None,
rpc_methods: Default::default(),
prometheus_config: None,
@@ -124,6 +124,7 @@ pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn Chain
rpc_ws: None,
rpc_ipc: None,
rpc_ws_max_connections: None,
rpc_http_threads: None,
rpc_cors: None,
rpc_methods: Default::default(),
prometheus_config: None,
+1
View File
@@ -101,6 +101,7 @@ where
rpc_ipc: Default::default(),
rpc_ws: Default::default(),
rpc_ws_max_connections: Default::default(),
rpc_http_threads: Default::default(),
rpc_methods: Default::default(),
state_cache_child_ratio: Default::default(),
state_cache_size: Default::default(),