3 # Run a series of simple test requests against S3 for gathering some basic
7 from boto.s3.connection import SubdomainCallingFormat
8 from boto.s3.key import Key
9 import sys, threading, time
12 BUCKET_NAME = 'mvrable-benchmark-west'
13 SIZES = [64, 4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20, 32 << 20]
15 class S3TestConnection:
17 self.conn = boto.connect_s3(is_secure=False,
18 calling_format=SubdomainCallingFormat())
19 self.bucket = self.conn.get_bucket(BUCKET_NAME)
21 def put_object(self, name, 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)
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)
34 def parallel_get(name, connections, delay1=0.0):
35 print "Get: %s x %d" % (name, len(connections))
37 for i in range(len(connections)):
39 threads.append(threading.Thread(target=c.get_object, args=(name,)))
40 for i in range(len(threads)):
42 if i == 0: time.sleep(delay1)
43 for t in threads: t.join()
48 c = S3TestConnection()
49 for repeat in range(4):
51 #c.put_object('file-%d-%d' % (size, repeat), size)
54 c = S3TestConnection()
55 for repeat in range(4):
57 c.get_object('file-%d-%d' % (size, repeat))
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()
67 parallel_get('file-%d-%d' % (size, i), connections)
69 # Pass 1: Downloads in parallel, but downloads staggered so one request
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()
77 parallel_get('file-%d-%d' % (size, i), connections, delay1=1.0)