-
Notifications
You must be signed in to change notification settings - Fork 27
/
entrypoint.sh
executable file
·211 lines (163 loc) · 5.87 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
set -e
NOW=$(date +"%Y%m%d-%H%M%S")
JMETER_HOME="/opt/jmeter/apache-jmeter"
java -version
if [ -z "${JMX_FOLDER}" ]; then
echo "Give at least the jmx parent folder name as parameter with"
echo "JMX_FOLDER=my-scenario docker-compose -p jmeter up -d"
exit 1
fi
source "/scenario/${JMX_FOLDER}/.env"
# Environment variable available :
if [ -z "${host}" ]; then
host=google.com
fi
if [ -z "${protocol}" ]; then
protocol=https
fi
if [ -z "${port}" ]; then
port=443
fi
if [ -z "${XMX}" ]; then
XMX="1g"
fi
if [ -z "${XMS}" ]; then
XMS="1g"
fi
# Copying JMX, modules files to bin folder
cp /scenario/modules/*.jmx "${JMETER_HOME}/bin"
cp "/scenario/${JMX_FOLDER}/${JMX_FOLDER}.jmx" "${JMETER_HOME}/bin"
# Setting report and log dir
LOGS_DIR="${JMETER_HOME}/logs/${JMX_FOLDER}"
RESULTS_DIR="${JMETER_HOME}/results/${JMX_FOLDER}"
RESULTS_FILE="${RESULTS_DIR}/${NOW}-load-test-${JMX_FOLDER}-result.csv"
# Preparing JMeter vars
JMX_FILE_PATH="${JMETER_HOME}/bin/${JMX_FOLDER}.jmx"
PARAM_HOSTS_ARGS="-Ghost=${host} -Gport=${port} -Gprotocol=${protocol}"
PARAM_USERS_ARGS="-Gthreads=${threads} -Gduration=${duration} -Grampup=${rampup} -Gjmx=${JMX_FOLDER}.jmx"
echo "server.rmi.ssl.disable=true" >> ${JMETER_HOME}/bin/jmeter.properties
# JVM args
JVM_ARGS="$JVM_ARGS -Duser.timezone=CET"
JVM_ARGS="$JVM_ARGS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false"
JVM_ARGS="$JVM_ARGS -Dcom.sun.management.jmxremote.authenticate=false"
JVM_ARGS="$JVM_ARGS -Dcom.sun.management.jmxremote.ssl=false"
JVM_ARGS="$JVM_ARGS -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -Xms${XMX} -Xmx${XMS} -XX:G1ReservePercent=20 -Xss256k"
export JVM_ARGS
# Runtime
CSV=$(find "/scenario/data" -type f -name "*.csv")
if [[ -z "${SLAVE}" ]]; then
# Building host list
START=1
END=${nbInjector}
i=${START}
HOST_LIST=()
while [[ ${i} -le ${END} ]]; do
# Warning, the below line could change depending the docker-compose version (could be _ separated instead of -)
HOST_LIST+=("jmeter-jmeter-slave-${i}")
i=$((i + 1))
done
echo "Injector hostname list : ${HOST_LIST[@]}"
# Building IP list of slaves
for HOST in "${HOST_LIST[@]}"; do
HOST_IP_LIST+=( "$(getent hosts "${HOST}" | awk -F" " '{print $1}')" )
done
echo "Injectors IP list : ${HOST_IP_LIST[@]}"
fi
if [[ -n "${CSV}" ]]; then
if [[ "${SLAVE}" -eq 1 ]]; then
IP=$(hostname -i)
echo "Slave at ${IP} is starting"
while ! ls /scenario/data/split/*${IP};
do
echo "Waiting for dataset to be splitted by controller "
sleep 2
done
for DATASET_FILE_PATH in $(ls /scenario/data/split/*"${IP}"); do
DATASET_FILE=$(basename "${DATASET_FILE_PATH}")
echo "copying ${DATASET_FILE_PATH} to ${JMETER_HOME}/${DATASET_FILE}/.${IP}"
cp "${DATASET_FILE_PATH}" "${JMETER_HOME}/bin/${DATASET_FILE/.${IP}/}"
done
ls -ltra ${JMETER_HOME}/bin/*.csv
else
echo "Found csv dataset to split: ${CSV}"
echo "Controller dataset management starting"
# Dataset splitting
mkdir -p "/scenario/data/split"
START=0
END=$((nbInjector -1))
i=${START}
# Splitting dataset to equal parts
for DATASET_FILE_PATH in $(ls /scenario/data/*.*); do
echo "Splitting ${DATASET_FILE_PATH}"
DATASET_FILE=$(basename "${DATASET_FILE_PATH}")
TOTAL_LINE=$(wc -l < "${DATASET_FILE_PATH}")
LINES_PER_FILES=$(((TOTAL_LINE + nbInjector - 1) / nbInjector))
split -d -a 1 -l ${LINES_PER_FILES} "${DATASET_FILE_PATH}" "/scenario/data/split/splitted_${DATASET_FILE}"
echo "Splitting folder content"
# Appending slave IP to dataset file
while [[ "${i}" -le ${END} ]]; do
echo "Generating dataset for ${HOST_IP_LIST[${i}]}"
mv "/scenario/data/split/splitted_${DATASET_FILE}${i}" "/scenario/data/split/${DATASET_FILE}.${HOST_IP_LIST[${i}]}"
i=$((i + 1))
done
done
fi
else
echo "No dataset found, starting JMeter..."
fi
if [[ "${SLAVE}" -eq 1 ]]; then
echo "Starting JMeter on slave ${IP}"
LOG_FILE="${LOGS_DIR}/jmeter-${IP}-${JMX_FOLDER}.jmx-${NOW}.log"
echo "Installing plugins for JMX ${JMX_FOLDER}.jmx"
${JMETER_HOME}/bin/PluginsManagerCMD.sh install-for-jmx "${JMX_FILE_PATH}"
set -x
${JMETER_HOME}/bin/jmeter \
-LINFO \
-j "${LOG_FILE}" \
-s \
-n \
-d "${JMETER_HOME}" \
-Gserver.exitaftertest=true \
${PARAM_HOSTS_ARGS} \
${PARAM_USERS_ARGS}
else
echo "Starting JMeter on controller"
echo "Waiting for injectors to start"
slave_array=(${HOST_IP_LIST[@]})
slave_num=${#slave_array[@]}
index=${slave_num}
while [ ${index} -gt 0 ]; do
for slave in ${slave_array[@]}; do
if echo 'test open port' 2>/dev/null > /dev/tcp/${slave}/1099
then
echo "${slave} ready"
slave_array=(${slave_array[@]/${slave}/})
index=$((index-1))
else
echo "${slave} not ready"
fi;
done;
echo 'Waiting for slave readiness'
sleep 2
done
printf -v SLAVE_IP_LIST '%s,' "${HOST_IP_LIST[@]}"
LOG_FILE="${LOGS_DIR}/jmeter-master-${JMX_FOLDER}.jmx-${NOW}.log"
mkdir -p "${RESULTS_DIR}"
echo "Slaves IP :"
echo "${SLAVE_IP_LIST::-1}"
set -x
${JMETER_HOME}/bin/jmeter \
-LINFO \
-X \
-d ${JMETER_HOME} \
-n -j ${LOG_FILE} \
-l "${RESULTS_FILE}" \
-R ${SLAVE_IP_LIST::-1} \
${PARAM_HOSTS_ARGS} \
${PARAM_USERS_ARGS} \
-t "${JMX_FILE_PATH}" \
-e \
-o "${RESULTS_DIR}/report-${JMX_FOLDER}-${NOW}"
trap "sh ${JMETER_HOME}/bin/stoptest.sh" EXIT
fi