Directory reorganization.
[bluesky.git] / cloudbench / cloudtest.py
diff --git a/cloudbench/cloudtest.py b/cloudbench/cloudtest.py
new file mode 100755 (executable)
index 0000000..0755688
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+#
+# Run a series of simple test requests against S3 for gathering some basic
+# performance numbers.
+
+import boto, time
+from boto.s3.connection import SubdomainCallingFormat
+from boto.s3.key import Key
+import azure
+
+BUCKET_NAME = 'mvrable-benchmark'
+SIZES = [64, 4096, 32 << 10, 256 << 10, 1 << 20, 4 << 20, 32 << 20]
+
+class S3TestConnection:
+    def __init__(self):
+        self.conn = boto.connect_s3(is_secure=False,
+                                    calling_format=SubdomainCallingFormat())
+        self.bucket = self.conn.get_bucket(BUCKET_NAME)
+
+    def put_object(self, name, size):
+        buf = 'A' * size
+        k = Key(self.bucket, name)
+        start_time = time.time()
+        k.set_contents_from_string(buf)
+        print "%s: %f" % (name, time.time() - start_time)
+
+    def get_object(self, name, size):
+        k = Key(self.bucket, name)
+        start_time = time.time()
+        buf = k.get_contents_as_string()
+        print "%s: %f" % (name, time.time() - start_time)
+
+class AzureTestConnection:
+    def __init__(self):
+        self.conn = azure.Connection()
+
+    def put_object(self, name, size):
+        buf = 'A' * size
+        start_time = time.time()
+        self.conn.make_request('/benchmark/' + name, 'PUT', buf,
+                               {'x-ms-blob-type': 'BlockBlob'})
+        print "%s: %f" % (name, time.time() - start_time)
+
+    def get_object(self, name, size):
+        start_time = time.time()
+        self.conn.make_request('/benchmark/' + name, 'GET')
+        print "%s: %f" % (name, time.time() - start_time)
+
+def run_test():
+    print "==== S3 ===="
+    c = S3TestConnection()
+    for repeat in range(4):
+        for size in SIZES:
+            c.put_object('file-%d-%d' % (size, repeat), size)
+
+    c = S3TestConnection()
+    for repeat in range(4):
+        for size in SIZES:
+            c.get_object('file-%d-%d' % (size, repeat), size)
+
+    print "==== AZURE ===="
+    c = AzureTestConnection()
+    for repeat in range(4):
+        for size in SIZES:
+            c.put_object('file-%d-%d' % (size, repeat), size)
+
+    c = AzureTestConnection()
+    for repeat in range(4):
+        for size in SIZES:
+            c.get_object('file-%d-%d' % (size, repeat), size)
+
+if __name__ == '__main__':
+    run_test()