Skip to content

Commit

Permalink
Simulator network configuration and stress test (#4677)
Browse files Browse the repository at this point in the history
* Update msim pointer

* Every test invocation gets a fresh TMPDIR

* Make sui-macros more self-contained

* Basic network configurations

* Run stress test in simulator

* Increase default gas amount to support stress test

* ctrl_c not supported in simulator

* Assert 0 errors during stress test
  • Loading branch information
mystenmark committed Sep 23, 2022
1 parent 79cc151 commit bbaafa2
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 170 deletions.
9 changes: 7 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/sui-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ narwhal-node = { git = "https://github.com/MystenLabs/narwhal", rev = "9d667b470
workspace-hack = { path = "../workspace-hack"}
test-utils = { path = "../test-utils" }

[target.'cfg(msim)'.dependencies]
sui-macros = { path = "../sui-macros" }
sui-simulator = { path = "../sui-simulator" }

[features]
benchmark = ["narwhal-node/benchmark"]
134 changes: 9 additions & 125 deletions crates/sui-benchmark/src/bin/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use futures::future::try_join_all;
use futures::StreamExt;
use prometheus::Registry;
use rand::seq::SliceRandom;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -17,14 +16,11 @@ use sui_benchmark::drivers::driver::Driver;
use sui_benchmark::drivers::BenchmarkCmp;
use sui_benchmark::drivers::BenchmarkStats;
use sui_benchmark::drivers::Interval;
use sui_benchmark::workloads::shared_counter::SharedCounterWorkload;
use sui_benchmark::workloads::transfer_object::TransferObjectWorkload;
use sui_benchmark::util::get_ed25519_keypair_from_keystore;
use sui_benchmark::workloads::workload::get_latest;
use sui_benchmark::workloads::workload::CombinationWorkload;
use sui_benchmark::workloads::workload::Payload;
use sui_benchmark::workloads::workload::Workload;
use sui_benchmark::workloads::workload::WorkloadInfo;
use sui_benchmark::workloads::workload::WorkloadType;
use sui_benchmark::workloads::{
make_combination_workload, make_shared_counter_workload, make_transfer_object_workload,
};
use sui_config::gateway::GatewayConfig;
use sui_config::Config;
use sui_config::PersistedConfig;
Expand All @@ -37,13 +33,10 @@ use sui_core::gateway_state::GatewayState;
use sui_core::safe_client::SafeClientMetrics;
use sui_node::metrics;
use sui_node::SuiNode;
use sui_sdk::crypto::FileBasedKeystore;
use sui_types::base_types::ObjectID;
use sui_types::base_types::SuiAddress;
use sui_types::batch::UpdateItem;
use sui_types::crypto::AccountKeyPair;
use sui_types::crypto::EncodeDecodeBase64;
use sui_types::crypto::SuiKeyPair;
use sui_types::messages::BatchInfoRequest;
use sui_types::messages::BatchInfoResponseItem;
use sui_types::messages::TransactionInfoRequest;
Expand Down Expand Up @@ -225,103 +218,6 @@ pub async fn follow(authority_client: NetworkAuthorityClient, download_txes: boo
});
}

fn make_combination_workload(
target_qps: u64,
num_workers: u64,
in_flight_ratio: u64,
primary_gas_id: ObjectID,
primary_gas_account_owner: SuiAddress,
primary_gas_account_keypair: Arc<AccountKeyPair>,
opts: &Opts,
) -> WorkloadInfo {
let mut workloads = HashMap::<WorkloadType, (u32, Box<dyn Workload<dyn Payload>>)>::new();
match opts.run_spec {
RunSpec::Bench {
shared_counter,
transfer_object,
..
} => {
if shared_counter > 0 {
let workload = SharedCounterWorkload::new_boxed(
primary_gas_id,
primary_gas_account_owner,
primary_gas_account_keypair.clone(),
None,
);
workloads
.entry(WorkloadType::SharedCounter)
.or_insert((shared_counter, workload));
}
if transfer_object > 0 {
let workload = TransferObjectWorkload::new_boxed(
opts.num_transfer_accounts,
primary_gas_id,
primary_gas_account_owner,
primary_gas_account_keypair,
);
workloads
.entry(WorkloadType::TransferObject)
.or_insert((transfer_object, workload));
}
}
}
let workload = CombinationWorkload::new_boxed(workloads);
WorkloadInfo {
target_qps,
num_workers,
max_in_flight_ops: in_flight_ratio * target_qps,
workload,
}
}

