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 """spam.py spams stdout for load testing the stdout handler.
8 To use on the server, use:
9 export ISOLATE=https://your-server.appspot.com
10 export SWARMING=https://your-server.appspot.com
11 ../isolate.py archive -I $ISOLATE -i spam.isolate -s spam.isolated
12 # Where Linux can also be Mac or Windows.
13 ../swarming.py run -I $ISOLATE -S $SWARMING spam.isolated -d os Linux \
14 --priority 10 -- --duration 600 --sleep 0.5 --size 1024
16 ./run_on_bot.py can also be used to trigger systematically on all bots.
25 parser = optparse.OptionParser(
26 description=sys.modules[__name__].__doc__, usage='%prog [options]')
27 parser.format_description = lambda _: parser.description
29 '--duration', type='float', default=5., help='Duration in seconds')
31 '--sleep', type='float', default=1.,
32 help='Sleep in seconds between burst')
34 '--size', type='int', default=10, help='Data written at each burst')
35 options, args = parser.parse_args()
37 parser.error('Unknown args: %s' % args)
38 if options.duration <= 0:
39 parser.error('Invalid --duration')
41 parser.error('Invalid --sleep')
43 parser.error('Invalid --size')
45 print('Duration: %gs' % options.duration)
46 print('Sleep: %gs' % options.sleep)
47 print('Bursts size: %d' % options.size)
49 end = start + options.duration
52 sys.stdout.write(str(index) * (options.size - 1))
53 sys.stdout.write('\n')
56 time.sleep(options.sleep)
57 index = (index + 1) % 10
61 if __name__ == '__main__':