sui_aws_orchestrator/protocol/
mod.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::path::PathBuf;
5
6use crate::{
7    benchmark::{BenchmarkParameters, BenchmarkType},
8    client::Instance,
9};
10
11pub mod narwhal;
12pub mod sui;
13
14/// The minimum interface that the protocol should implement to allow benchmarks from
15/// the orchestrator.
16pub trait ProtocolCommands<T: BenchmarkType> {
17    /// The list of dependencies to install (e.g., through apt-get).
18    fn protocol_dependencies(&self) -> Vec<&'static str>;
19
20    /// The directories of all databases (that should be erased before each run).
21    fn db_directories(&self) -> Vec<PathBuf>;
22
23    /// The command to generate the genesis and all configuration files. This command
24    /// is run on each remote machine.
25    fn genesis_command<'a, I>(&self, instances: I) -> String
26    where
27        I: Iterator<Item = &'a Instance>;
28
29    /// The command to run a node. The function returns a vector of commands along with the
30    /// associated instance on which to run the command.
31    fn node_command<I>(
32        &self,
33        instances: I,
34        parameters: &BenchmarkParameters<T>,
35    ) -> Vec<(Instance, String)>
36    where
37        I: IntoIterator<Item = Instance>;
38
39    fn monitor_command<I>(&self, instances: I) -> Vec<(Instance, String)>
40    where
41        I: IntoIterator<Item = Instance>;
42
43    /// The command to run a client. The function returns a vector of commands along with the
44    /// associated instance on which to run the command.
45    fn client_command<I>(
46        &self,
47        instances: I,
48        parameters: &BenchmarkParameters<T>,
49    ) -> Vec<(Instance, String)>
50    where
51        I: IntoIterator<Item = Instance>;
52}
53
54/// The names of the minimum metrics exposed by the load generators that are required to
55/// compute performance.
56pub trait ProtocolMetrics {
57    /// The name of the metric reporting the total duration of the benchmark (in seconds).
58    const BENCHMARK_DURATION: &'static str;
59    /// The name of the metric reporting the total number of finalized transactions
60    const TOTAL_TRANSACTIONS: &'static str;
61    /// The name of the metric reporting the latency buckets.
62    const LATENCY_BUCKETS: &'static str;
63    /// The name of the metric reporting the sum of the end-to-end latency of all finalized
64    /// transactions.
65    const LATENCY_SUM: &'static str;
66    /// The name of the metric reporting the square of the sum of the end-to-end latency of all
67    /// finalized transactions.
68    const LATENCY_SQUARED_SUM: &'static str;
69
70    /// The network path where the nodes expose prometheus metrics.
71    fn nodes_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
72    where
73        I: IntoIterator<Item = Instance>;
74    /// The command to retrieve the metrics from the nodes.
75    fn nodes_metrics_command<I>(&self, instances: I) -> Vec<(Instance, String)>
76    where
77        I: IntoIterator<Item = Instance>,
78    {
79        self.nodes_metrics_path(instances)
80            .into_iter()
81            .map(|(instance, path)| (instance, format!("curl {path}")))
82            .collect()
83    }
84
85    /// The network path where the clients expose prometheus metrics.
86    fn clients_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
87    where
88        I: IntoIterator<Item = Instance>;
89    /// The command to retrieve the metrics from the clients.
90    fn clients_metrics_command<I>(&self, instances: I) -> Vec<(Instance, String)>
91    where
92        I: IntoIterator<Item = Instance>,
93    {
94        self.clients_metrics_path(instances)
95            .into_iter()
96            .map(|(instance, path)| (instance, format!("curl {path}")))
97            .collect()
98    }
99}
100
101#[cfg(test)]
102pub mod test_protocol_metrics {
103    use crate::client::Instance;
104
105    use super::ProtocolMetrics;
106
107    pub struct TestProtocolMetrics;
108
109    impl ProtocolMetrics for TestProtocolMetrics {
110        const BENCHMARK_DURATION: &'static str = "benchmark_duration";
111        const TOTAL_TRANSACTIONS: &'static str = "latency_s_count";
112        const LATENCY_BUCKETS: &'static str = "latency_s";
113        const LATENCY_SUM: &'static str = "latency_s_sum";
114        const LATENCY_SQUARED_SUM: &'static str = "latency_squared_s";
115
116        fn nodes_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
117        where
118            I: IntoIterator<Item = Instance>,
119        {
120            instances
121                .into_iter()
122                .enumerate()
123                .map(|(i, instance)| (instance, format!("localhost:{}/metrics", 8000 + i as u16)))
124                .collect()
125        }
126
127        fn clients_metrics_path<I>(&self, instances: I) -> Vec<(Instance, String)>
128        where
129            I: IntoIterator<Item = Instance>,
130        {
131            instances
132                .into_iter()
133                .enumerate()
134                .map(|(i, instance)| (instance, format!("localhost:{}/metrics", 9000 + i as u16)))
135                .collect()
136        }
137    }
138}