sui_single_node_benchmark/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::benchmark_context::BenchmarkContext;
5use crate::command::Component;
6use crate::workload::Workload;
7use sui_protocol_config::ProtocolConfig;
8
9pub(crate) mod benchmark_context;
10pub mod command;
11pub(crate) mod mock_account;
12pub(crate) mod mock_storage;
13pub(crate) mod single_node;
14pub(crate) mod tx_generator;
15pub mod workload;
16
17/// Benchmark a given workload on a specified component.
18/// The different kinds of workloads and components can be found in command.rs.
19/// \checkpoint_size represents both the size of a consensus commit, and size of a checkpoint
20/// if we are benchmarking the checkpoint.
21pub async fn run_benchmark(
22    workload: Workload,
23    component: Component,
24    checkpoint_size: usize,
25    print_sample_tx: bool,
26) {
27    // This benchmark uses certify_transactions (QD path) which requires
28    // disable_preconsensus_locking=false for signed transaction storage.
29    let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
30        config.set_disable_preconsensus_locking_for_testing(false);
31        config.set_address_aliases_for_testing(false);
32        config
33    });
34
35    let mut ctx = BenchmarkContext::new(workload.clone(), component, print_sample_tx).await;
36    let tx_generator = workload.create_tx_generator(&mut ctx).await;
37    let transactions = ctx.generate_transactions(tx_generator).await;
38
39    // No consensus in single node benchmark so we do not need to go through
40    // the certification process before assigning shared object versions.
41    let assigned_versions = ctx
42        .validator()
43        .assigned_shared_object_versions(&transactions)
44        .await;
45
46    match component {
47        Component::CheckpointExecutor => {
48            ctx.benchmark_checkpoint_executor(transactions, assigned_versions, checkpoint_size)
49                .await;
50        }
51        Component::ExecutionOnly => {
52            ctx.benchmark_transaction_execution_in_memory(
53                transactions,
54                assigned_versions,
55                print_sample_tx,
56            )
57            .await;
58        }
59        _ => {
60            ctx.benchmark_transaction_execution(transactions, assigned_versions, print_sample_tx)
61                .await;
62        }
63    }
64}