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
32    });
33
34    let mut ctx = BenchmarkContext::new(workload.clone(), component, print_sample_tx).await;
35    let tx_generator = workload.create_tx_generator(&mut ctx).await;
36    let transactions = ctx.generate_transactions(tx_generator).await;
37
38    // No consensus in single node benchmark so we do not need to go through
39    // the certification process before assigning shared object versions.
40    let assigned_versions = ctx
41        .validator()
42        .assigned_shared_object_versions(&transactions)
43        .await;
44
45    match component {
46        Component::CheckpointExecutor => {
47            ctx.benchmark_checkpoint_executor(transactions, assigned_versions, checkpoint_size)
48                .await;
49        }
50        Component::ExecutionOnly => {
51            ctx.benchmark_transaction_execution_in_memory(
52                transactions,
53                assigned_versions,
54                print_sample_tx,
55            )
56            .await;
57        }
58        _ => {
59            ctx.benchmark_transaction_execution(transactions, assigned_versions, print_sample_tx)
60                .await;
61        }
62    }
63}