352cf9aa6561ae16c45037516dd7d6356e19f47f
[lttng-tools.git] / tests / regression / tools / streaming / test_high_throughput_limits
1 #!/bin/bash
2 #
3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
5 #
6 # SPDX-License-Identifier: LGPL-2.1-only
7
8 TEST_DESC="Streaming - High throughput with bandwidth limits"
9
10 CURDIR=$(dirname $0)/
11 TESTDIR=$CURDIR/../../..
12 NR_APP_ITER=10
13 NR_ITER=1000000
14 TESTAPP_PATH="$TESTDIR/utils/testapp"
15 TESTAPP_NAME="gen-ust-events"
16 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17 SESSION_NAME="high-throughput"
18 EVENT_NAME="tp:tptest"
19 SESSIOND_CTRL_PORT=5342
20 SESSIOND_DATA_PORT=5343
21 DEFAULT_IF="lo"
22
23 TRACE_PATH=$(mktemp -d)
24
25 NUM_TESTS=104
26
27 source $TESTDIR/utils/utils.sh
28
29 if [ ! -x "$TESTAPP_BIN" ]; then
30 BAIL_OUT "No UST events binary detected."
31 fi
32
33 function reset_bw_limit
34 {
35 tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1
36 return $?
37 }
38
39 function set_bw_limit
40 {
41 limit=$1
42 ctrlportlimit=$(($limit/10))
43 # failsafe to have at least 1kbit/s for control (in the case where $1 < 10)
44 [ $ctrlportlimit = 0 ] && ctrlportlimit=1
45 # if $1 < 10, we might bust the limit set here, but the
46 # parent qdisc (1:) will always limit us to the right max value
47 dataportlimit=$((9*${ctrlportlimit}))
48
49 diag "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data"
50
51 tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1
52 if [ $? -ne 0 ]; then
53 reset_bw_limit
54 return 1
55 fi
56
57 # the total bandwidth is the limit set by the user
58 tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1
59 if [ $? -ne 0 ]; then
60 reset_bw_limit
61 return 1
62 fi
63 # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port
64 tc class add dev $DEFAULT_IF parent 1:1 classid 1:10 htb rate ${ctrlportlimit}kbit ceil ${limit}kbit prio 1 >/dev/null 2>&1
65 if [ $? -ne 0 ]; then
66 reset_bw_limit
67 return 1
68 fi
69 # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused)
70 tc class add dev $DEFAULT_IF parent 1:1 classid 1:11 htb rate ${dataportlimit}kbit ceil ${limit}kbit prio 2 >/dev/null 2>&1
71 if [ $? -ne 0 ]; then
72 reset_bw_limit
73 return 1
74 fi
75
76 # filter to assign control traffic to the 1:10 class
77 tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:10 >/dev/null 2>&1
78 if [ $? -ne 0 ]; then
79 reset_bw_limit
80 return 1
81 fi
82 # filter to assign data traffic to the 1:11 class
83 tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:11 >/dev/null 2>&1
84 if [ $? -ne 0 ]; then
85 reset_bw_limit
86 return 1
87 fi
88
89 return 0
90 }
91
92 function create_lttng_session_with_uri
93 {
94 sess_name=$1
95 uri=$2
96 # Create session with custom URI
97 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1
98 ok $? "Create session with uri $uri"
99 }
100
101 function run_apps
102 {
103 for i in `seq 1 $NR_APP_ITER`; do
104 # With bandwidth limitation, unfortunately, application easily timeout
105 # due to very slow communication between the consumer and relayd making
106 # the status reply from the consumer quite slow thus delaying the
107 # registration done message.
108 LTTNG_UST_REGISTER_TIMEOUT=-1 $TESTAPP_BIN -i $NR_ITER & >/dev/null 2>&1
109 done
110 }
111
112 function test_high_throughput
113 {
114 NETWORK_URI="net://localhost"
115 create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI
116 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
117 start_lttng_tracing_ok $SESSION_NAME
118 run_apps
119 diag "Waiting for applications to end"
120 wait
121 pass "waiting done"
122 stop_lttng_tracing_ok $SESSION_NAME
123 destroy_lttng_session_ok $SESSION_NAME
124 validate_event_count
125 }
126
127 function validate_event_count
128 {
129
130 TEMP_FILE=$(mktemp)
131 TEMP_FILE_2=$(mktemp)
132
133 traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l)
134 babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2
135
136 cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE
137
138 dropped=0
139 while read line;
140 do
141 let dropped=$dropped+$line
142 done < $TEMP_FILE
143
144 let total=$dropped+$traced
145 let wanted=$NR_APP_ITER*$NR_ITER
146
147 if [ $wanted -ne $total ]; then
148 fail "Validate trace event count"
149 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
150 return 1
151 else
152 pass "Validate trace event count"
153 diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... "
154
155 rm -rf $TRACE_PATH
156 rm $TEMP_FILE $TEMP_FILE_2
157
158 return 0
159 fi
160 }
161
162 function interrupt_cleanup()
163 {
164 diag "*** Exiting ***"
165 reset_bw_limit
166 # invoke utils cleanup
167 full_cleanup
168 }
169
170 plan_tests $NUM_TESTS
171
172 print_test_banner "$TEST_DESC"
173
174 if [ "$(id -u)" == "0" ]; then
175 isroot=1
176 else
177 isroot=0
178 fi
179
180 skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS ||
181 {
182
183 # Catch sigint and try to cleanup limits
184 trap interrupt_cleanup SIGTERM SIGINT
185
186 BW_LIMITS=(3200 1600 800 400 200 100 50 25)
187 for BW in ${BW_LIMITS[@]};
188 do
189 diag "Test high-throughput with bandwidth limit set to ${BW}kbits"
190
191 set_bw_limit $BW
192 ok $? "Setting bandwidth limit"
193
194 start_lttng_sessiond
195 start_lttng_relayd "-o $TRACE_PATH"
196 test_high_throughput
197 result=$?
198 stop_lttng_relayd
199 stop_lttng_sessiond
200 reset_bw_limit
201 ok $? "Reset bandwith limits"
202 done
203 }
This page took 0.033748 seconds and 3 git commands to generate.