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
|
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
script_dir="$(realpath "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )")"
root_dir="$(realpath "${script_dir}/..")"
pushd "${root_dir}"
"${VIRTUAL_ENV}/bin/pip" install --editable .
popd
pushd "${script_dir}"
pids=()
function cleanup(){
for pid in ${pids}
do
echo "Killing worker with pid ${pid}"
kill -9 "${pid}" || echo "Failed killing worker with pid ${pid}"
done
}
trap cleanup EXIT
export LOCUST_WORKER_ADDITIONAL_WAIT_BEFORE_READY_AFTER_STOP=5
n_workers=4
for n in $(seq 1 ${n_workers})
do
tmp_file="$(mktemp /tmp/locust-worker-${n}.log.XXXXXX)"
echo "Starting worker ${n} (logs in ${tmp_file})"
"${VIRTUAL_ENV}/bin/python" -m locust \
--locustfile "${script_dir}/locustfile.py" \
--host "https://example.com" \
--worker \
--master-host "0.0.0.0" \
--master-port "5557" \
--logfile "${tmp_file}" \
--loglevel "DEBUG" &
pids+=($!)
done
echo "Starting master"
"${VIRTUAL_ENV}/bin/python" -m locust \
--locustfile "${script_dir}/locustfile.py" \
--host "https://example.com" \
--headless \
--master \
--master-bind-host "0.0.0.0" \
--master-bind-port "5557" \
--expect-workers ${n_workers} \
--loglevel "DEBUG"
popd
|