aramperes / onetun

User space WireGuard port-forward in Rust
MIT License
861 stars 42 forks source link

Improve bandwidth #29

Open aramperes opened 2 years ago

aramperes commented 2 years ago

I tested some sftp tunneling on some big files and found that each connection is capped at around 2MB/s. Naturally this depends on the latency and bandwidth with the WireGuard router, but with the official kernel implementation I get around 20MB/s for the same endpoint.

$ sftp user@192.168.4.2
# 20MB/s

$ sftp -P 2222 user@127.0.0.1
# onetun: 2.4MB/s

Parity with the kernel is not a goal since userspace will be a bit slower, but I would like to aim for something like ~50% instead of ~10%.

zonyitoo commented 2 years ago

Hello @aramperes , I may have encountered the same issue with smoltcp which have a lot smaller bandwidth than system network stack. Do you think the key problem is in smoltcp's design or there are any possible improvements could be done in application?

aramperes commented 2 years ago

@zonyitoo A few thoughts:

https://github.com/aramperes/onetun/blob/648154b5ee89b4311f24a4827847ead765e8533f/src/virtual_device.rs#L28-L41

jkcoxson commented 2 years ago

Would this benefit from removing Tokio completely and switching to crossbeam? That should keep the architecture intact, but I don’t know how much that would improve performance.

Alternatively, crossfire should be an almost drop in replacement for Tokio’s broadcast while not having to remove the async runtime. It boasts higher speeds on its readme compared to even Tokio’s single consumer channels.

aramperes commented 2 years ago

Moving away from Tokio/async may indeed be an option, however I would need to see clear benefits/benchmarks before making that decision. Maybe it's something worth testing in a branch. Either way, I don't think this would solve the locking issue in the Device implementation, which I suspect is the main bottleneck.

crossfire doesn't seem maintained enough for me to make the switch, and hasn't been udpated past Tokio 0.2.