Add a few more test scripts.
[bluesky.git] / cloudbench / paralleltest.py
1 #!/usr/bin/python
2 #
3 # Run a series of simple test requests against S3 for gathering some basic
4 # performance numbers.
5
6 import boto, time
7 from boto.s3.connection import SubdomainCallingFormat
8 from boto.s3.key import Key
9 import sys, threading, time
10 import azure
11
12 BUCKET_NAME = 'mvrable-benchmark-west'
13 SIZES = [64, 4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20, 32 << 20]
14
15 class S3TestConnection:
16     def __init__(self):
17         self.conn = boto.connect_s3(is_secure=False,
18                                     calling_format=SubdomainCallingFormat())
19         self.bucket = self.conn.get_bucket(BUCKET_NAME)
20
21     def put_object(self, name, size):
22         buf = 'A' * size
23         k = Key(self.bucket, name)
24         start_time = time.time()
25         k.set_contents_from_string(buf)
26         print "%s: %f" % (name, time.time() - start_time)
27
28     def get_object(self, name):
29         k = Key(self.bucket, name)
30         start_time = time.time()
31         buf = k.get_contents_as_string()
32         print "%s: %f" % (name, time.time() - start_time)
33
34 def parallel_get(name, connections, delay1=0.0):
35     print "Get: %s x %d" % (name, len(connections))
36     threads = []
37     for i in range(len(connections)):
38         c = connections[i]
39         threads.append(threading.Thread(target=c.get_object, args=(name,)))
40     for i in range(len(threads)):
41         threads[i].start()
42         if i == 0: time.sleep(delay1)
43     for t in threads: t.join()
44     time.sleep(1.0)
45
46 def run_test():
47     print "==== S3 ===="
48     c = S3TestConnection()
49     for repeat in range(4):
50         for size in SIZES:
51             #c.put_object('file-%d-%d' % (size, repeat), size)
52             pass
53
54     c = S3TestConnection()
55     for repeat in range(4):
56         for size in SIZES:
57             c.get_object('file-%d-%d' % (size, repeat))
58
59 if __name__ == '__main__':
60     # Pass 1: Identical downloads in parallel
61     connections = [S3TestConnection() for _ in range(8)]
62     SIZES = [4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20]
63     PRIME = (1 << 20) + (1 << 10)
64     c = S3TestConnection()
65     for size in SIZES:
66         for i in range(32):
67             parallel_get('file-%d-%d' % (size, i), connections)
68
69     # Pass 1: Downloads in parallel, but downloads staggered so one request
70     # arrives earlier
71     connections = [S3TestConnection() for _ in range(8)]
72     SIZES = [4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20]
73     PRIME = (1 << 20) + (1 << 10)
74     c = S3TestConnection()
75     for size in SIZES:
76         for i in range(32):
77             parallel_get('file-%d-%d' % (size, i), connections, delay1=1.0)