diff --git a/crates/sui-indexer-alt-jsonrpc/src/lib.rs b/crates/sui-indexer-alt-jsonrpc/src/lib.rs index f6d86429d00de..1b1a6c9358ed8 100644 --- a/crates/sui-indexer-alt-jsonrpc/src/lib.rs +++ b/crates/sui-indexer-alt-jsonrpc/src/lib.rs @@ -18,8 +18,12 @@ pub mod args; #[derive(clap::Args, Debug, Clone)] pub struct RpcArgs { /// Address to listen to for incoming JSON-RPC connections. - #[clap(long)] + #[clap(long, default_value_t = Self::default().listen_address)] listen_address: SocketAddr, + + /// The maximum number of concurrent connections to accept. + #[clap(long, default_value_t = Self::default().max_rpc_connections)] + max_rpc_connections: u32, } pub struct RpcService { @@ -35,10 +39,14 @@ impl RpcService { /// bind to its socket upon construction (and will fail if this is not possible), but will not /// accept connections until [Self::run] is called. pub async fn new(rpc_args: RpcArgs) -> anyhow::Result { - let RpcArgs { listen_address } = rpc_args; + let RpcArgs { + listen_address, + max_rpc_connections, + } = rpc_args; let server = ServerBuilder::new() .http_only() + .max_connections(max_rpc_connections) .build(listen_address) .await .context("Failed to bind server")?; @@ -78,6 +86,15 @@ impl RpcService { } } +impl Default for RpcArgs { + fn default() -> Self { + Self { + listen_address: "0.0.0.0:6000".parse().unwrap(), + max_rpc_connections: 100, + } + } +} + pub async fn start_rpc(args: Args) -> anyhow::Result<()> { let Args { db_args, rpc_args } = args; @@ -114,10 +131,12 @@ mod tests { } async fn test_service() -> RpcService { - let listen_address = test_listen_address(); - RpcService::new(RpcArgs { listen_address }) - .await - .expect("Failed to create test JSON-RPC service") + RpcService::new(RpcArgs { + listen_address: test_listen_address(), + ..Default::default() + }) + .await + .expect("Failed to create test JSON-RPC service") } #[tokio::test] diff --git a/crates/sui-pg-db/src/lib.rs b/crates/sui-pg-db/src/lib.rs index ca9b4178be299..d3062848bcef4 100644 --- a/crates/sui-pg-db/src/lib.rs +++ b/crates/sui-pg-db/src/lib.rs @@ -25,8 +25,8 @@ pub struct DbArgs { database_url: Url, /// Number of connections to keep in the pool. - #[arg(long, default_value_t = Self::default().connection_pool_size)] - connection_pool_size: u32, + #[arg(long, default_value_t = Self::default().db_connection_pool_size)] + db_connection_pool_size: u32, /// Time spent waiting for a connection from the pool to become available, in milliseconds. #[arg(long, default_value_t = Self::default().connection_timeout_ms)] @@ -169,7 +169,7 @@ impl Default for DbArgs { "postgres://postgres:postgrespw@localhost:5432/sui_indexer_alt", ) .unwrap(), - connection_pool_size: 100, + db_connection_pool_size: 100, connection_timeout_ms: 60_000, } } @@ -193,7 +193,7 @@ async fn pool(args: DbArgs) -> anyhow::Result> { let manager = AsyncDieselConnectionManager::new(args.database_url.as_str()); Ok(Pool::builder() - .max_size(args.connection_pool_size) + .max_size(args.db_connection_pool_size) .connection_timeout(args.connection_timeout()) .build(manager) .await?)