rapiz1 / rathole

A lightweight and high-performance reverse proxy for NAT traversal, written in Rust. An alternative to frp and ngrok.
Apache License 2.0
9.32k stars 468 forks source link

Testing the localhost forwarding capabilities, the results seem unexpected. Local test: TCP forwarding speed is 13Gbps, without forwarding it’s 120Gbps, a significant difference. #378

Open zsinba opened 1 month ago

zsinba commented 1 month ago

I downloaded the source code and compiled it, then tried it on macOS. Download time: 2024-07-21 09:37:10 Compilation script: cargo build --release Compiled version: rathole v0.5.0-13-gbe14d12 Compiled file size: 3895544 Jul 21 09:21 rathole (3.7M Jul 21 09:21 rathole*) Test case: examples/iperf3 Server configuration (server.toml):

[server]
bind_addr = "0.0.0.0:2333"
default_token = "123"
[server.services.iperf3-udp]
type = "udp"
bind_addr = "0.0.0.0:5202"
[server.services.iperf3-tcp]
type = "tcp"
bind_addr = "0.0.0.0:5202"

Client configuration (client.toml):

[client]
remote_addr = "127.0.0.1:2333"
default_token = "123"
[client.services.iperf3-udp]
type = "udp"
local_addr = "127.0.0.1:5201"
[client.services.iperf3-tcp]
type = "tcp"
local_addr = "127.0.0.1:5201"

Server start command:

cd /rathole/target/release
./rathole -s ../../examples/iperf3/server.toml

Client start command:

cd rathole/target/release
./rathole -c ../../examples/iperf3/client.toml

iperf3 server startup:

iperf3-darwin -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

iperf3 client startup (with Rathole):

iperf3-darwin -c 127.0.0.1 -t 100 -p 5202

The result maintained a speed of around 13Gbps. Without Rathole forwarding, the startup command was:

iperf3-darwin -c 127.0.0.1 -t 100 -p 5201

The speed obtained was approximately 100Gbps. For UDP testing, after forwarding through Rathole, the speed was:

iperf3-darwin -c 127.0.0.1 -t 100 -p 5202 -u

The speed was only 1Mbps. Without Rathole, the UDP test command was:

iperf3-darwin -c 127.0.0.1 -t 100 -p 5201 -u

The speed was also 1Mbps, indicating that this might be the upper limit for UDP, and Rathole does not affect it. Question: When forwarding TCP, does the code limit the upper speed of the forwarding? Note: This is just a local test, so the significance is limited, but the limitations are evident.

Musixal commented 1 month ago

iperf3-darwin -c 127.0.0.1 -t 100 -p 5201 -u -b 10G

for UDP you must define the bitrate. The default bitrate is 1Mb/s