diff --git a/Cargo.lock b/Cargo.lock index 5c8a39444f115c..9514385efda232 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15148,6 +15148,23 @@ dependencies = [ "typed-store", ] +[[package]] +name = "sui-rpc-benchmark" +version = "1.39.0" +dependencies = [ + "anyhow", + "async-trait", + "clap", + "futures", + "serde", + "serde_json", + "sui-sdk", + "sui-types", + "telemetry-subscribers", + "tokio", + "tracing", +] + [[package]] name = "sui-rpc-loadgen" version = "1.39.0" diff --git a/Cargo.toml b/Cargo.toml index c33adee27a8a61..201f316630b1a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,6 +148,7 @@ members = [ "crates/sui-replay", "crates/sui-rest-api", "crates/sui-rosetta", + "crates/sui-rpc-benchmark", "crates/sui-rpc-loadgen", "crates/sui-sdk", "crates/sui-security-watchdog", diff --git a/crates/sui-rpc-benchmark/Cargo.toml b/crates/sui-rpc-benchmark/Cargo.toml new file mode 100644 index 00000000000000..230b8a38b3c4af --- /dev/null +++ b/crates/sui-rpc-benchmark/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "sui-rpc-benchmark" +version.workspace = true +authors = ["Mysten Labs "] +license = "Apache-2.0" +publish = false +edition = "2021" + +[dependencies] +anyhow.workspace = true +async-trait.workspace = true +clap = { workspace = true, features = ["derive"] } +tokio = { workspace = true, features = ["full"] } +tracing.workspace = true +futures.workspace = true +serde.workspace = true +serde_json.workspace = true + +sui-types.workspace = true +sui-sdk.workspace = true +telemetry-subscribers.workspace = true + +[[bin]] +name = "sui-rpc-benchmark" +path = "src/main.rs" diff --git a/crates/sui-rpc-benchmark/README.md b/crates/sui-rpc-benchmark/README.md new file mode 100644 index 00000000000000..f6e6f36a2b39b6 --- /dev/null +++ b/crates/sui-rpc-benchmark/README.md @@ -0,0 +1,32 @@ +# sui-rpc-benchmark: Benchmarking Tool for SUI RPC Performance + +`sui-rpc-benchmark` is a benchmarking utility designed to measure and compare performance across different RPC access methods in Sui: + +- Direct database reads +- JSON RPC endpoints +- GraphQL queries + +## Overview + +The benchmark tool helps evaluate: +- Query latency and throughput +- Resource utilization +- Performance at scale + +## Usage Examples + +Run benchmarks with: + +``` +# Direct database queries: +cargo run --release --bin sui-rpc-benchmark direct --num-queries 100 --num-threads 1 + +# JSON RPC endpoints: +cargo run --release --bin sui-rpc-benchmark jsonrpc --endpoint http://127.0.0.1:9000 --num-queries 100 --num-threads 1 + +# GraphQL queries: +cargo run --release --bin sui-rpc-benchmark graphql --endpoint http://127.0.0.1:9000/graphql --num-queries 100 --num-threads 1 +``` + + + diff --git a/crates/sui-rpc-benchmark/src/lib.rs b/crates/sui-rpc-benchmark/src/lib.rs new file mode 100644 index 00000000000000..9de43b6332b8d9 --- /dev/null +++ b/crates/sui-rpc-benchmark/src/lib.rs @@ -0,0 +1,71 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +use clap::{Parser, Subcommand}; +use anyhow::Result; + +#[derive(Parser)] +#[clap( + name = "sui-rpc-benchmark", + about = "Benchmark tool for comparing Sui RPC access methods" +)] +pub struct Opts { + #[clap(subcommand)] + pub command: Command, +} + +#[derive(Subcommand)] +pub enum Command { + /// Benchmark direct database queries + #[clap(name = "direct")] + DirectQuery { + #[clap(long, default_value = "100")] + num_queries: u64, + #[clap(long, default_value = "1")] + num_threads: usize, + }, + + /// Benchmark JSON RPC endpoints + #[clap(name = "jsonrpc")] + JsonRpc { + #[clap(long, default_value = "http://127.0.0.1:9000")] + endpoint: String, + #[clap(long, default_value = "100")] + num_queries: u64, + #[clap(long, default_value = "1")] + num_threads: usize, + }, + + /// Benchmark GraphQL queries + #[clap(name = "graphql")] + GraphQL { + #[clap(long, default_value = "http://127.0.0.1:9000/graphql")] + endpoint: String, + #[clap(long, default_value = "100")] + num_queries: u64, + #[clap(long, default_value = "1")] + num_threads: usize, + }, +} + +pub fn run_benchmarks() -> Result<()> { + let opts: Opts = Opts::parse(); + + match opts.command { + Command::DirectQuery { num_queries, num_threads } => { + println!("Running direct query benchmark with {} queries and {} threads", num_queries, num_threads); + Ok(()) + } + Command::JsonRpc { endpoint, num_queries, num_threads } => { + println!("Running JSON RPC benchmark against {} with {} queries and {} threads", endpoint, num_queries, num_threads); + // TODO: Implement JSON RPC benchmark + Ok(()) + } + Command::GraphQL { endpoint, num_queries, num_threads } => { + println!("Running GraphQL benchmark against {} with {} queries and {} threads", endpoint, num_queries, num_threads); + // TODO: Implement GraphQL benchmark + Ok(()) + } + } +} + diff --git a/crates/sui-rpc-benchmark/src/main.rs b/crates/sui-rpc-benchmark/src/main.rs new file mode 100644 index 00000000000000..1f206ed8bffab9 --- /dev/null +++ b/crates/sui-rpc-benchmark/src/main.rs @@ -0,0 +1,11 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +use anyhow::Result; + +use sui_rpc_benchmark::run_benchmarks; + +#[tokio::main] +async fn main() -> Result<()> { + run_benchmarks() +}