Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / swarming_client / tools / gce_load_test_on_startup.sh
1 #!/bin/bash
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.
5
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.
9 #
10 # Please see https://developers.google.com/compute/docs/howtos/startupscript for
11 # more details on how to use this script.
12 #
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!
15
16 set -e
17
18 ## Settings
19
20 # Server to load test against. Please set to your server.
21 SERVER=https://CHANGE-ME-TO-PROPER-VALUE.appspot.com
22
23 # Source code to use.
24 REPO=https://code.google.com/p/swarming.client.git
25
26 # Once the tasks are completed, one can harvest the logs back:
27 #   scp "slave:/var/log/swarming/*.*" .
28 LOG=/var/log/swarming
29
30 # Delay to wait before starting each client load test. This soften the curve.
31 CLIENT_DELAY=60s
32
33
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
38
39 # It will end up in /client.
40 rm -rf swarming_client
41 git clone $REPO swarming_client
42 TOOLS_DIR=./swarming_client/tools
43 mkdir -p $LOG
44
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!
53
54 echo "1. Starting bots."
55 BOTS_PID=
56 # Each load test bot process creates multiple (default is 250) fake bots.
57 for i in {1..4}; do
58   $TOOLS_DIR/swarming_load_test_bot.py -S $SERVER --suffix $i \
59       --slaves 250 \
60       --dump=$LOG/bot$i.json > $LOG/bot$i.log 2>&1 &
61   BOT_PID=$!
62   echo "  Bot $i pid: $BOT_PID"
63   BOTS_PID="$BOTS_PID $BOT_PID"
64 done
65
66 echo "2. Starting clients."
67 # Each client will send by default 16 tasks/sec * 60 sec, so 16*60*4 = 3840
68 # tasks per VM.
69 CLIENTS_PID=
70 for i in {1..4}; do
71   echo "  Sleeping for $CLIENT_DELAY before starting client #$i"
72   sleep $CLIENT_DELAY
73   $TOOLS_DIR/swarming_load_test_client.py -S $SERVER \
74       --send-rate 16 \
75       --duration 60 \
76       --timeout 180 \
77       --concurrent 250 \
78       --dump=$LOG/client$i.json > $LOG/client$i.log 2>&1 &
79   CLIENT_PID=$!
80   echo "  Client $i pid: $CLIENT_PID"
81   CLIENTS_PID="$CLIENTS_PID $CLIENT_PID"
82 done
83
84 echo "3. Waiting for the clients to complete; $CLIENTS_PID"
85 for i in $CLIENTS_PID; do
86   echo "  Waiting for $i"
87   wait $i
88 done
89
90 echo "4. Sending a Ctrl-C to each bot process so they stop; $BOTS_PID"
91 for i in $BOTS_PID; do
92   kill $i
93 done
94
95 echo "5. Waiting for the bot processes to stop."
96 for i in $BOTS_PID; do
97   echo "  Waiting for $i"
98   wait $i || true
99 done
100
101 echo "6. Load test is complete."
102 touch $LOG/done