sui_single_node_benchmark/
command.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use clap::{Parser, Subcommand, ValueEnum};
5use std::path::PathBuf;
6use strum_macros::EnumIter;
7
8#[derive(Parser)]
9#[clap(
10    name = "sui-single-node-benchmark",
11    about = "Benchmark a single validator node",
12    rename_all = "kebab-case",
13    author,
14    version
15)]
16pub struct Command {
17    #[arg(
18        long,
19        default_value_t = 500000,
20        help = "Number of transactions to submit"
21    )]
22    pub tx_count: u64,
23    #[arg(
24        long,
25        default_value_t = 100,
26        help = "Number of transactions in a consensus commit/checkpoint"
27    )]
28    pub checkpoint_size: usize,
29    #[arg(
30        long,
31        help = "Whether to print out a sample transaction and effects that is going to be benchmarked on"
32    )]
33    pub print_sample_tx: bool,
34    #[arg(
35        long,
36        default_value_t = false,
37        help = "If true, skip signing on the validators, instead, creating certificates directly using validator secrets"
38    )]
39    pub skip_signing: bool,
40    #[arg(
41        long,
42        default_value = "baseline",
43        ignore_case = true,
44        help = "Which component to benchmark"
45    )]
46    pub component: Component,
47    #[clap(subcommand)]
48    pub workload: WorkloadKind,
49}
50
51#[derive(Copy, Clone, EnumIter, ValueEnum)]
52pub enum Component {
53    ExecutionOnly,
54    /// Baseline includes the execution and storage layer only.
55    Baseline,
56    /// On top of Baseline, this schedules transactions through the transaction manager.
57    WithTxManager,
58    /// This goes through the `handle_certificate` entry point on authority_server, which includes
59    /// certificate verification, transaction manager, as well as a noop consensus layer. The noop
60    /// consensus layer does absolutely nothing when receiving a transaction in consensus.
61    ValidatorWithoutConsensus,
62    /// Similar to ValidatorWithNoopConsensus, but the consensus layer contains a fake consensus
63    /// protocol that basically sequences transactions in order. It then verify the transaction
64    /// and store the sequenced transactions into the store. It covers the consensus-independent
65    /// portion of the code in consensus handler.
66    ValidatorWithFakeConsensus,
67    /// Benchmark only validator signing component: `handle_transaction`.
68    TxnSigning,
69    /// Benchmark the checkpoint executor by constructing a full epoch of checkpoints, execute
70    /// all transactions in them and measure time.
71    CheckpointExecutor,
72}
73
74#[derive(Subcommand, Clone)]
75pub enum WorkloadKind {
76    PTB {
77        #[arg(
78            long,
79            default_value_t = 0,
80            help = "Number of address owned input objects per transaction.\
81                This represents the amount of DB reads per transaction prior to execution."
82        )]
83        num_transfers: u64,
84        #[arg(
85            long,
86            default_value_t = false,
87            help = "When transferring an object, whether to use native TransferObjecet command, or to use Move code for the transfer"
88        )]
89        use_native_transfer: bool,
90        #[arg(
91            long,
92            default_value_t = 0,
93            help = "Number of dynamic fields read per transaction.\
94            This represents the amount of runtime DB reads per transaction during execution."
95        )]
96        num_dynamic_fields: u64,
97        #[arg(
98            long,
99            default_value_t = 0,
100            help = "Computation intensity per transaction.\
101            The transaction computes the n-th Fibonacci number \
102            specified by this parameter * 100."
103        )]
104        computation: u8,
105        #[arg(
106            long,
107            default_value_t = 0,
108            help = "Whether to use shared objects in the transaction.\
109            If 0, no shared objects will be used.\
110            Otherwise `v` shared objects will be created and each transaction will use these `v` shared objects."
111        )]
112        num_shared_objects: usize,
113        #[arg(
114            long,
115            default_value_t = 0,
116            help = "How many NFTs to mint/transfer during the transaction.\
117            If 0, no NFTs will be minted.\
118            Otherwise `v` NFTs with the specified size will be created and transferred to the sender"
119        )]
120        num_mints: u16,
121        #[arg(
122            long,
123            default_value_t = 32,
124            help = "Size of the Move contents of the NFT to be minted, in bytes.\
125            Defaults to 32 bytes (i.e., NFT with ID only)."
126        )]
127        nft_size: u16,
128        #[arg(
129            long,
130            help = "If true, call a single batch_mint Move function.\
131            Otherwise, batch via a PTB with multiple commands"
132        )]
133        use_batch_mint: bool,
134    },
135    Publish {
136        #[arg(
137            long,
138            help = "Path to the manifest file that describe the package dependencies.\
139            Follow examples in the tests directory to see how to set up the manifest file.\
140            The manifest file is a json file that contains a list of dependent packages that need to\
141            be published first, as well as the root package that will be benchmarked on. Each package\
142            can be either in source code or bytecode form. If it is in source code form, the benchmark\
143            will compile the package first before publishing it."
144        )]
145        manifest_file: PathBuf,
146    },
147}
148
149impl WorkloadKind {
150    pub(crate) fn gas_object_num_per_account(&self) -> u64 {
151        match self {
152            // Each transaction will always have 1 gas object, plus the number of owned objects that will be transferred.
153            WorkloadKind::PTB { num_transfers, .. } => *num_transfers + 1,
154            WorkloadKind::Publish { .. } => 1,
155        }
156    }
157}