2 # Copyright (c) 2018 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.
18 WRK_TAR=${WRK_VERSION}".tar.gz"
19 WRK_DWNLD_PATH="https://github.com/wg/wrk/archive"
21 WRK_INSTALL_DIR=${WRK_TARGET}/wrk-${WRK_VERSION}
23 function wrk_utils.install {
28 # Force the installation:
31 # Check if wrk is installed:
32 if [ "${force}" = true ]; then
37 test -d ${dir}/${WRK_INSTALL_DIR} && echo "WRK already installed: ${dir}/${WRK_INSTALL_DIR}" && exit 0
41 # Install pre-requisites:
43 apt-get install build-essential libssl-dev -y
45 # Remove previous installation:
48 # Change the directory:
51 # Get the specified version:
52 wget ${WRK_DWNLD_PATH}/${WRK_TAR}
60 # Move the executable to somewhere in the PATH:
64 function wrk_utils.destroy {
67 sudo rm /usr/local/bin/wrk || true
68 sudo rm -rf ${WRK_INSTALL_DIR} || true
71 function wrk_utils.traffic_1_url_1_core {
74 # - using n instances of wrk, each on separate core.
76 # The CPU used for wrk
78 # Total number of threads to use by one instance of wrk to send traffic.
80 # Total number of HTTP connections to keep open with each thread handling
81 # N = connections / threads.
83 # Duration of the test.
85 # HTTP header to add to request.
87 # Record a timeout if a response is not received within this amount of time.
89 # Path to LuaJIT script.
91 # Print detailed latency statistics.
93 # URL to send the traffic to.
96 if [ "${timeout}" != "None" ]; then
97 timeout="--timeout ${timeout}"
102 if [ "${latency}" = "True" ]; then
108 if [ "${script}" != "None" ]; then
109 script="--script '${script}'"
114 if [ "${header}" != "None" ]; then
120 taskset --cpu-list ${cpu} \
121 wrk --threads ${threads} \
122 --connections ${connections} \
123 --duration ${duration} \
124 --header "${header}" \
131 function wrk_utils.traffic_n_urls_n_cores {
134 # - using n instances of wrk, each on separate core.
136 # The first CPU used for wrk
138 # Total number of threads to use by one instance of wrk to send traffic.
140 # Total number of HTTP connections to keep open with each thread handling
141 # N = connections / threads.
143 # Duration of the test.
145 # HTTP header to add to request.
147 # Record a timeout if a response is not received within this amount of time.
149 # Path to LuaJIT script.
151 # Print detailed latency statistics.
153 # URL to send the traffic to.
156 if [ "${timeout}" != "None" ]; then
157 timeout="--timeout ${timeout}"
162 if [ "${latency}" = "True" ]; then
168 if [ "${script}" != "None" ]; then
169 script="--script '${script}'"
174 if [ "${header}" != "None" ]; then
180 urls=$(echo ${urls} | tr ";" "\n")
182 for url in ${urls}; do
183 taskset --cpu-list ${cpu} \
184 wrk --threads ${threads} \
185 --connections ${connections} \
186 --duration ${duration} \
187 --header "${header}" \
199 function wrk_utils.traffic_n_urls_m_cores {
202 # - using m instances of wrk, each on separate core.
204 # The first CPU used for wrk
206 # The last CPU used for wrk
208 # Total number of threads to use by one instance of wrk to send traffic.
210 # Total number of HTTP connections to keep open with each thread handling
211 # N = connections / threads.
213 # Duration of the test.
215 # HTTP header to add to request.
217 # Record a timeout if a response is not received within this amount of time.
219 # Path to LuaJIT script.
221 # Print detailed latency statistics.
223 # URL to send the traffic to.
226 if [ "${timeout}" != "None" ]; then
227 timeout="--timeout ${timeout}"
232 if [ "${latency}" = "True" ]; then
238 if [ "${script}" != "None" ]; then
239 script="--script '${script}'"
244 if [ "${header}" != "None" ]; then
250 urls=$(echo ${urls} | tr ";" "\n")
253 for i in `seq 1 ${cpus_per_url}`; do
254 for url in ${urls}; do
255 taskset --cpu-list ${cpu} \
256 wrk --threads ${threads} \
257 --connections ${connections} \
258 --duration ${duration} \
259 --header "${header}" \
276 wrk_utils.install ${force}
281 traffic_1_url_1_core)
282 wrk_utils.traffic_1_url_1_core "${args[@]:1}"
284 traffic_n_urls_n_cores)
285 wrk_utils.traffic_n_urls_n_cores "${args[@]:1}"
287 traffic_n_urls_m_cores)
288 wrk_utils.traffic_n_urls_m_cores "${args[@]:1}"