Skip to content

Commit 4e561dd

Browse files
perf: allow running quinn-perf within dockers
1 parent d845f40 commit 4e561dd

File tree

7 files changed

+257
-0
lines changed

7 files changed

+257
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99

1010
cargo-test-*
1111
tarpaulin-report.html
12+
13+
perf/docker/work/
14+

perf/docker/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://hub.docker.com/_/debian
2+
FROM debian:bookworm-slim
3+
4+
RUN apt-get update && apt-get install -y procps iputils-ping iproute2 ethtool tcpdump
5+
6+
WORKDIR /root
7+
8+
RUN mkdir -p .local/share/quinn
9+
10+
COPY ./entrypoint.sh .
11+
12+
COPY ./target/quinn-perf .
13+
14+
ENTRYPOINT [ "/root/entrypoint.sh" ]

perf/docker/build.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env -S bash -eu
2+
3+
CURDIR=$(pwd)
4+
TOKIO_CONSOLE=0
5+
6+
function usage() {
7+
echo "usage: $0 [-t]"
8+
echo " -t enable tokio console"
9+
exit 1
10+
}
11+
12+
while getopts "t" opt; do
13+
case $opt in
14+
t) TOKIO_CONSOLE=1;;
15+
h) usage;;
16+
*) usage;;
17+
esac
18+
done
19+
20+
mkdir -p ./target
21+
22+
cd ../..
23+
24+
if [ ${TOKIO_CONSOLE} -eq 0 ]; then
25+
cargo build -p perf --release
26+
else
27+
echo "Building with tokio console support"
28+
RUSTFLAGS="--cfg tokio_unstable" cargo build -p perf -r -F tokio-console
29+
fi
30+
31+
32+
cp -au ./target/release/quinn-perf ${CURDIR}/target
33+
34+
cd ${CURDIR}
35+
docker compose build

perf/docker/docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
networks:
2+
quinn-perf:
3+
ipam:
4+
config:
5+
- subnet: 172.42.0.0/16
6+
7+
services:
8+
server:
9+
build: .
10+
image: quinn_perf
11+
networks:
12+
quinn-perf:
13+
ipv4_address: 172.42.0.2
14+
volumes:
15+
- ./work:/root/.local/share/quinn
16+
cap_add:
17+
- NET_ADMIN
18+
environment:
19+
- SSLKEYLOGFILE=/root/.local/share/quinn/server.key
20+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669 # tokio-console
21+
ports:
22+
- 6669:6669 # tokio-console
23+
24+
client:
25+
image: quinn_perf
26+
networks:
27+
quinn-perf:
28+
ipv4_address: 172.42.0.3
29+
volumes:
30+
- ./work:/root/.local/share/quinn
31+
cap_add:
32+
- NET_ADMIN
33+
environment:
34+
- SSLKEYLOGFILE=/root/.local/share/quinn/client.key
35+
- TOKIO_CONSOLE_BIND=0.0.0.0:6669 # tokio-console
36+
ports:
37+
- 6668:6669 # tokio-console
38+

perf/docker/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
while :; do sleep 10; done

perf/docker/run-client.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env -S bash -eu
2+
3+
SERVICE=client
4+
QUINN_PERF_CLIENT_ARGS="--keylog --duration 60 172.42.0.2:4433"
5+
6+
LATENCY=0
7+
LOSS=0
8+
GSO=0
9+
CAPTURE=0
10+
OPEN=0
11+
TOKIO_CONSOLE=0
12+
13+
function usage() {
14+
echo "usage: $0 [-cghot] [-l number] [-L number]"
15+
echo " -c enable packet capture"
16+
echo " -g enable GSO (default: disabled)"
17+
echo " -h display help"
18+
echo " -l number specify simulated latency in ms (default: ${LATENCY}ms)"
19+
echo " -L number specify simulated packet loss in percentage (default: ${LOSS}%)"
20+
echo " -o open packet capture"
21+
echo " -t attach to tokio console"
22+
exit 1
23+
}
24+
25+
while getopts "cghl:L:ot" opt; do
26+
case $opt in
27+
c) CAPTURE=1;;
28+
g) GSO=1;;
29+
l) LATENCY=$OPTARG;;
30+
L) LOSS=$OPTARG;;
31+
o) OPEN=1;;
32+
t) TOKIO_CONSOLE=1;;
33+
h) usage;;
34+
*) usage;;
35+
esac
36+
done
37+
38+
if [ ${TOKIO_CONSOLE} -eq 1 ]; then
39+
tokio-console http://127.0.0.1:6668
40+
exit 0
41+
fi
42+
43+
mkdir -p ./work
44+
45+
echo "Launching docker ${SERVICE}"
46+
docker compose up -d --force-recreate ${SERVICE}
47+
if [ "${LATENCY}" -ne "0" ] || [ "${LOSS}" -ne "0" ]; then
48+
echo "Enforcing a latency of ${LATENCY}ms and a packet loss of ${LOSS}%"
49+
docker compose exec -it ${SERVICE} tc qdisc add dev eth0 root netem delay "${LATENCY}ms" loss "${LOSS}%"
50+
fi
51+
52+
if [ ${GSO} -eq 0 ]; then
53+
# FIXME disable GSO due to this issue
54+
# https://gitlab.com/wireshark/wireshark/-/issues/19109
55+
docker compose exec -it ${SERVICE} ethtool -K eth0 tx-udp-segmentation off
56+
fi
57+
58+
if [ ${CAPTURE} -eq 1 ]; then
59+
echo "Starting capture within docker"
60+
docker compose exec -d ${SERVICE} tcpdump -ni eth0 -s0 -w /root/.local/share/quinn/${SERVICE}.pcap udp and port 4433
61+
fi
62+
63+
echo "Launching quinn perf client"
64+
docker compose exec -it ${SERVICE} /root/quinn-perf client ${QUINN_PERF_CLIENT_ARGS}
65+
66+
if [ ${CAPTURE} -eq 1 ]; then
67+
echo "Stopping capture within docker"
68+
docker compose exec -it ${SERVICE} killall -STOP tcpdump
69+
fi
70+
71+
if [ "${LATENCY}" -ne "0" ] || [ "${LOSS}" -ne "0" ]; then
72+
echo "Dumping QOS stats"
73+
docker compose exec -it ${SERVICE} tc -s qdisc ls dev eth0
74+
fi
75+
76+
if [ ${CAPTURE} -eq 1 ] && [ ${OPEN} -eq 1 ]; then
77+
wireshark -o tls.keylog_file:./work/${SERVICE}.key ./work/${SERVICE}.pcap
78+
fi

