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