Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: enhance WireGuard performance #51

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 23 additions & 102 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ debug = true

[patch.crates-io]
rustls = { git = "https://github.com/XOR-op/rustls.delta.git", branch = "unofficial-rel-0.23" }
smoltcp = { git = "https://github.com/XOR-op/smoltcp.git", branch = "resize-recv-buffer" }
smoltcp = { git = "https://github.com/XOR-op/smoltcp.git", branch = "rcv-buf-pinned" }
# Only used to bump x25519-dalek; will be removed once 0.6.1 is released
boringtun = { git = "https://github.com/XOR-op/boringtun", branch = "master"}
3 changes: 2 additions & 1 deletion boltconn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ network-interface = "2.0.0"
nix = { version = "0.29.0", features = ["user", "fs"] }
rand = { version = "0.8.5", features = ["small_rng"] }
regex = "1.7.0"
sharded-slab = "0.1.7"
socket2 = { version = "0.5.1", features = ["all"] }
thiserror = "1.0.37"
tokio = { version = "1.32.0", features = [
tokio = { version = "1.40.0", features = [
"rt",
"rt-multi-thread",
"net",
Expand Down
10 changes: 0 additions & 10 deletions boltconn/src/common/id_gen.rs

This file was deleted.

3 changes: 2 additions & 1 deletion boltconn/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub mod client_hello;
pub mod duplex_chan;
pub mod evictable_vec;
pub mod host_matcher;
pub mod id_gen;
mod sync;
pub mod utils;

pub use sync::{local_async_run, AbortCanary};

Expand All @@ -45,6 +45,7 @@ impl StreamOutboundTrait for tokio::net::windows::named_pipe::NamedPipeServer {}
impl StreamOutboundTrait for tokio::net::UnixStream {}

pub const MAX_PKT_SIZE: usize = 65576;
pub const MAX_UDP_PKT_SIZE: usize = 1518;

pub async fn read_to_bytes_mut(
buf: &mut BytesMut,
Expand Down
53 changes: 53 additions & 0 deletions boltconn/src/common/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{Duration, Instant};

#[derive(Default, Debug)]
pub struct IdGenerator(AtomicU64);

impl IdGenerator {
pub fn get(&self) -> u64 {
self.0.fetch_add(1, Ordering::Relaxed)
}
}

#[allow(unused)]
pub struct TputMeasurement {
inner: std::sync::Mutex<TputMeasurementInner>,
}

struct TputMeasurementInner {
pub accum_bytes: u64,
pub last_time: Instant,
pub interval: Duration,
}

impl TputMeasurement {
pub fn new(interval: Duration) -> Self {
Self {
inner: std::sync::Mutex::new(TputMeasurementInner {
accum_bytes: 0,
last_time: Instant::now(),
interval,
}),
}
}

pub fn update(&self, bytes: usize) -> Option<f64> {
let mut inner = self.inner.lock().unwrap();
inner.accum_bytes += bytes as u64;
let now = Instant::now();
let elapsed = now - inner.last_time;
if elapsed >= inner.interval {
let tput = inner.accum_bytes as f64 / elapsed.as_secs_f64();
inner.accum_bytes = 0;
inner.last_time = now;
Some(tput)
} else {
None
}
}

pub fn update_to_mbps(&self, bytes: usize) -> Option<f64> {
self.update(bytes).map(|tput| tput * 8.0 / 1_000_000.0)
}
}
Loading
Loading