From 6eb7e0619fa4676193de37c55bc492efda954aac Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Thu, 17 Mar 2011 02:59:19 -0700 Subject: [PATCH] Create a simple tool for measuring latencies of write operations There is no explicit sync, but NFS has an implicit one on file close() which should be good enough for benchmarking. --- microbench/writebench.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 microbench/writebench.py diff --git a/microbench/writebench.py b/microbench/writebench.py new file mode 100755 index 0000000..b480886 --- /dev/null +++ b/microbench/writebench.py @@ -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) -- 2.20.1