Skip to content

Commit

Permalink
feat: introduce cpu-arch, dashmap, parking_lot
Browse files Browse the repository at this point in the history
* Change mutex usage from std to parking_lot (faster impl)
* Calculate checksums/ip-addr with cpu-native ASM
* Move from locked hashmap to dashmap (lockfree)
  • Loading branch information
kp-omer-shamash committed Jan 9, 2025
1 parent 0548f16 commit 676d160
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 108 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
runner = ["qemu-aarch64-static"] # use qemu user emulation for cargo run and test

[build]
rustflags = ["-C", "target-cpu=native"]
71 changes: 71 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions lightway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ metrics.workspace = true
more-asserts.workspace = true
num_enum = "0.7.0"
once_cell = "1.19.0"
parking_lot = "0.12"
pnet.workspace = true
rand.workspace = true
rand_core = "0.6.4"
Expand Down
5 changes: 3 additions & 2 deletions lightway-core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ mod io_adapter;
mod key_update;

use bytes::{Bytes, BytesMut};
use parking_lot::Mutex;
use rand::Rng;
use std::borrow::Cow;
use std::net::AddrParseError;
use std::num::{NonZeroU16, Wrapping};
use std::{
net::SocketAddr,
sync::{Arc, Mutex},
sync::Arc,
time::{Duration, Instant},
};
use thiserror::Error;
Expand Down Expand Up @@ -936,7 +937,7 @@ impl<AppState: Send> Connection<AppState> {
ref mut pending_session_id,
..
} => {
let new_session_id = rng.lock().unwrap().gen();
let new_session_id = rng.lock().gen();

self.session.io_cb_mut().set_session_id(new_session_id);

Expand Down
2 changes: 1 addition & 1 deletion lightway-core/src/connection/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'a, AppState: Send + 'static> ServerConnectionBuilder<'a, AppState> {
let auth = ctx.auth.clone();
let ip_pool = ctx.ip_pool.clone();

let session_id = ctx.rng.lock().unwrap().gen();
let session_id = ctx.rng.lock().gen();

let outside_mtu = MAX_OUTSIDE_MTU;

Expand Down
3 changes: 2 additions & 1 deletion lightway-core/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub mod ip_pool;
mod server_auth;

use parking_lot::Mutex;
use rand::SeedableRng;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use thiserror::Error;

use crate::{
Expand Down
Loading

0 comments on commit 676d160

Please sign in to comment.