fn make_shared_counter_workload(
target_qps: u64,
num_workers: u64,
max_in_flight_ops: u64,
primary_gas_id: ObjectID,
owner: SuiAddress,
keypair: Arc<AccountKeyPair>,
) -> Option<WorkloadInfo> {
if target_qps == 0 || max_in_flight_ops == 0 || num_workers == 0 {
None
} else {
let workload = SharedCounterWorkload::new_boxed(primary_gas_id, owner, keypair, None);
Some(WorkloadInfo {
target_qps,
num_workers,
max_in_flight_ops,
workload,
})
}
}

fn make_transfer_object_workload(
target_qps: u64,
num_workers: u64,
max_in_flight_ops: u64,
num_transfer_accounts: u64,
primary_gas_id: &ObjectID,
owner: SuiAddress,
keypair: Arc<AccountKeyPair>,
) -> Option<WorkloadInfo> {
if target_qps == 0 || max_in_flight_ops == 0 || num_workers == 0 {
None
} else {
let workload = TransferObjectWorkload::new_boxed(
num_transfer_accounts,
*primary_gas_id,
owner,
keypair,
);
Some(WorkloadInfo {
target_qps,
num_workers,
max_in_flight_ops,
workload,
})
}
}

/// To spin up a local cluster and direct some load
/// at it with 50/50 shared and owned traffic, use
/// it something like:
Expand Down Expand Up @@ -478,22 +374,8 @@ async fn main() -> Result<()> {
&opts.keystore_path
))
})?;
let keystore = FileBasedKeystore::load_or_create(&keystore_path)?;
let keypair = keystore
.key_pairs()
.iter()
.find(|x| {
let address: SuiAddress = Into::<SuiAddress>::into(&x.public());
address == primary_gas_account
})
.map(|x| x.encode_base64())
.unwrap();
// TODO(joyqvq): This is a hack to decode base64 keypair with added flag, ok for now since it is for benchmark use.
// Rework to get the typed keypair directly from above.
let ed25519_keypair = match SuiKeyPair::decode_base64(&keypair).unwrap() {
SuiKeyPair::Ed25519SuiKeyPair(x) => x,
_ => panic!("Unexpected keypair type"),
};
let ed25519_keypair =
get_ed25519_keypair_from_keystore(keystore_path, &primary_gas_account)?;
(
*primary_gas_id,
primary_gas_account,
Expand Down Expand Up @@ -550,7 +432,9 @@ async fn main() -> Result<()> {
primary_gas_id,
owner,
keypair,
&opts,
opts.num_transfer_accounts,
shared_counter,
transfer_object,
);
combination_workload.workload.init(&aggregator).await;
vec![combination_workload]
Expand Down
13 changes: 12 additions & 1 deletion crates/sui-benchmark/src/drivers/bench_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ impl BenchDriver {
}
}

#[cfg(not(msim))]
async fn ctrl_c() -> std::io::Result<()> {
tokio::signal::ctrl_c().await
}

// TODO: if more use is made of tokio::signal we should just add support for it to the sim.
#[cfg(msim)]
async fn ctrl_c() -> std::io::Result<()> {
futures::future::pending().await
}

#[async_trait]
impl Driver<BenchmarkStats> for BenchDriver {
async fn run(
Expand Down Expand Up @@ -524,7 +535,7 @@ impl Driver<BenchmarkStats> for BenchDriver {
drop(tx);
let all_tasks = try_join_all(tasks);
let _res = tokio::select! {
_ = tokio::signal::ctrl_c() => {
_ = ctrl_c() => {
self.terminate();
vec![]
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// SPDX-License-Identifier: Apache-2.0

pub mod drivers;
pub mod util;
pub mod workloads;
33 changes: 33 additions & 0 deletions crates/sui-benchmark/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use sui_sdk::crypto::FileBasedKeystore;
use sui_types::{
base_types::SuiAddress,
crypto::{AccountKeyPair, EncodeDecodeBase64, SuiKeyPair},
};

use std::path::PathBuf;

pub fn get_ed25519_keypair_from_keystore(
keystore_path: PathBuf,
requested_address: &SuiAddress,
) -> Result<AccountKeyPair> {
let keystore = FileBasedKeystore::load_or_create(&keystore_path)?;
let keypair = keystore
.key_pairs()
.iter()
.find(|x| {
let address: SuiAddress = Into::<SuiAddress>::into(&x.public());
address == *requested_address
})
.map(|x| x.encode_base64())
.unwrap();
// TODO(joyqvq): This is a hack to decode base64 keypair with added flag, ok for now since it is for benchmark use.
// Rework to get the typed keypair directly from above.
Ok(match SuiKeyPair::decode_base64(&keypair).unwrap() {
SuiKeyPair::Ed25519SuiKeyPair(x) => x,
_ => panic!("Unexpected keypair type"),
})
}
Loading

0 comments on commit bbaafa2

Please sign in to comment.