2 # Copyright (c) 2019 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 function wrk_utils.installed {
19 # Check if the WRK utility is installed. Fail if not installed.
22 # - 0 - If command is installed.
23 # - 1 - If command is not installed.
31 function wrk_utils.traffic_1_url_1_core {
34 # - using n instances of wrk, each on separate core.
36 # The CPU used for wrk
38 # Total number of threads to use by one instance of wrk to send traffic.
40 # Total number of HTTP connections to keep open with each thread handling
41 # N = connections / threads.
43 # Duration of the test.
45 # HTTP header to add to request.
47 # Record a timeout if a response is not received within this amount of time.
49 # Path to LuaJIT script.
51 # Print detailed latency statistics.
53 # URL to send the traffic to.
56 if [ "${timeout}" != "None" ]; then
57 timeout="--timeout ${timeout}"
62 if [ "${latency}" = "True" ]; then
68 if [ "${script}" != "None" ]; then
69 script="--script '${script}'"
74 if [ "${header}" != "None" ]; then
80 taskset --cpu-list ${cpu} \
81 wrk --threads ${threads} \
82 --connections ${connections} \
83 --duration ${duration} \
84 --header "${header}" \
91 function wrk_utils.traffic_n_urls_n_cores {
94 # - using n instances of wrk, each on separate core.
96 # The first CPU used for wrk
98 # Total number of threads to use by one instance of wrk to send traffic.
100 # Total number of HTTP connections to keep open with each thread handling
101 # N = connections / threads.
103 # Duration of the test.
105 # HTTP header to add to request.
107 # Record a timeout if a response is not received within this amount of time.
109 # Path to LuaJIT script.
111 # Print detailed latency statistics.
113 # URL to send the traffic to.
116 if [ "${timeout}" != "None" ]; then
117 timeout="--timeout ${timeout}"
122 if [ "${latency}" = "True" ]; then
128 if [ "${script}" != "None" ]; then
129 script="--script '${script}'"
134 if [ "${header}" != "None" ]; then
140 urls=$(echo ${urls} | tr ";" "\n")
142 for url in ${urls}; do
143 taskset --cpu-list ${cpu} \
144 wrk --threads ${threads} \
145 --connections ${connections} \
146 --duration ${duration} \
147 --header "${header}" \
159 function wrk_utils.traffic_n_urls_m_cores {
162 # - using m instances of wrk, each on separate core.
164 # The first CPU used for wrk
166 # The last CPU used for wrk
168 # Total number of threads to use by one instance of wrk to send traffic.
170 # Total number of HTTP connections to keep open with each thread handling
171 # N = connections / threads.
173 # Duration of the test.
175 # HTTP header to add to request.
177 # Record a timeout if a response is not received within this amount of time.
179 # Path to LuaJIT script.
181 # Print detailed latency statistics.
183 # URL to send the traffic to.
186 if [ "${timeout}" != "None" ]; then
187 timeout="--timeout ${timeout}"
192 if [ "${latency}" = "True" ]; then
198 if [ "${script}" != "None" ]; then
199 script="--script '${script}'"
204 if [ "${header}" != "None" ]; then
210 urls=$(echo ${urls} | tr ";" "\n")
213 for i in `seq 1 ${cpus_per_url}`; do
214 for url in ${urls}; do
215 taskset --cpu-list ${cpu} \
216 wrk --threads ${threads} \
217 --connections ${connections} \
218 --duration ${duration} \
219 --header "${header}" \
237 traffic_1_url_1_core)
238 wrk_utils.traffic_1_url_1_core "${args[@]:1}"
240 traffic_n_urls_n_cores)
241 wrk_utils.traffic_n_urls_n_cores "${args[@]:1}"
243 traffic_n_urls_m_cores)
244 wrk_utils.traffic_n_urls_m_cores "${args[@]:1}"