2019-10-06 12:56:17 -07:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate solana_core;
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
use log::*;
|
|
|
|
use solana_core::cluster_info::{ClusterInfo, Node};
|
|
|
|
use solana_core::contact_info::ContactInfo;
|
2019-10-10 13:24:03 -07:00
|
|
|
use solana_core::retransmit_stage::retransmitter;
|
2019-10-20 08:54:38 -07:00
|
|
|
use solana_ledger::bank_forks::BankForks;
|
2020-03-21 10:54:40 -07:00
|
|
|
use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo};
|
2019-10-18 09:28:51 -07:00
|
|
|
use solana_ledger::leader_schedule_cache::LeaderScheduleCache;
|
2019-10-10 13:24:03 -07:00
|
|
|
use solana_measure::measure::Measure;
|
2020-03-17 23:30:23 -07:00
|
|
|
use solana_perf::packet::to_packets_chunked;
|
2019-11-06 10:52:30 -08:00
|
|
|
use solana_perf::test_tx::test_tx;
|
2019-10-06 12:56:17 -07:00
|
|
|
use solana_runtime::bank::Bank;
|
|
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
use solana_sdk::timing::timestamp;
|
|
|
|
use std::net::UdpSocket;
|
2019-10-10 13:24:03 -07:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
2019-10-06 12:56:17 -07:00
|
|
|
use std::sync::mpsc::channel;
|
2019-10-10 13:24:03 -07:00
|
|
|
use std::sync::Mutex;
|
2019-10-06 12:56:17 -07:00
|
|
|
use std::sync::{Arc, RwLock};
|
2019-10-10 13:24:03 -07:00
|
|
|
use std::thread::sleep;
|
|
|
|
use std::thread::Builder;
|
|
|
|
use std::time::Duration;
|
2019-10-06 12:56:17 -07:00
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-10 13:24:03 -07:00
|
|
|
fn bench_retransmitter(bencher: &mut Bencher) {
|
2019-10-06 12:56:17 -07:00
|
|
|
solana_logger::setup();
|
|
|
|
let mut cluster_info = ClusterInfo::new_with_invalid_keypair(Node::new_localhost().info);
|
2019-10-10 13:24:03 -07:00
|
|
|
const NUM_PEERS: usize = 4;
|
|
|
|
let mut peer_sockets = Vec::new();
|
2019-10-06 12:56:17 -07:00
|
|
|
for _ in 0..NUM_PEERS {
|
|
|
|
let id = Pubkey::new_rand();
|
2019-10-10 13:24:03 -07:00
|
|
|
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
|
|
|
let mut contact_info = ContactInfo::new_localhost(&id, timestamp());
|
|
|
|
contact_info.tvu = socket.local_addr().unwrap();
|
|
|
|
contact_info.tvu.set_ip("127.0.0.1".parse().unwrap());
|
|
|
|
contact_info.tvu_forwards = contact_info.tvu;
|
|
|
|
info!("local: {:?}", contact_info.tvu);
|
2019-10-06 12:56:17 -07:00
|
|
|
cluster_info.insert_info(contact_info);
|
2019-10-10 13:24:03 -07:00
|
|
|
socket.set_nonblocking(true).unwrap();
|
|
|
|
peer_sockets.push(socket);
|
2019-10-06 12:56:17 -07:00
|
|
|
}
|
2019-10-10 13:24:03 -07:00
|
|
|
let peer_sockets = Arc::new(peer_sockets);
|
2019-10-06 12:56:17 -07:00
|
|
|
let cluster_info = Arc::new(RwLock::new(cluster_info));
|
|
|
|
|
2019-11-08 20:56:57 -08:00
|
|
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100_000);
|
|
|
|
let bank0 = Bank::new(&genesis_config);
|
2019-10-06 12:56:17 -07:00
|
|
|
let bank_forks = BankForks::new(0, bank0);
|
|
|
|
let bank = bank_forks.working_bank();
|
|
|
|
let bank_forks = Arc::new(RwLock::new(bank_forks));
|
|
|
|
let (packet_sender, packet_receiver) = channel();
|
2019-10-10 13:24:03 -07:00
|
|
|
let packet_receiver = Arc::new(Mutex::new(packet_receiver));
|
|
|
|
const NUM_THREADS: usize = 2;
|
|
|
|
let sockets = (0..NUM_THREADS)
|
|
|
|
.map(|_| UdpSocket::bind("0.0.0.0:0").unwrap())
|
|
|
|
.collect();
|
2019-10-06 12:56:17 -07:00
|
|
|
|
|
|
|
let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank));
|
|
|
|
|
2019-10-10 13:24:03 -07:00
|
|
|
// To work reliably with higher values, this needs larger udp rmem size
|
2019-10-06 12:56:17 -07:00
|
|
|
let tx = test_tx();
|
2019-10-10 13:24:03 -07:00
|
|
|
const NUM_PACKETS: usize = 50;
|
|
|
|
let chunk_size = NUM_PACKETS / (4 * NUM_THREADS);
|
|
|
|
let batches = to_packets_chunked(&vec![tx; NUM_PACKETS], chunk_size);
|
|
|
|
info!("batches: {}", batches.len());
|
2019-10-06 12:56:17 -07:00
|
|
|
|
2019-10-10 13:24:03 -07:00
|
|
|
let retransmitter_handles = retransmitter(
|
|
|
|
Arc::new(sockets),
|
|
|
|
bank_forks,
|
|
|
|
&leader_schedule_cache,
|
|
|
|
cluster_info,
|
|
|
|
packet_receiver,
|
|
|
|
);
|
|
|
|
|
|
|
|
let total = Arc::new(AtomicUsize::new(0));
|
2019-10-06 12:56:17 -07:00
|
|
|
bencher.iter(move || {
|
2019-10-10 13:24:03 -07:00
|
|
|
let peer_sockets1 = peer_sockets.clone();
|
|
|
|
let handles: Vec<_> = (0..NUM_PEERS)
|
|
|
|
.into_iter()
|
|
|
|
.map(|p| {
|
|
|
|
let peer_sockets2 = peer_sockets1.clone();
|
|
|
|
let total2 = total.clone();
|
|
|
|
Builder::new()
|
|
|
|
.name("recv".to_string())
|
|
|
|
.spawn(move || {
|
|
|
|
info!("{} waiting on {:?}", p, peer_sockets2[p]);
|
|
|
|
let mut buf = [0u8; 1024];
|
|
|
|
loop {
|
|
|
|
while peer_sockets2[p].recv(&mut buf).is_ok() {
|
|
|
|
total2.fetch_add(1, Ordering::Relaxed);
|
|
|
|
}
|
|
|
|
if total2.load(Ordering::Relaxed) >= NUM_PACKETS {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
info!("{} recv", total2.load(Ordering::Relaxed));
|
|
|
|
sleep(Duration::from_millis(1));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
2019-10-06 12:56:17 -07:00
|
|
|
for packets in batches.clone() {
|
|
|
|
packet_sender.send(packets).unwrap();
|
|
|
|
}
|
|
|
|
info!("sent...");
|
2019-10-10 13:24:03 -07:00
|
|
|
|
|
|
|
let mut join_time = Measure::start("join");
|
|
|
|
for h in handles {
|
|
|
|
h.join().unwrap();
|
|
|
|
}
|
|
|
|
join_time.stop();
|
|
|
|
info!("took: {}ms", join_time.as_ms());
|
|
|
|
|
|
|
|
total.store(0, Ordering::Relaxed);
|
2019-10-06 12:56:17 -07:00
|
|
|
});
|
2019-10-10 13:24:03 -07:00
|
|
|
|
|
|
|
for t in retransmitter_handles {
|
|
|
|
t.join().unwrap();
|
|
|
|
}
|
2019-10-06 12:56:17 -07:00
|
|
|
}
|