1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-28 12:10:37 +02:00

fix io-uring feature for actix-server (#414)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
fakeshadow
2021-11-07 23:43:59 +08:00
committed by GitHub
parent 3f49d8ab54
commit 3658929010
3 changed files with 30 additions and 28 deletions

View File

@ -283,15 +283,6 @@ impl ServerWorker {
let counter = Counter::new(config.max_concurrent_connections);
let counter_clone = counter.clone();
// every worker runs in it's own arbiter.
// use a custom tokio runtime builder to change the settings of runtime.
#[cfg(all(target_os = "linux", feature = "io-uring"))]
let arbiter = {
// TODO: pass max blocking thread config when tokio-uring enable configuration
// on building runtime.
let _ = config.max_blocking_threads;
Arbiter::new()
};
// get actix system context if it is set
let sys = System::try_current();
@ -299,6 +290,8 @@ impl ServerWorker {
// service factories initialization channel
let (factory_tx, factory_rx) = std::sync::mpsc::sync_channel(1);
// every worker runs in it's own thread and tokio runtime.
// use a custom tokio runtime builder to change the settings of runtime.
std::thread::Builder::new()
.name(format!("actix-server worker {}", idx))
.spawn(move || {
@ -307,13 +300,7 @@ impl ServerWorker {
System::set_current(sys);
}
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.max_blocking_threads(config.max_blocking_threads)
.build()
.unwrap();
rt.block_on(tokio::task::LocalSet::new().run_until(async move {
let worker_fut = async move {
let fut = factories
.iter()
.enumerate()
@ -368,7 +355,26 @@ impl ServerWorker {
})
.await
.expect("task 2 panic");
}))
};
#[cfg(all(target_os = "linux", feature = "io-uring"))]
{
// TODO: pass max blocking thread config when tokio-uring enable configuration
// on building runtime.
let _ = config.max_blocking_threads;
tokio_uring::start(worker_fut)
}
#[cfg(not(all(target_os = "linux", feature = "io-uring")))]
{
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.max_blocking_threads(config.max_blocking_threads)
.build()
.unwrap();
rt.block_on(tokio::task::LocalSet::new().run_until(worker_fut))
}
})
.expect("worker thread error/panic");