From: Michael Vrable Date: Thu, 17 Mar 2011 17:12:09 +0000 (-0700) Subject: Merge git+ssh://idril.vpn.vrable.net/home/mvrable/local/bluesky X-Git-Url: http://git.vrable.net/?p=bluesky.git;a=commitdiff_plain;h=1b57824ed22fb6a40a0f85e5cbc3b0a9538b08ec;hp=b0c6dd01d47fb4f5230af2af3700328f5dd53cd5 Merge git+ssh://idril.vpn.vrable.net/home/mvrable/local/bluesky --- diff --git a/microbench/writebench.py b/microbench/writebench.py new file mode 100755 index 0000000..4779955 --- /dev/null +++ b/microbench/writebench.py @@ -0,0 +1,41 @@ +#!/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 latencies[-1] + count += 1 + return latencies + +if __name__ == '__main__': + rate = float(sys.argv[1]) + latencies = run_writebench('.', rate)