mirror of
https://github.com/fafhrd91/actix-net
synced 2025-02-17 13:33:31 +01:00
fix io-uring feature for actix-server (#414)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
3f49d8ab54
commit
3658929010
13
.github/workflows/ci.yml
vendored
13
.github/workflows/ci.yml
vendored
@ -196,13 +196,6 @@ jobs:
|
|||||||
- name: Cache Dependencies
|
- name: Cache Dependencies
|
||||||
uses: Swatinem/rust-cache@v1.3.0
|
uses: Swatinem/rust-cache@v1.3.0
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- name: doc tests io-uring
|
||||||
uses: actions-rs/cargo@v1
|
run: |
|
||||||
with:
|
sudo bash -c "ulimit -Sl 512 && ulimit -Hl 512 && PATH=$PATH:/usr/share/rust/.cargo/bin && RUSTUP_TOOLCHAIN=nightly cargo ci-doctest"
|
||||||
command: install
|
|
||||||
args: cargo-hack
|
|
||||||
|
|
||||||
- name: doc tests
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
timeout-minutes: 40
|
|
||||||
with: { command: ci-doctest }
|
|
||||||
|
@ -18,7 +18,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
io-uring = ["actix-rt/io-uring"]
|
io-uring = ["tokio-uring"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-rt = { version = "2.4.0", default-features = false }
|
actix-rt = { version = "2.4.0", default-features = false }
|
||||||
@ -32,6 +32,9 @@ num_cpus = "1.13"
|
|||||||
socket2 = "0.4.2"
|
socket2 = "0.4.2"
|
||||||
tokio = { version = "1.5.1", features = ["sync"] }
|
tokio = { version = "1.5.1", features = ["sync"] }
|
||||||
|
|
||||||
|
# runtime for io-uring feature
|
||||||
|
tokio-uring = { version = "0.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-codec = "0.4.0"
|
actix-codec = "0.4.0"
|
||||||
actix-rt = "2.0.0"
|
actix-rt = "2.0.0"
|
||||||
|
@ -283,15 +283,6 @@ impl ServerWorker {
|
|||||||
let counter = Counter::new(config.max_concurrent_connections);
|
let counter = Counter::new(config.max_concurrent_connections);
|
||||||
|
|
||||||
let counter_clone = counter.clone();
|
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
|
// get actix system context if it is set
|
||||||
let sys = System::try_current();
|
let sys = System::try_current();
|
||||||
@ -299,6 +290,8 @@ impl ServerWorker {
|
|||||||
// service factories initialization channel
|
// service factories initialization channel
|
||||||
let (factory_tx, factory_rx) = std::sync::mpsc::sync_channel(1);
|
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()
|
std::thread::Builder::new()
|
||||||
.name(format!("actix-server worker {}", idx))
|
.name(format!("actix-server worker {}", idx))
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
@ -307,13 +300,7 @@ impl ServerWorker {
|
|||||||
System::set_current(sys);
|
System::set_current(sys);
|
||||||
}
|
}
|
||||||
|
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
let worker_fut = async move {
|
||||||
.enable_all()
|
|
||||||
.max_blocking_threads(config.max_blocking_threads)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
rt.block_on(tokio::task::LocalSet::new().run_until(async move {
|
|
||||||
let fut = factories
|
let fut = factories
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -368,7 +355,26 @@ impl ServerWorker {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.expect("task 2 panic");
|
.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");
|
.expect("worker thread error/panic");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user