mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
aquatic_common, udp, udp load test: improve cpu pinning
This commit is contained in:
parent
91a62ab73a
commit
aa332ab296
9 changed files with 142 additions and 78 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
|
||||
use aquatic_common::cpu_pinning::CpuPinningConfig;
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -27,7 +28,7 @@ pub struct Config {
|
|||
pub duration: usize,
|
||||
pub network: NetworkConfig,
|
||||
pub handler: HandlerConfig,
|
||||
pub core_affinity: CoreAffinityConfig,
|
||||
pub cpu_pinning: CpuPinningConfig,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
|
@ -97,13 +98,6 @@ pub struct HandlerConfig {
|
|||
pub additional_request_factor: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct CoreAffinityConfig {
|
||||
/// Set core affinities, descending from last core
|
||||
pub set_affinities: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -113,7 +107,7 @@ impl Default for Config {
|
|||
duration: 0,
|
||||
network: NetworkConfig::default(),
|
||||
handler: HandlerConfig::default(),
|
||||
core_affinity: CoreAffinityConfig::default(),
|
||||
cpu_pinning: CpuPinningConfig::default_for_load_test(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -192,11 +186,3 @@ pub struct SocketWorkerLocalStatistics {
|
|||
pub responses_scrape: usize,
|
||||
pub responses_error: usize,
|
||||
}
|
||||
|
||||
impl Default for CoreAffinityConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
set_affinities: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::sync::{atomic::Ordering, Arc};
|
|||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use aquatic_common::cpu_pinning::{pin_current_if_configured_to, WorkerIndex};
|
||||
use crossbeam_channel::unbounded;
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::Mutex;
|
||||
|
|
@ -33,15 +34,6 @@ pub fn main() {
|
|||
impl aquatic_cli_helpers::Config for Config {}
|
||||
|
||||
fn run(config: Config) -> ::anyhow::Result<()> {
|
||||
let affinity_max = core_affinity::get_core_ids()
|
||||
.map(|ids| ids.iter().map(|id| id.id).max())
|
||||
.flatten()
|
||||
.unwrap_or(0);
|
||||
|
||||
if config.core_affinity.set_affinities {
|
||||
core_affinity::set_for_current(core_affinity::CoreId { id: affinity_max });
|
||||
}
|
||||
|
||||
if config.handler.weight_announce + config.handler.weight_connect + config.handler.weight_scrape
|
||||
== 0
|
||||
{
|
||||
|
|
@ -50,6 +42,12 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
|
||||
println!("Starting client with config: {:#?}", config);
|
||||
|
||||
pin_current_if_configured_to(
|
||||
&config.cpu_pinning,
|
||||
config.num_socket_workers as usize,
|
||||
WorkerIndex::Other,
|
||||
);
|
||||
|
||||
let mut info_hashes = Vec::with_capacity(config.handler.number_of_torrents);
|
||||
|
||||
for _ in 0..config.handler.number_of_torrents {
|
||||
|
|
@ -101,11 +99,11 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let state = state.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
if config.core_affinity.set_affinities {
|
||||
core_affinity::set_for_current(core_affinity::CoreId {
|
||||
id: affinity_max - 1 - i as usize,
|
||||
});
|
||||
}
|
||||
pin_current_if_configured_to(
|
||||
&config.cpu_pinning,
|
||||
config.num_socket_workers as usize,
|
||||
WorkerIndex::SocketWorker(i as usize),
|
||||
);
|
||||
|
||||
run_socket_thread(state, response_sender, receiver, &config, addr, thread_id)
|
||||
});
|
||||
|
|
@ -118,11 +116,11 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let response_receiver = response_receiver.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
if config.core_affinity.set_affinities {
|
||||
core_affinity::set_for_current(core_affinity::CoreId {
|
||||
id: affinity_max - config.num_socket_workers as usize - 1 - i as usize,
|
||||
});
|
||||
}
|
||||
pin_current_if_configured_to(
|
||||
&config.cpu_pinning,
|
||||
config.num_socket_workers as usize,
|
||||
WorkerIndex::RequestWorker(i as usize),
|
||||
);
|
||||
run_handler_thread(&config, state, pareto, request_senders, response_receiver)
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue