Skip to content

Commit

Permalink
init commit of rpc benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
gegaowp committed Nov 25, 2024
1 parent 8bbdec3 commit a256fc7
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions crates/sui-rpc-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "sui-rpc-benchmark"
version.workspace = true
authors = ["Mysten Labs <[email protected]>"]
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"
32 changes: 32 additions & 0 deletions crates/sui-rpc-benchmark/README.md
Original file line number Diff line number Diff line change
@@ -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
```



71 changes: 71 additions & 0 deletions crates/sui-rpc-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
}

11 changes: 11 additions & 0 deletions crates/sui-rpc-benchmark/src/main.rs
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit a256fc7

Please sign in to comment.