2019-10-01 09:38:29 -07:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
use rand::{thread_rng, Rng};
|
2020-06-03 08:24:05 -07:00
|
|
|
use solana_core::broadcast_stage::broadcast_metrics::TransmitShredsStats;
|
2020-04-06 17:36:22 -07:00
|
|
|
use solana_core::broadcast_stage::{broadcast_shreds, get_broadcast_peers};
|
2019-10-01 09:38:29 -07:00
|
|
|
use solana_core::cluster_info::{ClusterInfo, Node};
|
|
|
|
use solana_core::contact_info::ContactInfo;
|
2020-04-06 17:36:22 -07:00
|
|
|
use solana_ledger::shred::Shred;
|
2020-10-19 12:23:14 -07:00
|
|
|
use solana_sdk::pubkey;
|
2019-10-01 09:38:29 -07:00
|
|
|
use solana_sdk::timing::timestamp;
|
2020-04-14 21:21:58 -07:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
net::UdpSocket,
|
|
|
|
sync::{atomic::AtomicU64, Arc},
|
|
|
|
};
|
2019-10-01 09:38:29 -07:00
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn broadcast_shreds_bench(bencher: &mut Bencher) {
|
|
|
|
solana_logger::setup();
|
2020-10-19 12:23:14 -07:00
|
|
|
let leader_pubkey = pubkey::new_rand();
|
2019-10-01 09:38:29 -07:00
|
|
|
let leader_info = Node::new_localhost_with_pubkey(&leader_pubkey);
|
2020-06-08 17:38:14 -07:00
|
|
|
let cluster_info = ClusterInfo::new_with_invalid_keypair(leader_info.info);
|
2019-10-01 09:38:29 -07:00
|
|
|
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
|
|
|
|
|
|
|
const NUM_SHREDS: usize = 32;
|
2020-04-06 17:36:22 -07:00
|
|
|
let shreds = vec![Shred::new_empty_data_shred(); NUM_SHREDS];
|
2019-10-01 09:38:29 -07:00
|
|
|
let mut stakes = HashMap::new();
|
|
|
|
const NUM_PEERS: usize = 200;
|
|
|
|
for _ in 0..NUM_PEERS {
|
2020-10-19 12:23:14 -07:00
|
|
|
let id = pubkey::new_rand();
|
2019-10-01 09:38:29 -07:00
|
|
|
let contact_info = ContactInfo::new_localhost(&id, timestamp());
|
|
|
|
cluster_info.insert_info(contact_info);
|
|
|
|
stakes.insert(id, thread_rng().gen_range(1, NUM_PEERS) as u64);
|
|
|
|
}
|
2020-04-21 12:54:45 -07:00
|
|
|
let cluster_info = Arc::new(cluster_info);
|
2021-01-24 13:15:09 -08:00
|
|
|
let (peers, peers_and_stakes) = get_broadcast_peers(&cluster_info, Some(&stakes));
|
2020-04-06 17:36:22 -07:00
|
|
|
let shreds = Arc::new(shreds);
|
2020-04-14 21:21:58 -07:00
|
|
|
let last_datapoint = Arc::new(AtomicU64::new(0));
|
2019-10-01 09:38:29 -07:00
|
|
|
bencher.iter(move || {
|
2019-10-10 19:38:48 -07:00
|
|
|
let shreds = shreds.clone();
|
2020-04-06 17:36:22 -07:00
|
|
|
broadcast_shreds(
|
|
|
|
&socket,
|
|
|
|
&shreds,
|
|
|
|
&peers_and_stakes,
|
|
|
|
&peers,
|
2020-04-14 21:21:58 -07:00
|
|
|
&last_datapoint,
|
2020-06-03 08:24:05 -07:00
|
|
|
&mut TransmitShredsStats::default(),
|
2020-04-06 17:36:22 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
2019-10-01 09:38:29 -07:00
|
|
|
});
|
|
|
|
}
|