3 # Copyright (C) 2010 The Regents of the University of California
4 # Written by Michael Vrable <mvrable@cs.ucsd.edu>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of the University nor the names of its contributors
15 # may be used to endorse or promote products derived from this software
16 # without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Run a series of simple test requests against S3 for gathering some basic
31 # performance numbers.
34 from boto.s3.connection import SubdomainCallingFormat
35 from boto.s3.key import Key
38 BUCKET_NAME = 'mvrable-benchmark'
39 SIZES = [64, 4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20, 32 << 20]
41 class S3TestConnection:
43 self.conn = boto.connect_s3(is_secure=False,
44 calling_format=SubdomainCallingFormat())
45 self.bucket = self.conn.get_bucket(BUCKET_NAME)
47 def put_object(self, name, size):
49 k = Key(self.bucket, name)
50 start_time = time.time()
51 k.set_contents_from_string(buf)
52 print "%s: %f" % (name, time.time() - start_time)
54 def get_object(self, name):
55 k = Key(self.bucket, name)
56 start_time = time.time()
57 buf = k.get_contents_as_string()
58 print "%s: %f" % (name, time.time() - start_time)
60 class AzureTestConnection:
62 self.conn = azure.Connection()
64 def put_object(self, name, size):
66 start_time = time.time()
67 self.conn.make_request('/benchmark/' + name, 'PUT', buf,
68 {'x-ms-blob-type': 'BlockBlob'})
69 print "%s: %f" % (name, time.time() - start_time)
71 def get_object(self, name):
72 start_time = time.time()
73 self.conn.make_request('/benchmark/' + name, 'GET')
74 print "%s: %f" % (name, time.time() - start_time)
78 c = S3TestConnection()
79 for repeat in range(4):
81 c.put_object('file-%d-%d' % (size, repeat), size)
83 c = S3TestConnection()
84 for repeat in range(4):
86 c.get_object('file-%d-%d' % (size, repeat))
88 print "==== AZURE ===="
89 c = AzureTestConnection()
90 for repeat in range(4):
92 c.put_object('file-%d-%d' % (size, repeat), size)
94 c = AzureTestConnection()
95 for repeat in range(4):
97 c.get_object('file-%d-%d' % (size, repeat))
99 if __name__ == '__main__':
101 SIZES = [4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20]
102 PRIME = (1 << 20) + (1 << 10)
103 c = AzureTestConnection()
105 c.put_object('file-%d-%d' % (size, 0), size)
106 c.put_object('file-%d-%d' % (PRIME, 0), PRIME)
110 c = AzureTestConnection()
111 c.get_object('file-%d-%d' % (PRIME, 0))
113 c.get_object('file-%d-%d' % (size, 0))