mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
udp: remove thingbuf in favor of crossbeam channel
thingbuf didn't have obvious performance advantages and is a lot less mature. Furthermore, it doesn't support anything like crossbeam Receiver::try_iter, which is prefereable now that announce responses can be sent to any socket worker.
This commit is contained in:
parent
e77c9f46e7
commit
1a6b4345d4
10 changed files with 163 additions and 329 deletions
|
|
@ -3,7 +3,6 @@ pub mod config;
|
|||
pub mod workers;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::mem::size_of;
|
||||
use std::thread::Builder;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -16,28 +15,20 @@ use aquatic_common::access_list::update_access_list;
|
|||
#[cfg(feature = "cpu-pinning")]
|
||||
use aquatic_common::cpu_pinning::{pin_current_if_configured_to, WorkerIndex};
|
||||
use aquatic_common::privileges::PrivilegeDropper;
|
||||
use aquatic_common::{CanonicalSocketAddr, PanicSentinelWatcher, ServerStartInstant};
|
||||
use aquatic_common::{PanicSentinelWatcher, ServerStartInstant};
|
||||
|
||||
use common::{
|
||||
ConnectedRequestSender, ConnectedResponseSender, Recycler, SocketWorkerIndex, State,
|
||||
SwarmWorkerIndex,
|
||||
ConnectedRequestSender, ConnectedResponseSender, SocketWorkerIndex, State, SwarmWorkerIndex,
|
||||
};
|
||||
use config::Config;
|
||||
use workers::socket::ConnectionValidator;
|
||||
|
||||
use crate::common::{ConnectedRequest, ConnectedResponseWithAddr};
|
||||
|
||||
pub const APP_NAME: &str = "aquatic_udp: UDP BitTorrent tracker";
|
||||
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub fn run(config: Config) -> ::anyhow::Result<()> {
|
||||
let mut signals = Signals::new([SIGUSR1, SIGTERM])?;
|
||||
|
||||
::log::info!(
|
||||
"Estimated max channel memory use: {:.02} MB",
|
||||
est_max_total_channel_memory(&config)
|
||||
);
|
||||
|
||||
let state = State::new(config.swarm_workers);
|
||||
let connection_validator = ConnectionValidator::new(&config)?;
|
||||
let (sentinel_watcher, sentinel) = PanicSentinelWatcher::create_with_sentinel();
|
||||
|
|
@ -56,19 +47,14 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let server_start_instant = ServerStartInstant::new();
|
||||
|
||||
for i in 0..config.swarm_workers {
|
||||
let (request_sender, request_receiver) = if config.worker_channel_size == 0 {
|
||||
unbounded()
|
||||
} else {
|
||||
bounded(config.worker_channel_size)
|
||||
};
|
||||
let (request_sender, request_receiver) = bounded(config.worker_channel_size);
|
||||
|
||||
request_senders.push(request_sender);
|
||||
request_receivers.insert(i, request_receiver);
|
||||
}
|
||||
|
||||
for i in 0..config.socket_workers {
|
||||
let (response_sender, response_receiver) =
|
||||
thingbuf::mpsc::blocking::with_recycle(config.worker_channel_size, Recycler);
|
||||
let (response_sender, response_receiver) = bounded(config.worker_channel_size);
|
||||
|
||||
response_senders.push(response_sender);
|
||||
response_receivers.insert(i, response_receiver);
|
||||
|
|
@ -214,16 +200,3 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn est_max_total_channel_memory(config: &Config) -> f64 {
|
||||
let request_channel_max_size = config.swarm_workers
|
||||
* config.worker_channel_size
|
||||
* (size_of::<SocketWorkerIndex>()
|
||||
+ size_of::<ConnectedRequest>()
|
||||
+ size_of::<CanonicalSocketAddr>());
|
||||
let response_channel_max_size = config.socket_workers
|
||||
* config.worker_channel_size
|
||||
* ConnectedResponseWithAddr::estimated_max_size(&config);
|
||||
|
||||
(request_channel_max_size as u64 + response_channel_max_size as u64) as f64 / (1024.0 * 1024.0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue