3 # A small synthetic write benchmark for BlueSky. We want to see what happens
4 # when there are write bursts that fill up the disk cache faster than it can be
5 # drained to the cloud. This tool simply writes out 1 MB files to a directory,
6 # recording the time needed to write each one. The rate at which files are
7 # written out can be specified in files (/megabytes) per second.
13 def write_file(path, n, size=1024**2):
15 try: os.mkdir('%s/%d' % (path, n // DIRSIZE))
18 f = open('%s/%d/%d' % (path, n // DIRSIZE, n), 'w')
24 def run_writebench(path, rate):
26 start_time = time.time()
27 last_time = start_time
29 while last_time < start_time + 120:
31 next_time = start_time + (1.0/rate) * count
32 time.sleep(max(0.0, next_time - now))
33 last_time = time.time()
34 latencies.append(write_file(path, count))
35 print "%s\t%s" % (latencies[-1], time.time() - start_time)
37 end_time = time.time()
38 duration = end_time - start_time
39 print "# %s MB/s (%d MB/%s seconds)" % (count / duration, count, duration)
42 if __name__ == '__main__':
43 rate = float(sys.argv[1])
44 latencies = run_writebench('.', rate)