toggle worker_affinity feature from program argument
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
674acc8657
commit
503210c3bf
2 changed files with 29 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::{ArgAction, Parser};
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
config::{Figment, FigmentValue},
|
config::{Figment, FigmentValue},
|
||||||
err, toml,
|
err, toml,
|
||||||
|
@ -50,6 +50,19 @@ pub(crate) struct Args {
|
||||||
/// Set the histogram bucket count (tokio_unstable). Default is 20.
|
/// Set the histogram bucket count (tokio_unstable). Default is 20.
|
||||||
#[arg(long, hide(true), env = "CONDUWUIT_RUNTIME_HISTOGRAM_BUCKETS", default_value = "20")]
|
#[arg(long, hide(true), env = "CONDUWUIT_RUNTIME_HISTOGRAM_BUCKETS", default_value = "20")]
|
||||||
pub(crate) worker_histogram_buckets: usize,
|
pub(crate) worker_histogram_buckets: usize,
|
||||||
|
|
||||||
|
/// Toggles worker affinity feature.
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
hide(true),
|
||||||
|
env = "CONDUWUIT_RUNTIME_WORKER_AFFINITY",
|
||||||
|
action = ArgAction::Set,
|
||||||
|
num_args = 0..=1,
|
||||||
|
require_equals(false),
|
||||||
|
default_value = "true",
|
||||||
|
default_missing_value = "true",
|
||||||
|
)]
|
||||||
|
pub(crate) worker_affinity: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse commandline arguments into structured data
|
/// Parse commandline arguments into structured data
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{thread, time::Duration};
|
use std::{sync::OnceLock, thread, time::Duration};
|
||||||
|
|
||||||
use conduwuit::Result;
|
use conduwuit::Result;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
|
@ -12,9 +12,14 @@ const GLOBAL_QUEUE_INTERVAL: u32 = 192;
|
||||||
const KERNEL_QUEUE_INTERVAL: u32 = 256;
|
const KERNEL_QUEUE_INTERVAL: u32 = 256;
|
||||||
const KERNEL_EVENTS_PER_TICK: usize = 512;
|
const KERNEL_EVENTS_PER_TICK: usize = 512;
|
||||||
|
|
||||||
pub(super) fn new(args: &Args) -> Result<tokio::runtime::Runtime> {
|
static WORKER_AFFINITY: OnceLock<bool> = OnceLock::new();
|
||||||
let mut builder = Builder::new_multi_thread();
|
|
||||||
|
|
||||||
|
pub(super) fn new(args: &Args) -> Result<tokio::runtime::Runtime> {
|
||||||
|
WORKER_AFFINITY
|
||||||
|
.set(args.worker_affinity)
|
||||||
|
.expect("set WORKER_AFFINITY from program argument");
|
||||||
|
|
||||||
|
let mut builder = Builder::new_multi_thread();
|
||||||
builder
|
builder
|
||||||
.enable_io()
|
.enable_io()
|
||||||
.enable_time()
|
.enable_time()
|
||||||
|
@ -63,7 +68,13 @@ fn enable_histogram(builder: &mut Builder, args: &Args) {
|
||||||
)]
|
)]
|
||||||
fn thread_start() {
|
fn thread_start() {
|
||||||
#[cfg(feature = "worker_affinity")]
|
#[cfg(feature = "worker_affinity")]
|
||||||
|
if WORKER_AFFINITY
|
||||||
|
.get()
|
||||||
|
.copied()
|
||||||
|
.expect("WORKER_AFFINITY initialized by runtime::new()")
|
||||||
|
{
|
||||||
set_worker_affinity();
|
set_worker_affinity();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "worker_affinity")]
|
#[cfg(feature = "worker_affinity")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue