Merge pull request #135 from greatest-ape/work-2023-03-15

reduce udp uring buffer sizes; upgrade glommio to v0.8; update dependencies
This commit is contained in:
Joakim Frostegård 2023-03-16 00:13:34 +01:00 committed by GitHub
commit 38383039db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 108 additions and 124 deletions

View file

@ -33,6 +33,7 @@
#### Added
* Add experimental io_uring backend with higher throughput
* Add optional response resend buffer for use on on operating systems that
don't buffer outgoing UDP traffic
* Add optional extended statistics (peers per torrent histogram)

143
Cargo.lock generated
View file

@ -122,7 +122,7 @@ dependencies = [
"serde",
"signal-hook",
"slab",
"socket2 0.4.9",
"socket2",
]
[[package]]
@ -166,7 +166,7 @@ dependencies = [
"rustls",
"serde",
"signal-hook",
"socket2 0.4.9",
"socket2",
"sqlx",
"tokio",
"tokio-rustls",
@ -223,7 +223,7 @@ dependencies = [
"aquatic_udp_protocol",
"blake3",
"cfg-if",
"constant_time_eq 0.2.4",
"constant_time_eq 0.2.5",
"crossbeam-channel",
"getrandom",
"hashbrown 0.13.2",
@ -243,7 +243,7 @@ dependencies = [
"serde",
"signal-hook",
"slab",
"socket2 0.4.9",
"socket2",
"time",
"tinytemplate",
]
@ -282,7 +282,7 @@ dependencies = [
"rand",
"rand_distr",
"serde",
"socket2 0.4.9",
"socket2",
]
[[package]]
@ -324,7 +324,7 @@ dependencies = [
"serde",
"signal-hook",
"slab",
"socket2 0.4.9",
"socket2",
"tungstenite",
]
@ -696,9 +696,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "constant_time_eq"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3ad85c1f65dc7b37604eb0e89748faf0b9653065f2a8ef69f96a687ec1e9279"
checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b"
[[package]]
name = "cpufeatures"
@ -1028,7 +1028,7 @@ dependencies = [
"futures-sink",
"nanorand",
"pin-project",
"spin 0.9.5",
"spin 0.9.6",
]
[[package]]
@ -1048,9 +1048,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84"
checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549"
dependencies = [
"futures-channel",
"futures-core",
@ -1063,9 +1063,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5"
checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac"
dependencies = [
"futures-core",
"futures-sink",
@ -1073,15 +1073,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608"
checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd"
[[package]]
name = "futures-executor"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e"
checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83"
dependencies = [
"futures-core",
"futures-task",
@ -1101,9 +1101,9 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531"
checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91"
[[package]]
name = "futures-lite"
@ -1122,9 +1122,9 @@ dependencies = [
[[package]]
name = "futures-macro"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6"
dependencies = [
"proc-macro2",
"quote",
@ -1144,21 +1144,21 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364"
checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2"
[[package]]
name = "futures-task"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366"
checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879"
[[package]]
name = "futures-util"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1"
checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab"
dependencies = [
"futures-channel",
"futures-core",
@ -1226,9 +1226,9 @@ dependencies = [
[[package]]
name = "glommio"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd6912e67cabcb397683537cadc80a38136fdea7702430ede1a43207940697a6"
checksum = "ac1f09bf53139d5680da6325b4e79c6bc1518e94a65ab74df14b7e3693a8c78b"
dependencies = [
"ahash 0.7.6",
"backtrace",
@ -1246,7 +1246,6 @@ dependencies = [
"libc",
"lockfree",
"log",
"membarrier",
"nix 0.23.2",
"pin-project-lite",
"rlimit",
@ -1255,7 +1254,7 @@ dependencies = [
"signal-hook",
"sketches-ddsketch 0.1.3",
"smallvec",
"socket2 0.3.19",
"socket2",
"tracing",
"typenum",
]
@ -1433,9 +1432,9 @@ dependencies = [
[[package]]
name = "hyper"
version = "0.14.24"
version = "0.14.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c"
checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899"
dependencies = [
"bytes",
"futures-channel",
@ -1447,7 +1446,7 @@ dependencies = [
"httpdate",
"itoa",
"pin-project-lite",
"socket2 0.4.9",
"socket2",
"tokio",
"tower-service",
"tracing",
@ -1628,17 +1627,6 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb"
[[package]]
name = "membarrier"
version = "0.2.2"
source = "git+https://github.com/glommer/membarrier-rs.git?branch=issue-22#a79ea2d9b6e976b83b7fd709073cf977b1e47581"
dependencies = [
"cfg-if",
"kernel32-sys",
"lazy_static",
"libc",
]
[[package]]
name = "memchr"
version = "2.5.0"
@ -2166,9 +2154,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.51"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224"
dependencies = [
"unicode-ident",
]
@ -2213,9 +2201,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.23"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [
"proc-macro2",
]
@ -2433,9 +2421,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.154"
version = "1.0.156"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cdd151213925e7f1ab45a9bbfb129316bd00799784b174b7cc7bcd16961c49e"
checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4"
dependencies = [
"serde_derive",
]
@ -2471,9 +2459,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.154"
version = "1.0.156"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fc80d722935453bcafdc2c9a73cd6fac4dc1938f0346035d84bf99fa9e33217"
checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d"
dependencies = [
"proc-macro2",
"quote",
@ -2613,17 +2601,6 @@ dependencies = [
"syn",
]
[[package]]
name = "socket2"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e"
dependencies = [
"cfg-if",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "socket2"
version = "0.4.9"
@ -2642,9 +2619,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.5"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc"
checksum = "b5d6e0250b93c8427a177b849d144a96d5acc57006149479403d7861ab721e34"
dependencies = [
"lock_api",
]
@ -2896,7 +2873,7 @@ dependencies = [
"parking_lot 0.12.1",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.4.9",
"socket2",
"tokio-macros",
"windows-sys 0.45.0",
]
@ -3331,9 +3308,9 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
@ -3346,45 +3323,45 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_i686_gnu"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_msvc"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.1"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "zeroize"

View file

@ -37,9 +37,6 @@ aquatic_udp = { version = "0.2.0", path = "./aquatic_udp" }
aquatic_ws_protocol = { version = "0.2.0", path = "./aquatic_ws_protocol" }
aquatic_ws = { version = "0.2.0", path = "./aquatic_ws" }
[patch.crates-io]
membarrier = { git = "https://github.com/glommer/membarrier-rs.git", branch = "issue-22" }
[profile.release]
debug = false
lto = "thin"

View file

@ -25,9 +25,9 @@ Features at a glance:
- All data is stored in-memory (no database needed)
- IPv4 and IPv6 support
- Supports forbidding/allowing info hashes
- Built-in TLS support (no reverse proxy needed)
- Automated CI testing of full file transfers
- Built-in tracker TLS support (no reverse proxy needed)
- Prometheus metrics
- Automated CI testing of full file transfers
Known users:

View file

@ -35,7 +35,7 @@ simple_logger = { version = "4", features = ["stderr"] }
toml = "0.5"
# Optional
glommio = { version = "0.7", optional = true }
glommio = { version = "0.8", optional = true }
hwloc = { version = "0.5", optional = true }
rustls = { version = "0.20", optional = true }
rustls-pemfile = { version = "1", optional = true }

View file

@ -1,5 +1,7 @@
use std::{fs::File, io::BufReader, path::Path};
use anyhow::Context;
pub type RustlsConfig = rustls::ServerConfig;
pub fn create_rustls_config(
@ -7,7 +9,12 @@ pub fn create_rustls_config(
tls_private_key_path: &Path,
) -> anyhow::Result<RustlsConfig> {
let certs = {
let f = File::open(tls_certificate_path)?;
let f = File::open(tls_certificate_path).with_context(|| {
format!(
"open tls certificate file at {}",
tls_certificate_path.to_string_lossy()
)
})?;
let mut f = BufReader::new(f);
rustls_pemfile::certs(&mut f)?
@ -17,7 +24,12 @@ pub fn create_rustls_config(
};
let private_key = {
let f = File::open(tls_private_key_path)?;
let f = File::open(tls_private_key_path).with_context(|| {
format!(
"open tls private key file at {}",
tls_private_key_path.to_string_lossy()
)
})?;
let mut f = BufReader::new(f);
rustls_pemfile::pkcs8_private_keys(&mut f)?
@ -29,7 +41,8 @@ pub fn create_rustls_config(
let tls_config = rustls::ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(certs, private_key)?;
.with_single_cert(certs, private_key)
.with_context(|| "create rustls config")?;
Ok(tls_config)
}

View file

@ -32,7 +32,7 @@ either = "1"
futures = "0.3"
futures-lite = "1"
futures-rustls = "0.22"
glommio = "0.7"
glommio = "0.8"
itoa = "1"
libc = "0.2"
log = "0.4"

View file

@ -22,7 +22,7 @@ anyhow = "1"
futures-lite = "1"
futures-rustls = "0.22"
hashbrown = "0.13"
glommio = "0.7"
glommio = "0.8"
log = "0.4"
mimalloc = { version = "0.1", default-features = false }
rand = { version = "0.8", features = ["small_rng"] }

View file

@ -34,8 +34,17 @@ use super::storage::PendingScrapeResponseSlab;
use super::validator::ConnectionValidator;
use super::{create_socket, EXTRA_PACKET_SIZE_IPV4, EXTRA_PACKET_SIZE_IPV6};
const RESPONSE_BUF_LEN: usize = 8192;
const REQUEST_BUF_LEN: usize = 4096;
/// Size of each request buffer
///
/// Enough for scrape request with 20 info hashes
const REQUEST_BUF_LEN: usize = 256;
/// Size of each response buffer
///
/// Enough for:
/// - IPv6 announce response with 112 peers
/// - scrape response for 170 info hashes
const RESPONSE_BUF_LEN: usize = 2048;
const USER_DATA_RECV: u64 = u64::MAX;
const USER_DATA_PULSE_TIMEOUT: u64 = u64::MAX - 1;
@ -82,6 +91,7 @@ pub struct SocketWorker {
recv_sqe: io_uring::squeue::Entry,
pulse_timeout_sqe: io_uring::squeue::Entry,
cleaning_timeout_sqe: io_uring::squeue::Entry,
pending_scrape_valid_until: ValidUntil,
}
impl SocketWorker {
@ -153,6 +163,9 @@ impl SocketWorker {
cleaning_timeout_sqe.clone(),
];
let pending_scrape_valid_until =
ValidUntil::new(server_start_instant, config.cleaning.max_pending_scrape_age);
let mut worker = Self {
config,
shared_state,
@ -171,17 +184,13 @@ impl SocketWorker {
cleaning_timeout_sqe,
resubmittable_sqe_buf,
socket,
pending_scrape_valid_until,
};
CurrentRing::with(|ring| worker.run_inner(ring));
}
fn run_inner(&mut self, ring: &mut IoUring) {
let mut pending_scrape_valid_until = ValidUntil::new(
self.server_start_instant,
self.config.cleaning.max_pending_scrape_age,
);
loop {
for sqe in self.resubmittable_sqe_buf.drain(..) {
unsafe { ring.submission().push(&sqe).unwrap() };
@ -249,28 +258,24 @@ impl SocketWorker {
.unwrap();
for cqe in ring.completion() {
self.handle_cqe(&mut pending_scrape_valid_until, cqe);
self.handle_cqe(cqe);
}
self.send_buffers.reset_likely_next_free_index();
}
}
fn handle_cqe(
&mut self,
pending_scrape_valid_until: &mut ValidUntil,
cqe: io_uring::cqueue::Entry,
) {
fn handle_cqe(&mut self, cqe: io_uring::cqueue::Entry) {
match cqe.user_data() {
USER_DATA_RECV => {
self.handle_recv_cqe(*pending_scrape_valid_until, &cqe);
self.handle_recv_cqe(&cqe);
if !io_uring::cqueue::more(cqe.flags()) {
self.resubmittable_sqe_buf.push(self.recv_sqe.clone());
}
}
USER_DATA_PULSE_TIMEOUT => {
*pending_scrape_valid_until = ValidUntil::new(
self.pending_scrape_valid_until = ValidUntil::new(
self.server_start_instant,
self.config.cleaning.max_pending_scrape_age,
);
@ -335,11 +340,7 @@ impl SocketWorker {
}
}
fn handle_recv_cqe(
&mut self,
pending_scrape_valid_until: ValidUntil,
cqe: &io_uring::cqueue::Entry,
) {
fn handle_recv_cqe(&mut self, cqe: &io_uring::cqueue::Entry) {
let result = cqe.result();
if result < 0 {
@ -375,7 +376,7 @@ impl SocketWorker {
let addr = match self.recv_helper.parse(buffer) {
Ok((request, addr)) => {
self.handle_request(pending_scrape_valid_until, request, addr);
self.handle_request(request, addr);
addr
}
@ -430,12 +431,7 @@ impl SocketWorker {
}
}
fn handle_request(
&mut self,
pending_scrape_valid_until: ValidUntil,
request: Request,
src: CanonicalSocketAddr,
) {
fn handle_request(&mut self, request: Request, src: CanonicalSocketAddr) {
let access_list_mode = self.config.access_list.mode;
match request {
@ -485,7 +481,7 @@ impl SocketWorker {
let split_requests = self.pending_scrape_responses.prepare_split_requests(
&self.config,
request,
pending_scrape_valid_until,
self.pending_scrape_valid_until,
);
for (swarm_worker_index, request) in split_requests {

View file

@ -32,7 +32,7 @@ cfg-if = "1"
futures = "0.3"
futures-lite = "1"
futures-rustls = "0.22"
glommio = "0.7"
glommio = "0.8"
hashbrown = { version = "0.13", features = ["serde"] }
httparse = "1"
log = "0.4"

View file

@ -22,7 +22,7 @@ anyhow = "1"
async-tungstenite = "0.19"
futures = "0.3"
futures-rustls = "0.22"
glommio = "0.7"
glommio = "0.8"
log = "0.4"
mimalloc = { version = "0.1", default-features = false }
rand = { version = "0.8", features = ["small_rng"] }