udp: new file structure: each worker types is submod of workers mod

This commit is contained in:
Joakim Frostegård 2021-11-21 19:39:44 +01:00
parent 2e3f7a4c9f
commit 34f263f6b9
6 changed files with 19 additions and 14 deletions

View file

@ -1,15 +1,12 @@
pub mod common; pub mod common;
pub mod config; pub mod config;
pub mod handlers; pub mod workers;
pub mod network;
pub mod tasks;
use config::Config; use config::Config;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::sync::{atomic::AtomicUsize, Arc}; use std::sync::{atomic::AtomicUsize, Arc};
use std::thread::Builder; use std::thread::Builder;
use std::time::Duration;
use anyhow::Context; use anyhow::Context;
#[cfg(feature = "cpu-pinning")] #[cfg(feature = "cpu-pinning")]
@ -72,7 +69,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
WorkerIndex::RequestWorker(i), WorkerIndex::RequestWorker(i),
); );
handlers::run_request_worker( workers::request::run_request_worker(
config, config,
state, state,
request_receiver, request_receiver,
@ -101,7 +98,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
WorkerIndex::SocketWorker(i), WorkerIndex::SocketWorker(i),
); );
network::run_socket_worker( workers::socket::run_socket_worker(
state, state,
config, config,
i, i,
@ -127,11 +124,7 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
WorkerIndex::Other, WorkerIndex::Other,
); );
loop { workers::statistics::run_statistics_worker(config, state);
::std::thread::sleep(Duration::from_secs(config.statistics.interval));
tasks::gather_and_print_statistics(&state, &config);
}
}) })
.with_context(|| "spawn statistics worker")?; .with_context(|| "spawn statistics worker")?;
} }

View file

@ -0,0 +1,3 @@
pub mod request;
pub mod socket;
pub mod statistics;

View file

@ -1,9 +1,18 @@
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use super::common::*; use crate::common::*;
use crate::config::Config; use crate::config::Config;
pub fn gather_and_print_statistics(state: &State, config: &Config) { pub fn run_statistics_worker(config: Config, state: State) {
loop {
::std::thread::sleep(Duration::from_secs(config.statistics.interval));
gather_and_print_statistics(&config, &state);
}
}
fn gather_and_print_statistics(config: &Config, state: &State) {
let interval = config.statistics.interval; let interval = config.statistics.interval;
let requests_received: f64 = state let requests_received: f64 = state

View file

@ -7,7 +7,7 @@
//! Scrape: 1 873 545 requests/second, 533.75 ns/request //! Scrape: 1 873 545 requests/second, 533.75 ns/request
//! ``` //! ```
use aquatic_udp::handlers::run_request_worker; use aquatic_udp::workers::request::run_request_worker;
use crossbeam_channel::unbounded; use crossbeam_channel::unbounded;
use num_format::{Locale, ToFormattedString}; use num_format::{Locale, ToFormattedString};
use rand::{rngs::SmallRng, thread_rng, Rng, SeedableRng}; use rand::{rngs::SmallRng, thread_rng, Rng, SeedableRng};