Skip to content

Commit

Permalink
set max batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
shunsukew committed May 20, 2024
1 parent aa48c3a commit 435b6dd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions benches/bench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ fn config() -> Config {
listen_address: SUBWAY_SERVER_ADDR.to_string(),
port: SUBWAY_SERVER_PORT,
max_connections: 1024 * 1024,
max_batch_size: None,
request_timeout_seconds: 120,
http_methods: Vec::new(),
cors: None,
Expand Down
1 change: 1 addition & 0 deletions configs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extensions:
port: 9944
listen_address: '0.0.0.0'
max_connections: 2000
max_batch_size: 10
http_methods:
- path: /health
method: system_health
Expand Down
1 change: 1 addition & 0 deletions configs/eth_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extensions:
port: 8545
listen_address: '0.0.0.0'
max_connections: 2000
max_batch_size: 10
cors: all

middlewares:
Expand Down
9 changes: 8 additions & 1 deletion src/extensions/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hyper::service::Service;
use hyper::service::{make_service_fn, service_fn};
use jsonrpsee::server::{
middleware::rpc::RpcServiceBuilder, stop_channel, ws, RandomStringIdProvider, RpcModule, ServerBuilder,
ServerHandle,
ServerHandle, BatchRequestConfig,
};
use jsonrpsee::Methods;

Expand Down Expand Up @@ -61,6 +61,7 @@ pub struct ServerConfig {
pub port: u16,
pub listen_address: String,
pub max_connections: u32,
pub max_batch_size: Option<u32>,
#[serde(default)]
pub http_methods: Vec<HttpMethodsConfig>,
#[serde(default = "default_request_timeout_seconds")]
Expand Down Expand Up @@ -176,10 +177,16 @@ impl SubwayServerBuilder {
.map(|(a, b, c)| layer_fn(|s| PrometheusService::new(s, protocol, a, b, c))),
);

let batch_request_config = match config.max_batch_size {
Some(max_size) => BatchRequestConfig::Limit(max_size),
None => BatchRequestConfig::Unlimited,
};

let service_builder = ServerBuilder::default()
.set_rpc_middleware(rpc_middleware)
.set_http_middleware(http_middleware)
.max_connections(config.max_connections)
.set_batch_request_config(batch_request_config)
.set_id_provider(RandomStringIdProvider::new(16))
.to_service_builder();

Expand Down
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ mod tests {
listen_address: "127.0.0.1".to_string(),
port,
max_connections: 1024,
max_batch_size: None,
request_timeout_seconds: request_timeout_seconds.unwrap_or(10),
http_methods: Vec::new(),
cors: None,
Expand Down
1 change: 1 addition & 0 deletions src/tests/merge_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async fn merge_subscription_works() {
listen_address: "0.0.0.0".to_string(),
port: 0,
max_connections: 10,
max_batch_size: None,
request_timeout_seconds: 120,
http_methods: Vec::new(),
cors: None,
Expand Down
1 change: 1 addition & 0 deletions src/tests/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async fn upstream_error_propagate() {
listen_address: "0.0.0.0".to_string(),
port: 0,
max_connections: 10,
max_batch_size: None,
request_timeout_seconds: 120,
http_methods: Vec::new(),
cors: None,
Expand Down

0 comments on commit 435b6dd

Please sign in to comment.