-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: multi-threaded UDP listeners
This commit adds the ability for STUNner to run UDP listeners over multiple parallel readloops. The idea is to create a configurable number of UDP server sockets using `SO_REUSEPORT` and spawn a separate goroutine to run a parallel readloop for each. The kernel will load-balance allocations across the sockets/readloops per the IP 5-tuple, so the same allocation will always stay at the same CPU. This allows UDP listeners to scale to multiple CPUs. Note that this is enabled only for UDP at the moment: TCP, TLS and DTLS listeners spawn a per-client readloop anyway. Also note that `SO_REUSEPORT` is not portable, so currently we enable this only for UNIX architectures. The feature is exposed via the command line flag `--udp-thread-num=<THREAD_NUMBER>` in `stunnerd`, and the `UDPListenerThreadNum` field of the `Options` struct in the lib. The commit also adds tests plus a benchmark script that tests `stunnerd` and `turncat` using iperf. Use `./benchmark.sh udp 16 8000000` to run a benchmark with a UDP listener running 16 readloops, and `./benchmark.sh tcp 0 8000000` for a simple TCP benchmark.
- Loading branch information
Showing
14 changed files
with
666 additions
and
494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
trap 'kill $(jobs -p)' EXIT | ||
RATE=1600 | ||
THREADS=0 | ||
|
||
[ -z "$1" ] && echo "usage: test2.sh <proto> [udp-thread-num] [PACKET-RATE]" && exit 1 | ||
[ -z "$1" ] || PROTO=$1 | ||
[ -z "$2" ] || THREADS=$2 | ||
[ -z "$3" ] || RATE=$3 | ||
|
||
go run cmd/stunnerd/main.go -l all:ERROR --udp-thread-num=${THREADS} turn://user:pass@127.0.0.1:5000?transport=${PROTO} & | ||
iperf -s -u -e -i 5 & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:4999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 4999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:5999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 5999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:6999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 6999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:7999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 7999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:8999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 8999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:9999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 9999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:10999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 10999 -t 0 -l 100 -b $RATE & | ||
|
||
go run cmd/turncat/main.go -l all:ERROR udp://127.0.0.1:11999 "turn://user:pass@127.0.0.1:5000?transport=${PROTO}" udp://localhost:5001 & | ||
iperf -c 127.0.0.1 -u -p 11999 -t 0 -l 100 -b $RATE | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.