Skip to content

Commit 59d7ce7

Browse files
popcnt1popcnt-subodhi
and
popcnt-subodhi
authored
ci: move build tx out of execution bench (#1390)
## Summary 1. move build tx out of execution bench, result: #1383 (comment) huge improvement(It's actually closer to the real server-side execution overhead) , the major cost is from tokio wake in present (need to figure out) 2. split write/query bench --------- Co-authored-by: popcnt-subodhi <subodhi@west>
1 parent aaaaf8a commit 59d7ce7

File tree

8 files changed

+154
-87
lines changed

8 files changed

+154
-87
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ base64 = "0.21.3"
249249
pprof = { version = "0.13.0", features = ["flamegraph", "criterion", "cpp", "frame-pointer"] }
250250

251251

252+
252253
celestia-rpc = { git = "https://github.com/eigerco/celestia-node-rs.git", rev = "129272e8d926b4c7badf27a26dea915323dd6489" }
253254
celestia-types = { git = "https://github.com/eigerco/celestia-node-rs.git", rev = "129272e8d926b4c7badf27a26dea915323dd6489" }
254255

crates/rooch-benchmarks/Cargo.toml

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,12 @@ bench = false
7575

7676
[[bench]]
7777
harness = false
78-
name = "bench_transaction"
78+
name = "bench_tx_write"
79+
80+
[[bench]]
81+
harness = false
82+
name = "bench_tx_query"
83+
84+
[[bench]]
85+
harness = false
86+
name = "bench_tx"

crates/rooch-benchmarks/README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,42 @@ cargo bench
99
2. run a special benchmark
1010

1111
```shell
12-
cargo bench --bench bench_transaction
13-
cargo bench --bench bench_transaction -- --verbose
12+
cargo bench --bench bench_tx
13+
cargo bench --bench bench_tx -- --verbose
14+
cargo bench --bench bench_tx_query
15+
cargo bench --bench bench_tx_write
1416
```
1517

1618
3. run a special benchmark with pprof (on linux)
19+
1720
```shell
18-
cargo bench --bench bench_transaction -- --profile-time=10
21+
cargo bench --bench bench_tx -- --profile-time=10
1922
```
2023

2124
## On OSX
2225

2326
1. install xcode and command line tools
2427

2528
2. install cargo instruments
29+
2630
```shell
2731
brew install cargo-instruments
2832
```
2933

3034
3. install cargo flamegraph
35+
3136
```shell
3237
cargo install flamegraph
3338
```
3439

3540
4. install gnuplot
41+
3642
```shell
3743
brew install gnuplot
3844
```
3945

4046
5. run with profile
47+
4148
```shell
42-
cargo instruments -t time --bench bench_transaction -- --bench
49+
cargo instruments -t time --bench bench_tx -- --bench
4350
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) RoochNetwork
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
mod bench_tx_query;
5+
mod bench_tx_write;
6+
7+
use bench_tx_query::transaction_query_benchmark;
8+
use bench_tx_write::transaction_write_benchmark;
9+
use criterion::{criterion_group, criterion_main, Criterion};
10+
use std::time::Duration;
11+
12+
criterion_group! {
13+
name = rooch_tx_bench;
14+
config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(10));
15+
targets = transaction_write_benchmark, transaction_query_benchmark
16+
}
17+
18+
criterion_main!(rooch_tx_bench);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) RoochNetwork
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use criterion::{criterion_group, criterion_main, Criterion};
5+
use moveos_config::temp_dir;
6+
use rooch_benchmarks::tx::{create_publish_transaction, create_transaction, setup_service};
7+
use rooch_key::keystore::account_keystore::AccountKeystore;
8+
use rooch_key::keystore::memory_keystore::InMemKeystore;
9+
use rooch_rpc_api::api::rooch_api::RoochAPIServer;
10+
use rooch_rpc_api::jsonrpc_types::StrView;
11+
use rooch_rpc_server::server::rooch_server::RoochServer;
12+
use rooch_test_transaction_builder::TestTransactionBuilder;
13+
use std::time::Duration;
14+
use tokio::runtime::Runtime;
15+
16+
pub fn transaction_query_benchmark(c: &mut Criterion) {
17+
let tempdir = temp_dir();
18+
let keystore = InMemKeystore::new_insecure_for_tests(10);
19+
20+
let rt: Runtime = Runtime::new().unwrap();
21+
let (rpc_service, aggregate_service) =
22+
rt.block_on(async { setup_service(&tempdir, &keystore).await.unwrap() });
23+
let rooch_server = RoochServer::new(rpc_service.clone(), aggregate_service);
24+
25+
let default_account = keystore.addresses()[0];
26+
let mut test_transaction_builder = TestTransactionBuilder::new(default_account.into());
27+
let tx = create_publish_transaction(&test_transaction_builder, &keystore).unwrap();
28+
let _publish_result = rt.block_on(async { rpc_service.execute_tx(tx).await.unwrap() });
29+
//
30+
for n in 1..500 {
31+
let tx = create_transaction(&mut test_transaction_builder, &keystore, n).unwrap();
32+
let _ = rt.block_on(async { rpc_service.execute_tx(tx).await.unwrap() });
33+
}
34+
35+
let mut tx_orders = (1..500).cycle().map(|v| v);
36+
c.bench_function("get_transactions_by_order", |b| {
37+
b.to_async(Runtime::new().unwrap()).iter(|| {
38+
rooch_server.get_transactions_by_order(
39+
Some(StrView(tx_orders.next().unwrap())),
40+
None,
41+
None,
42+
)
43+
})
44+
});
45+
}
46+
47+
criterion_group! {
48+
name = rooch_tx_query_bench;
49+
config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(10));
50+
targets = transaction_query_benchmark
51+
}
52+
criterion_main!(rooch_tx_query_bench);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) RoochNetwork
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use criterion::{criterion_group, criterion_main, Criterion};
5+
use moveos_config::temp_dir;
6+
use rooch_benchmarks::tx::{create_transaction, setup_service};
7+
use rooch_key::keystore::account_keystore::AccountKeystore;
8+
use rooch_key::keystore::memory_keystore::InMemKeystore;
9+
use rooch_test_transaction_builder::TestTransactionBuilder;
10+
use std::fs::File;
11+
use std::time::Duration;
12+
use tokio::runtime::Runtime;
13+
14+
pub fn transaction_write_benchmark(c: &mut Criterion) {
15+
let tempdir = temp_dir();
16+
let keystore = InMemKeystore::new_insecure_for_tests(10);
17+
18+
let rt: Runtime = Runtime::new().unwrap();
19+
let (rpc_service, _aggregate_service) =
20+
rt.block_on(async { setup_service(&tempdir, &keystore).await.unwrap() });
21+
22+
let default_account = keystore.addresses()[0];
23+
let mut test_transaction_builder = TestTransactionBuilder::new(default_account.into());
24+
25+
let transactions: Vec<_> = (0..10000)
26+
.map(|n| create_transaction(&mut test_transaction_builder, &keystore, n).unwrap())
27+
.collect();
28+
let mut transactions_iter = transactions.into_iter().cycle();
29+
30+
let guard = pprof::ProfilerGuardBuilder::default()
31+
.frequency(1000)
32+
.blocklist(&["libc", "libgcc", "pthread", "vdso"])
33+
.build()
34+
.unwrap();
35+
36+
c.bench_function("execute_tx", |b| {
37+
b.to_async(Runtime::new().unwrap()).iter(|| {
38+
let tx = transactions_iter.next().unwrap();
39+
rpc_service.execute_tx(tx)
40+
});
41+
});
42+
43+
if let Ok(report) = guard.report().build() {
44+
let file = File::create("flamegraph.svg").unwrap();
45+
report.flamegraph(file).unwrap();
46+
};
47+
}
48+
49+
criterion_group! {
50+
name = rooch_tx_write_bench;
51+
config = Criterion::default().warm_up_time(Duration::from_millis(100)).sample_size(10).measurement_time(Duration::from_secs(3));
52+
targets = transaction_write_benchmark
53+
}
54+
55+
criterion_main!(rooch_tx_write_bench);

crates/rooch-benchmarks/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
pub mod helper;
5+
pub mod tx;

crates/rooch-benchmarks/benches/bench_transaction.rs crates/rooch-benchmarks/src/tx.rs

+7-82
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ use anyhow::Result;
55
use coerce::actor::scheduler::timer::Timer;
66
use coerce::actor::system::ActorSystem;
77
use coerce::actor::IntoActor;
8-
use criterion::{criterion_group, criterion_main, Criterion};
98
use moveos_config::store_config::RocksdbConfig;
10-
use moveos_config::{temp_dir, DataDirPath};
9+
use moveos_config::DataDirPath;
1110
use moveos_store::{MoveOSDB, MoveOSStore};
12-
use rooch_framework::natives::default_gas_schedule;
13-
// use pprof::criterion::{Output, PProfProfiler};
1411
use raw_store::rocks::RocksDB;
1512
use raw_store::StoreInstance;
1613
use rooch_config::da_config::DAConfig;
@@ -21,6 +18,7 @@ use rooch_da::proxy::DAProxy;
2118
use rooch_executor::actor::executor::ExecutorActor;
2219
use rooch_executor::actor::reader_executor::ReaderExecutorActor;
2320
use rooch_executor::proxy::ExecutorProxy;
21+
use rooch_framework::natives::default_gas_schedule;
2422
use rooch_indexer::actor::indexer::IndexerActor;
2523
use rooch_indexer::actor::reader_indexer::IndexerReaderActor;
2624
use rooch_indexer::indexer_reader::IndexerReader;
@@ -31,9 +29,6 @@ use rooch_key::keystore::memory_keystore::InMemKeystore;
3129
use rooch_proposer::actor::messages::ProposeBlock;
3230
use rooch_proposer::actor::proposer::ProposerActor;
3331
use rooch_proposer::proxy::ProposerProxy;
34-
use rooch_rpc_api::api::rooch_api::RoochAPIServer;
35-
use rooch_rpc_api::jsonrpc_types::StrView;
36-
use rooch_rpc_server::server::rooch_server::RoochServer;
3732
use rooch_rpc_server::service::aggregate_service::AggregateService;
3833
use rooch_rpc_server::service::rpc_service::RpcService;
3934
use rooch_sequencer::actor::sequencer::SequencerActor;
@@ -46,73 +41,12 @@ use rooch_types::bitcoin::network::Network;
4641
use rooch_types::chain_id::RoochChainID;
4742
use rooch_types::transaction::TypedTransaction;
4843
use std::time::Duration;
49-
use tokio::runtime::Runtime;
5044
use tracing::info;
5145

5246
pub const EXAMPLE_SIMPLE_BLOG_PACKAGE_NAME: &'static str = "simple_blog";
5347
pub const EXAMPLE_SIMPLE_BLOG_NAMED_ADDRESS: &str = "simple_blog";
5448

55-
pub struct StoreHolder {
56-
_moveos_store: MoveOSStore,
57-
_rooch_store: RoochStore,
58-
_indexer_store: IndexerStore,
59-
}
60-
fn transaction_write_benchmark(c: &mut Criterion) {
61-
std::env::set_var("RUST_LOG", "error");
62-
63-
let tempdir = temp_dir();
64-
let keystore = InMemKeystore::new_insecure_for_tests(10);
65-
66-
let rt: Runtime = Runtime::new().unwrap();
67-
let (rpc_service, _aggregate_service) =
68-
rt.block_on(async { setup_service(&tempdir, &keystore).await.unwrap() });
69-
70-
let default_account = keystore.addresses()[0];
71-
let mut test_transaction_builder = TestTransactionBuilder::new(default_account.into());
72-
let tx = create_publish_transaction(&test_transaction_builder, &keystore).unwrap();
73-
let _publish_result = rt.block_on(async { rpc_service.execute_tx(tx).await.unwrap() });
74-
75-
let mut transactions = (1..500)
76-
.cycle()
77-
.map(|n| create_transaction(&mut test_transaction_builder, &keystore, n).unwrap());
78-
c.bench_function("execute_tx", |b| {
79-
b.to_async(Runtime::new().unwrap())
80-
.iter(|| rpc_service.execute_tx(transactions.next().unwrap()))
81-
});
82-
}
83-
84-
fn transaction_query_benchmark(c: &mut Criterion) {
85-
let tempdir = temp_dir();
86-
let keystore = InMemKeystore::new_insecure_for_tests(10);
87-
88-
let rt: Runtime = Runtime::new().unwrap();
89-
let (rpc_service, aggregate_service) =
90-
rt.block_on(async { setup_service(&tempdir, &keystore).await.unwrap() });
91-
let rooch_server = RoochServer::new(rpc_service.clone(), aggregate_service);
92-
93-
let default_account = keystore.addresses()[0];
94-
let mut test_transaction_builder = TestTransactionBuilder::new(default_account.into());
95-
let tx = create_publish_transaction(&test_transaction_builder, &keystore).unwrap();
96-
let _publish_result = rt.block_on(async { rpc_service.execute_tx(tx).await.unwrap() });
97-
//
98-
for n in 1..500 {
99-
let tx = create_transaction(&mut test_transaction_builder, &keystore, n).unwrap();
100-
let _ = rt.block_on(async { rpc_service.execute_tx(tx).await.unwrap() });
101-
}
102-
103-
let mut tx_orders = (1..500).cycle().map(|v| v);
104-
c.bench_function("get_transactions_by_order", |b| {
105-
b.to_async(Runtime::new().unwrap()).iter(|| {
106-
rooch_server.get_transactions_by_order(
107-
Some(StrView(tx_orders.next().unwrap())),
108-
None,
109-
None,
110-
)
111-
})
112-
});
113-
}
114-
115-
async fn setup_service(
49+
pub async fn setup_service(
11650
datadir: &DataDirPath,
11751
keystore: &InMemKeystore,
11852
) -> Result<(RpcService, AggregateService)> {
@@ -218,7 +152,7 @@ async fn setup_service(
218152
Ok((rpc_service, aggregate_service))
219153
}
220154

221-
fn init_storage(datadir: &DataDirPath) -> Result<(MoveOSStore, RoochStore)> {
155+
pub fn init_storage(datadir: &DataDirPath) -> Result<(MoveOSStore, RoochStore)> {
222156
let (rooch_db_path, moveos_db_path) = (
223157
StoreConfig::get_mock_rooch_store_dir(datadir),
224158
StoreConfig::get_mock_moveos_store_dir(datadir),
@@ -248,7 +182,7 @@ fn init_storage(datadir: &DataDirPath) -> Result<(MoveOSStore, RoochStore)> {
248182
Ok((moveos_store, rooch_store))
249183
}
250184

251-
fn init_indexer(datadir: &DataDirPath) -> Result<(IndexerStore, IndexerReader)> {
185+
pub fn init_indexer(datadir: &DataDirPath) -> Result<(IndexerStore, IndexerReader)> {
252186
let indexer_db_path = IndexerConfig::get_mock_indexer_db(datadir);
253187
let indexer_db_parent_dir = indexer_db_path
254188
.parent()
@@ -269,7 +203,7 @@ fn init_indexer(datadir: &DataDirPath) -> Result<(IndexerStore, IndexerReader)>
269203
Ok((indexer_store, indexer_reader))
270204
}
271205

272-
fn create_publish_transaction(
206+
pub fn create_publish_transaction(
273207
test_transaction_builder: &TestTransactionBuilder,
274208
keystore: &InMemKeystore,
275209
) -> Result<TypedTransaction> {
@@ -283,7 +217,7 @@ fn create_publish_transaction(
283217
Ok(TypedTransaction::Rooch(rooch_tx))
284218
}
285219

286-
fn create_transaction(
220+
pub fn create_transaction(
287221
test_transaction_builder: &mut TestTransactionBuilder,
288222
keystore: &InMemKeystore,
289223
sequence_number: u64,
@@ -296,12 +230,3 @@ fn create_transaction(
296230
keystore.sign_transaction(&test_transaction_builder.sender.into(), tx_data, None)?;
297231
Ok(TypedTransaction::Rooch(rooch_tx))
298232
}
299-
300-
criterion_group! {
301-
name = rooch_transaction_benches;
302-
config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(10));
303-
// config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(10))
304-
// .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
305-
targets = transaction_write_benchmark, transaction_query_benchmark
306-
}
307-
criterion_main!(rooch_transaction_benches);

0 commit comments

Comments
 (0)