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
11 BUCKET_NAME = 'mvrable-benchmark'
12 SIZES = [64, 4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20, 32 << 20]
14 class S3TestConnection:
16 self.conn = boto.connect_s3(is_secure=False,
17 calling_format=SubdomainCallingFormat())
18 self.bucket = self.conn.get_bucket(BUCKET_NAME)
20 def put_object(self, name, size):
22 k = Key(self.bucket, name)
23 start_time = time.time()
24 k.set_contents_from_string(buf)
25 print "%s: %f" % (name, time.time() - start_time)
27 def get_object(self, name):
28 k = Key(self.bucket, name)
29 start_time = time.time()
30 buf = k.get_contents_as_string()
31 print "%s: %f" % (name, time.time() - start_time)
33 class AzureTestConnection:
35 self.conn = azure.Connection()
37 def put_object(self, name, size):
39 start_time = time.time()
40 self.conn.make_request('/benchmark/' + name, 'PUT', buf,
41 {'x-ms-blob-type': 'BlockBlob'})
42 print "%s: %f" % (name, time.time() - start_time)
44 def get_object(self, name):
45 start_time = time.time()
46 self.conn.make_request('/benchmark/' + name, 'GET')
47 print "%s: %f" % (name, time.time() - start_time)
51 c = S3TestConnection()
52 for repeat in range(4):
54 c.put_object('file-%d-%d' % (size, repeat), size)
56 c = S3TestConnection()
57 for repeat in range(4):
59 c.get_object('file-%d-%d' % (size, repeat))
61 print "==== AZURE ===="
62 c = AzureTestConnection()
63 for repeat in range(4):
65 c.put_object('file-%d-%d' % (size, repeat), size)
67 c = AzureTestConnection()
68 for repeat in range(4):
70 c.get_object('file-%d-%d' % (size, repeat))
72 if __name__ == '__main__':
74 SIZES = [4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20]
75 PRIME = (1 << 20) + (1 << 10)
76 c = AzureTestConnection()
78 c.put_object('file-%d-%d' % (size, 0), size)
79 c.put_object('file-%d-%d' % (PRIME, 0), PRIME)
83 c = AzureTestConnection()
84 c.get_object('file-%d-%d' % (PRIME, 0))
86 c.get_object('file-%d-%d' % (size, 0))