Skip to content

Commit

Permalink
feat(io_uring): add uring for connect_phase linux
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Dec 31, 2024
1 parent 6b61a14 commit a45cada
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 16 deletions.
42 changes: 33 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions spider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider"
version = "2.22.19"
version = "2.23.1"
authors = [
"j-mendez <[email protected]>"
]
Expand Down Expand Up @@ -81,6 +81,7 @@ features = [

[target.'cfg(target_os = "linux")'.dependencies]
libc = "0.2"
tokio-uring = { version = "0.4", optional = true }

[target.'cfg(all(not(windows), not(target_os = "android"), not(target_env = "musl")))'.dependencies]
tikv-jemallocator = { version = "0.6", optional = true }
Expand Down Expand Up @@ -115,7 +116,7 @@ reqwest = { version = "0.12", features = [
] }

[features]
default = ["sync", "reqwest_native_tls_native_roots", "disk_native_tls", "cookies", "ua_generator", "encoding", "string_interner_buffer_backend", "balance"]
default = ["sync", "reqwest_native_tls_native_roots", "disk_native_tls", "cookies", "ua_generator", "encoding", "string_interner_buffer_backend", "balance", "io_uring"]
disk = ["dep:sqlx", "dep:aho-corasick"]
disk_native_tls = ["disk", "sqlx/runtime-tokio-native-tls"]
disk_aws = ["disk", "sqlx/tls-rustls-aws-lc-rs"]
Expand All @@ -128,6 +129,7 @@ jemalloc = ["tikv-jemallocator"]
decentralized = ["serde", "flexbuffers"]
control = []
time = []
io_uring = ["dep:tokio-uring"]
sync = ["tokio/sync"]
flexbuffers = ["dep:flexbuffers"]
serde = ["dep:serde", "hashbrown/serde", "string-interner/serde", "dep:serde_regex", "smallvec/serde"]
Expand Down
23 changes: 23 additions & 0 deletions spider/src/utils/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ pub(crate) fn background_connect_threading() -> bool {
}

/// Init a background thread for request connect handling.
#[cfg(all(target_os = "linux", feature = "io_uring"))]
pub(crate) fn init_background_runtime() {
let _ = CONNECT_THREAD_POOL.set({
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let builder = std::thread::Builder::new();

if let Err(_) = builder.spawn(move || {
tokio_uring::builder().start(async {
while let Some(work) = rx.recv().await {
tokio_uring::spawn(work);
}
})
}) {
let _ = tx.downgrade();
BACKGROUND_THREAD_CONNECT_ENABLED.store(false, std::sync::atomic::Ordering::Relaxed);
};

tx
});
}

/// Init a background thread for request connect handling.
#[cfg(any(not(target_os = "linux"), not(feature = "io_uring")))]
pub(crate) fn init_background_runtime() {
let _ = CONNECT_THREAD_POOL.set({
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
Expand Down
2 changes: 1 addition & 1 deletion spider_chrome/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_chrome"
version = "2.22.19"
version = "2.23.1"
rust-version = "1.70"
authors = [
"j-mendez <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion spider_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_cli"
version = "2.22.19"
version = "2.23.1"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_transformations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_transformations"
version = "2.22.19"
version = "2.23.1"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_utils"
version = "2.22.19"
version = "2.23.1"
authors = [
"j-mendez <[email protected]>"
]
Expand Down
2 changes: 1 addition & 1 deletion spider_worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spider_worker"
version = "2.22.19"
version = "2.23.1"
authors = [
"j-mendez <[email protected]>"
]
Expand Down

0 comments on commit a45cada

Please sign in to comment.