Skip to content

Commit

Permalink
Allow running perf client and server within dockers
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-damiend committed Jan 12, 2024
1 parent 20dff91 commit 6419ae6
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Cargo.lock
.idea
.DS_Store
.vscode

perf/docker/work/
15 changes: 15 additions & 0 deletions perf/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://hub.docker.com/_/debian
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y procps iputils-ping iproute2 ethtool tcpdump

WORKDIR /root

RUN mkdir -p .local/share/quinn

COPY ./entrypoint.sh .

COPY ./target/perf_client .
COPY ./target/perf_server .

ENTRYPOINT [ "/root/entrypoint.sh" ]
12 changes: 12 additions & 0 deletions perf/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

CURDIR=$(pwd)

mkdir -p ./target

cd ../..
cargo build -p perf --release
cp -au ./target/release/perf_server ./target/release/perf_client ${CURDIR}/target

cd ${CURDIR}
docker compose build
33 changes: 33 additions & 0 deletions perf/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'

networks:
quinn-perf:
ipam:
config:
- subnet: 172.42.0.0/16

services:
server:
build: .
image: quinn_perf
networks:
quinn-perf:
ipv4_address: 172.42.0.2
volumes:
- ./work:/root/.local/share/quinn
cap_add:
- NET_ADMIN
environment:
- SSLKEYLOGFILE=/root/.local/share/quinn/server.key

client:
image: quinn_perf
networks:
quinn-perf:
ipv4_address: 172.42.0.3
volumes:
- ./work:/root/.local/share/quinn
cap_add:
- NET_ADMIN
environment:
- SSLKEYLOGFILE=/root/.local/share/quinn/client.key
3 changes: 3 additions & 0 deletions perf/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

while :; do sleep 10; done
62 changes: 62 additions & 0 deletions perf/docker/run-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

SERVICE=client
PERF_CLIENT_ARGS="--keylog --duration 5 172.42.0.2:4433"

LATENCY=0
CAPTURE=0
OPEN=0

function usage() {
echo "usage: $0 [-hco] [-l number]"
echo " -h display help"
echo " -c enable packet capture"
echo " -o open packet capture"
echo " -l number specify simulated latency in ms (default: ${LATENCY}ms)"
exit 1
}

while getopts "hcl:" opt; do
case $opt in
c) CAPTURE=1;;
o) OPEN=1;;
l) LATENCY=$OPTARG;;
h) usage;;
*) usage;;
esac
done

mkdir -p ./work

echo "Launching docker ${SERVICE}"
docker compose up -d --force-recreate ${SERVICE}
if [ ${LATENCY} -ne 0 ]; then
echo "Enforcing a latency of ${LATENCY}ms"
docker compose exec -it ${SERVICE} tc qdisc add dev eth0 root netem delay ${LATENCY}ms
fi

# FIXME disable GSO due to this issue
# https://gitlab.com/wireshark/wireshark/-/issues/19109
docker compose exec -it ${SERVICE} ethtool -K eth0 tx-udp-segmentation off

if [ ${CAPTURE} -eq 1 ]; then
echo "Starting capture within docker"
docker compose exec -d ${SERVICE} tcpdump -ni eth0 -s0 -w /root/.local/share/quinn/${SERVICE}.pcap udp and port 4433
fi

echo "Launching quinn perf client"
docker compose exec -it ${SERVICE} /root/perf_client ${PERF_CLIENT_ARGS}

if [ ${CAPTURE} -eq 1 ]; then
echo "Stopping capture within docker"
docker compose exec -it ${SERVICE} killall -STOP tcpdump
fi

if [ ${LATENCY} -ne 0 ]; then
echo "Dumping QOS stats"
docker compose exec -it ${SERVICE} tc -s qdisc ls dev eth0
fi

if [ ${CAPTURE} -eq 1 ] && [ ${OPEN} -eq 1 ]; then
wireshark -o tls.keylog_file:./work/${SERVICE}.key ./work/${SERVICE}.pcap
fi
71 changes: 71 additions & 0 deletions perf/docker/run-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

SERVICE=server
PERF_SERVER_ARGS="--keylog --listen 172.42.0.2:4433"

LATENCY=0
CAPTURE=0
OPEN=0

function usage() {
echo "usage: $0 [-hco] [-l number]"
echo " -h display help"
echo " -c enable packet capture"
echo " -o open packet capture"
echo " -l number specify simulated latency in ms (default: ${LATENCY}ms)"
exit 1
}

while getopts "hcl:o" opt; do
case $opt in
c) CAPTURE=1;;
o) OPEN=1;;
l) LATENCY=$OPTARG;;
h) usage;;
*) usage;;
esac
done

mkdir -p ./work

echo "Launching docker ${SERVICE}"
docker compose up -d --force-recreate ${SERVICE}
if [ ${LATENCY} -ne 0 ]; then
echo "Enforcing a latency of ${LATENCY}ms"
docker compose exec -it ${SERVICE} tc qdisc add dev eth0 root netem delay ${LATENCY}ms
fi


# FIXME disable GSO due to this issue
# https://gitlab.com/wireshark/wireshark/-/issues/19109
docker compose exec -it ${SERVICE} ethtool -K eth0 tx-udp-segmentation off

if [ ${CAPTURE} -eq 1 ]; then
echo "Starting capture within docker"
docker compose exec -d ${SERVICE} tcpdump -ni eth0 -s0 -w /root/.local/share/quinn/${SERVICE}.pcap udp port 4433
fi

echo "Launching quinn perf server"
docker compose exec -d ${SERVICE} /root/perf_server ${PERF_SERVER_ARGS}

echo "Press Ctrl-C to stop server"
( trap exit SIGINT ; read -r -d '' _ </dev/tty )

echo "Stopping server"
docker compose exec -it ${SERVICE} killall -STOP perf_${SERVICE}

if [ ${CAPTURE} -eq 1 ]; then
echo "Stopping capture within docker"
docker compose exec -it ${SERVICE} killall -STOP tcpdump
fi

if [ ${LATENCY} -ne 0 ]; then
echo "Dumping QOS stats"
docker compose exec -it ${SERVICE} tc -s qdisc ls dev eth0
fi

docker compose down

if [ ${CAPTURE} -eq 1 ] && [ ${OPEN} -eq 1 ]; then
wireshark -o tls.keylog_file:./work/${SERVICE}.key ./work/${SERVICE}.pcap
fi

0 comments on commit 6419ae6

Please sign in to comment.