Create a simple tool for measuring latencies of write operations
authorMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 17 Mar 2011 09:59:19 +0000 (02:59 -0700)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 17 Mar 2011 09:59:19 +0000 (02:59 -0700)
There is no explicit sync, but NFS has an implicit one on file close()
which should be good enough for benchmarking.

microbench/writebench.py [new file with mode: 0755]

diff --git a/microbench/writebench.py b/microbench/writebench.py
new file mode 100755 (executable)
index 0000000..b480886
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+#
+# A small synthetic write benchmark for BlueSky.  We want to see what happens
+# when there are write bursts that fill up the disk cache faster than it can be
+# drained to the cloud.  This tool simply writes out 1 MB files to a directory,
+# recording the time needed to write each one.  The rate at which files are
+# written out can be specified in files (/megabytes) per second.
+
+import os, sys, time
+
+DIRSIZE=100
+
+def write_file(path, n, size=1024**2):
+    buf = 'A' * size
+    try: os.mkdir('%s/%d' % (path, n // DIRSIZE))
+    except: pass
+    t1 = time.time()
+    f = open('%s/%d/%d' % (path, n // DIRSIZE, n), 'w')
+    f.write(buf)
+    f.close()
+    t2 = time.time()
+    return t2 - t1
+
+def run_writebench(path, rate):
+    count = 0
+    start_time = time.time()
+    last_time = start_time
+    latencies = []
+    while last_time < start_time + 30:
+        now = time.time()
+        next_time = start_time + (1.0/rate) * count
+        time.sleep(max(0.0, next_time - now))
+        last_time = time.time()
+        latencies.append(write_file(path, count))
+        #print "create(%d) = %s" % (count, latencies[-1])
+        print latencies[-1]
+        count += 1
+    return latencies
+
+if __name__ == '__main__':
+    rate = float(sys.argv[1])
+    latencies = run_writebench('.', rate)