http, http_private: rename request workers to swarm workers

This commit is contained in:
Joakim Frostegård 2022-07-04 11:52:51 +02:00
parent fb2794643d
commit c89406179b
12 changed files with 31 additions and 33 deletions

View file

@ -17,7 +17,7 @@ pub struct RequestWorkerIndex(pub usize);
impl RequestWorkerIndex {
pub fn from_info_hash(config: &Config, info_hash: InfoHash) -> Self {
Self(info_hash.0[0] as usize % config.request_workers)
Self(info_hash.0[0] as usize % config.swarm_workers)
}
}

View file

@ -11,12 +11,12 @@ use aquatic_common::cli::LogLevel;
#[serde(default)]
pub struct Config {
/// Socket workers receive requests from the socket, parse them and send
/// them on to the request workers. They then receive responses from the
/// request workers, encode them and send them back over the socket.
/// them on to the swarm workers. They then receive responses from the
/// swarm workers, encode them and send them back over the socket.
pub socket_workers: usize,
/// Request workers receive a number of requests from socket workers,
/// Swarm workers receive a number of requests from socket workers,
/// generate responses and send them back to the socket workers.
pub request_workers: usize,
pub swarm_workers: usize,
pub worker_channel_size: usize,
/// Number of database connections to establish in each socket worker
pub db_connections_per_worker: u32,
@ -31,7 +31,7 @@ impl Default for Config {
fn default() -> Self {
Self {
socket_workers: 1,
request_workers: 1,
swarm_workers: 1,
worker_channel_size: 128,
db_connections_per_worker: 4,
log_level: LogLevel::default(),

View file

@ -30,7 +30,7 @@ pub fn run(config: Config) -> anyhow::Result<()> {
let mut request_senders = Vec::new();
let mut request_receivers = VecDeque::new();
for _ in 0..config.request_workers {
for _ in 0..config.swarm_workers {
let (request_sender, request_receiver) = channel(config.worker_channel_size);
request_senders.push(request_sender);
@ -64,16 +64,14 @@ pub fn run(config: Config) -> anyhow::Result<()> {
handles.push(handle);
}
for _ in 0..config.request_workers {
for _ in 0..config.swarm_workers {
let sentinel = sentinel.clone();
let config = config.clone();
let request_receiver = request_receivers.pop_front().unwrap();
let handle = ::std::thread::Builder::new()
.name("request".into())
.spawn(move || {
workers::request::run_request_worker(sentinel, config, request_receiver)
})?;
.spawn(move || workers::swarm::run_swarm_worker(sentinel, config, request_receiver))?;
handles.push(handle);
}

View file

@ -1,2 +1,2 @@
pub mod request;
pub mod socket;
pub mod swarm;

View file

@ -33,7 +33,7 @@ pub async fn announce(
let request = AnnounceRequest::from_query_string(&query)
.map_err(|_| FailureResponse::new("Malformed request"))?;
let request_worker_index = RequestWorkerIndex::from_info_hash(&config, request.info_hash);
let swarm_worker_index = RequestWorkerIndex::from_info_hash(&config, request.info_hash);
let opt_user_agent = opt_user_agent.map(|header| header.as_str().to_owned());
let source_addr = CanonicalSocketAddr::new(source_addr);
@ -43,7 +43,7 @@ pub async fn announce(
.await?;
let response_receiver = request_sender
.send_to(request_worker_index, validated_request, source_addr)
.send_to(swarm_worker_index, validated_request, source_addr)
.await
.map_err(|err| internal_error(format!("Sending request over channel failed: {:#}", err)))?;

View file

@ -21,7 +21,7 @@ use crate::config::Config;
use common::*;
pub fn run_request_worker(
pub fn run_swarm_worker(
_sentinel: PanicSentinel,
config: Config,
request_receiver: Receiver<ChannelAnnounceRequest>,