]> git.meshlink.io Git - utcp/blob - benchmark-stream
Handle channel closure during a receive callback when the ringbuffer wraps.
[utcp] / benchmark-stream
1 #!/bin/bash
2 set -e
3
4 # Configuration
5 LOG_PREFIX=/dev/shm/benchmark-log
6
7 # Size in bytes
8 SIZE=2e6
9
10 # Rate of generated stream in bits/s
11 STREAMRATE=10e6
12
13 # Network parameters
14 # Some realistic values:
15 # - Gbit LAN connection: RATE=1gbit DELAY=0.4ms JITTER=0.04ms LOSS=0%
16 # - Fast WAN connection: RATE=100mbit DELAY=50ms JITTER=3ms LOSS=0%
17 # - 5GHz WiFi connection: RATE=90mbit DELAY=5ms JITTER=1ms LOSS=0%
18 RATE=100mbit
19 DELAY=10ms
20 JITTER=1ms
21 LOSS=0.1%
22
23 # Maximum achievable bandwidth is limited to BUFSIZE / (2 * DELAY)
24 # The Linux kernel has a default maximum send buffer of 4 MiB
25 #export BUFSIZE=4194304
26
27 # Require root permissions
28 if [ "$USER" != "root" ]; then
29         exec sudo "$0" "$@"
30 fi
31
32 # Remove old log files
33 rm -f $LOG_PREFIX-* 2>/dev/null
34
35 # Clean up old namespaces
36 ip link del utcp-left 2>/dev/null || true
37 ip link del utcp-right 2>/dev/null || true
38 ip netns delete utcp-left 2>/dev/null || true
39 ip netns delete utcp-right 2>/dev/null || true
40
41 # Set up the left namespace
42 ip netns add utcp-left
43 ip link add name utcp-left type veth peer name utcp-right
44 ip link set utcp-left netns utcp-left
45
46 ip netns exec utcp-left ethtool -K utcp-left tso off
47 ip netns exec utcp-left ip link set dev lo up
48 ip netns exec utcp-left ip addr add dev utcp-left 192.168.1.1/24
49 ip netns exec utcp-left ip link set utcp-left up
50
51 #ip netns exec utcp-left tc qdisc del dev utcp-left root
52 ip netns exec utcp-left tc qdisc add dev utcp-left root netem rate $RATE delay $DELAY $JITTER loss random $LOSS
53
54 # Set up the right namespace
55 ip netns add utcp-right
56 ip link set utcp-right netns utcp-right
57
58 ip netns exec utcp-right ethtool -K utcp-right tso off
59 ip netns exec utcp-right ip link set dev lo up
60 ip netns exec utcp-right ip addr add dev utcp-right 192.168.1.2/24
61 ip netns exec utcp-right ip link set utcp-right up
62
63 #ip netns exec utcp-right tc qdisc del dev utcp-right root
64 ip netns exec utcp-right tc qdisc add dev utcp-right root netem rate $RATE delay $DELAY $JITTER loss random $LOSS
65 # Test using kernel TCP
66 ip netns exec utcp-right tcpdump -i utcp-right -w $LOG_PREFIX-socat.pcap port 9999 2>/dev/null &
67 ip netns exec utcp-left socat TCP4-LISTEN:9999 - </dev/null | ./stream -r $STREAMRATE -t $SIZE -v &
68 sleep 0.1
69 ./stream -r $STREAMRATE -t $SIZE | ip netns exec utcp-right time socat - TCP4:192.168.1.1:9999 2>$LOG_PREFIX-socat-client.txt >/dev/null
70 sleep 0.1
71 kill $(jobs -p) 2>/dev/null
72
73 # Test using UTCP
74 ip netns exec utcp-right tcpdump -i utcp-right -w $LOG_PREFIX-utcp.pcap udp port 9999 2>/dev/null &
75 ip netns exec utcp-left ./test 9999 2>$LOG_PREFIX-server.txt </dev/null | ./stream -r $STREAMRATE -t $SIZE -v &
76 sleep 0.1
77 ./stream -r $STREAMRATE -t $SIZE | ip netns exec utcp-right time ./test 192.168.1.1 9999 2>$LOG_PREFIX-client.txt >/dev/null
78 sleep 0.1
79 kill $(jobs -p) 2>/dev/null
80
81 # Print timing statistics
82 echo "Regular TCP:"
83 tail -2 $LOG_PREFIX-socat-client.txt
84
85 echo
86 echo "UTCP:"
87 tail -3 $LOG_PREFIX-client.txt
88
89 # If sudo was used, ensure the log files can be read by the user
90 if [ -n "$SUDO_USER" ]; then
91         chown $SUDO_USER $LOG_PREFIX-*
92 fi