bencher: change to account for new aquatic_udp implementation

This commit is contained in:
Joakim Frostegård 2024-02-10 18:51:13 +01:00
parent 358c8951c0
commit 2c7bcf71ad
4 changed files with 33 additions and 36 deletions

View file

@ -94,11 +94,11 @@ pub struct State {
pub server_start_instant: ServerStartInstant,
}
impl State {
pub fn new(config: &Config) -> Self {
impl Default for State {
fn default() -> Self {
Self {
access_list: Arc::new(AccessListArcSwap::default()),
torrent_maps: TorrentMaps::new(config),
torrent_maps: TorrentMaps::default(),
server_start_instant: ServerStartInstant::new(),
}
}

View file

@ -25,7 +25,7 @@ pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn run(config: Config) -> ::anyhow::Result<()> {
let mut signals = Signals::new([SIGUSR1])?;
let state = State::new(&config);
let state = State::default();
let statistics = Statistics::new(&config);
let connection_validator = ConnectionValidator::new(&config)?;
let priv_dropper = PrivilegeDropper::new(config.privileges.clone(), config.socket_workers);

View file

@ -16,6 +16,7 @@ use aquatic_common::{CanonicalSocketAddr, IndexMap};
use aquatic_udp_protocol::*;
use arrayvec::ArrayVec;
use crossbeam_channel::Sender;
use hashbrown::HashMap;
use hdrhistogram::Histogram;
use parking_lot::RwLockUpgradableReadGuard;
use rand::prelude::SmallRng;
@ -29,24 +30,24 @@ const SMALL_PEER_MAP_CAPACITY: usize = 2;
use aquatic_udp_protocol::InfoHash;
use parking_lot::RwLock;
type TorrentMapShard<T> = IndexMap<InfoHash, Arc<TorrentData<T>>>;
#[derive(Clone)]
pub struct TorrentMaps {
ipv4: TorrentMapShards<Ipv4AddrBytes>,
ipv6: TorrentMapShards<Ipv6AddrBytes>,
}
impl TorrentMaps {
pub fn new(config: &Config) -> Self {
let num_shards = 16usize;
impl Default for TorrentMaps {
fn default() -> Self {
const NUM_SHARDS: usize = 16;
Self {
ipv4: TorrentMapShards::new(num_shards),
ipv6: TorrentMapShards::new(num_shards),
ipv4: TorrentMapShards::new(NUM_SHARDS),
ipv6: TorrentMapShards::new(NUM_SHARDS),
}
}
}
impl TorrentMaps {
pub fn announce(
&self,
config: &Config,
@ -294,6 +295,9 @@ impl<I: Ip> TorrentMapShards<I> {
}
}
/// Use HashMap instead of IndexMap for better lookup performance
type TorrentMapShard<T> = HashMap<InfoHash, Arc<TorrentData<T>>>;
pub struct TorrentData<T: Ip> {
peer_map: RwLock<PeerMap<T>>,
pending_removal: AtomicBool,