perf/docker/run-server.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env -S bash -eu
2+
3+
SERVICE=server
4+
QUINN_PERF_SERVER_ARGS="--keylog --listen 172.42.0.2:4433"
5+
6+
LATENCY=0
7+
LOSS=0
8+
GSO=0
9+
CAPTURE=0
10+
OPEN=0
11+
TOKIO_CONSOLE=0
12+
13+
function usage() {
14+
echo "usage: $0 [-cghot] [-l number] [-L number]"
15+
echo " -c enable packet capture"
16+
echo " -g enable GSO (default: disabled)"
17+
echo " -h display help"
18+
echo " -l number specify simulated latency in ms (default: ${LATENCY}ms)"
19+
echo " -L number specify simulated packet loss in percentage (default: ${LOSS}%)"
20+
echo " -o open packet capture"
21+
echo " -t attach to tokio console"
22+
exit 1
23+
}
24+
25+
while getopts "cghl:L:ot" opt; do
26+
case $opt in
27+
c) CAPTURE=1;;
28+
g) GSO=1;;
29+
l) LATENCY=$OPTARG;;
30+
L) LOSS=$OPTARG;;
31+
o) OPEN=1;;
32+
t) TOKIO_CONSOLE=1;;
33+
h) usage;;
34+
*) usage;;
35+
esac
36+
done
37+
38+
if [ ${TOKIO_CONSOLE} -eq 1 ]; then
39+
tokio-console http://127.0.0.1:6669
40+
exit 0
41+
fi
42+
43+
mkdir -p ./work
44+
45+
echo "Launching docker ${SERVICE}"
46+
docker compose up -d --force-recreate ${SERVICE}
47+
if [ "${LATENCY}" -ne "0" ] || [ "${LOSS}" -ne "0" ]; then
48+
echo "Enforcing a latency of ${LATENCY}ms and a packet loss of ${LOSS}%"
49+
docker compose exec -it ${SERVICE} tc qdisc add dev eth0 root netem delay "${LATENCY}ms" loss "${LOSS}%"
50+
fi
51+
52+
if [ ${GSO} -eq 0 ]; then
53+
# FIXME disable GSO due to this issue
54+
# https://gitlab.com/wireshark/wireshark/-/issues/19109
55+
docker compose exec -it ${SERVICE} ethtool -K eth0 tx-udp-segmentation off
56+
fi
57+
58+
if [ ${CAPTURE} -eq 1 ]; then
59+
echo "Starting capture within docker"
60+
docker compose exec -d ${SERVICE} tcpdump -ni eth0 -s0 -w /root/.local/share/quinn/${SERVICE}.pcap udp port 4433
61+
fi
62+
63+
echo "Launching quinn perf server"
64+
docker compose exec -d ${SERVICE} /root/quinn-perf server ${QUINN_PERF_SERVER_ARGS}
65+
66+
echo "Press Ctrl-C to stop server"
67+
( trap exit SIGINT ; read -r -d '' _ </dev/tty )
68+
69+
echo "Stopping server"
70+
docker compose exec -it ${SERVICE} killall -STOP quinn-perf
71+
72+
if [ ${CAPTURE} -eq 1 ]; then
73+
echo "Stopping capture within docker"
74+
docker compose exec -it ${SERVICE} killall -STOP tcpdump
75+
fi
76+
77+
if [ "${LATENCY}" -ne "0" ] || [ "${LOSS}" -ne "0" ]; then
78+
echo "Dumping QOS stats"
79+
docker compose exec -it ${SERVICE} tc -s qdisc ls dev eth0
80+
fi
81+
82+
docker compose down
83+
84+
if [ ${CAPTURE} -eq 1 ] && [ ${OPEN} -eq 1 ]; then
85+
wireshark -o tls.keylog_file:./work/${SERVICE}.key ./work/${SERVICE}.pcap
86+
fi

0 commit comments

Comments
 (0)