Add script to delete state from S3 for benchmarking cleanup.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 10 Feb 2011 00:31:51 +0000 (16:31 -0800)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 10 Feb 2011 00:31:51 +0000 (16:31 -0800)
microbench/setup/s3-cleanup.py [new file with mode: 0755]

diff --git a/microbench/setup/s3-cleanup.py b/microbench/setup/s3-cleanup.py
new file mode 100755 (executable)
index 0000000..ab465e8
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+#
+# Delete all files on S3 used for a benchmarking run (we don't want to be
+# charged for storage of them).
+
+import boto, sys, time, Queue
+from boto.s3.connection import SubdomainCallingFormat
+from threading import Lock, Thread
+
+if len(sys.argv) > 1:
+    bucket_name = sys.argv[1]
+else:
+    bucket_name = 'mvrable-bluesky'
+
+DELAY = 4.0
+print "Will delete all contents of %s starting in %s seconds..." \
+        % (bucket_name, DELAY)
+time.sleep(DELAY)
+
+THREADS = 32
+print "Using %d threads" % (THREADS,)
+
+q = Queue.Queue(THREADS * 4096)
+l = Lock()
+
+def deletion_task():
+    conn = boto.connect_s3()
+    bucket = conn.get_bucket(bucket_name)
+    while True:
+        k = q.get()
+        l.acquire()
+        print k
+        l.release()
+        bucket.delete_key(k)
+        q.task_done()
+
+for i in range(THREADS):
+    t = Thread(target=deletion_task)
+    t.setDaemon(True)
+    t.start()
+
+conn = boto.connect_s3(is_secure=False,
+                       calling_format=SubdomainCallingFormat())
+bucket = conn.get_bucket(bucket_name)
+for k in bucket:
+    q.put(k.key)
+
+q.join()
+time.sleep(0.5)
+
+print "Finished"