2 # Copyright 2014 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file.
6 # Script to be used on GCE slave startup to initiate a load test. Each VM will
7 # fire an equivalent number of bots and clients. Fine tune the value depending
8 # on what kind of load test is desired.
10 # Please see https://developers.google.com/compute/docs/howtos/startupscript for
11 # more details on how to use this script.
13 # The script may run as root, which is counter intuitive. We don't mind much
14 # because is deleted right after the load test, but still keep this in mind!
20 # Server to load test against. Please set to your server.
21 SERVER=https://CHANGE-ME-TO-PROPER-VALUE.appspot.com
24 REPO=https://code.google.com/p/swarming.client.git
26 # Once the tasks are completed, one can harvest the logs back:
27 # scp "slave:/var/log/swarming/*.*" .
30 # Delay to wait before starting each client load test. This soften the curve.
34 ## Actual work starts here.
35 # Installs python and git. Do not bail out if it fails, since we do want the
36 # script to be usable as non-root.
37 apt-get install -y git-core python || true
39 # It will end up in /client.
40 rm -rf swarming_client
41 git clone $REPO swarming_client
42 TOOLS_DIR=./swarming_client/tools
45 # This is assuming 8 cores system, so it's worth having 8 different python
46 # processes, 4 fake bots load processes, 4 fake clients load processes. Each
47 # load test process creates 250 instances. This gives us a nice 1k bots, 1k
48 # clients per VM which makes it simple to size the load test, want 20k bots and
49 # 20k clients? Fire 20 VMs. It assumes a high network throughput per host since
50 # 250 bots + 250 clients generates a fair amount of HTTPS requests. This is not
51 # a problem on GCE, these VMs have pretty high network I/O. This may not hold
52 # true on other Cloud Hosting provider. Tune accordingly!
54 echo "1. Starting bots."
56 # Each load test bot process creates multiple (default is 250) fake bots.
58 $TOOLS_DIR/swarming_load_test_bot.py -S $SERVER --suffix $i \
60 --dump=$LOG/bot$i.json > $LOG/bot$i.log 2>&1 &
62 echo " Bot $i pid: $BOT_PID"
63 BOTS_PID="$BOTS_PID $BOT_PID"
66 echo "2. Starting clients."
67 # Each client will send by default 16 tasks/sec * 60 sec, so 16*60*4 = 3840
71 echo " Sleeping for $CLIENT_DELAY before starting client #$i"
73 $TOOLS_DIR/swarming_load_test_client.py -S $SERVER \
78 --dump=$LOG/client$i.json > $LOG/client$i.log 2>&1 &
80 echo " Client $i pid: $CLIENT_PID"
81 CLIENTS_PID="$CLIENTS_PID $CLIENT_PID"
84 echo "3. Waiting for the clients to complete; $CLIENTS_PID"
85 for i in $CLIENTS_PID; do
86 echo " Waiting for $i"
90 echo "4. Sending a Ctrl-C to each bot process so they stop; $BOTS_PID"
91 for i in $BOTS_PID; do
95 echo "5. Waiting for the bot processes to stop."
96 for i in $BOTS_PID; do
97 echo " Waiting for $i"
101 echo "6. Load test is complete."