3 # A simple benchmark for Blue Sky that will read and/or write a collection of
4 # files with a specified working set size, and measure the response time to do
7 import json, os, random, sys, threading, time
12 """Performs a mix of file system operations and records the performance."""
16 self.duration = 10.0 # Seconds for which to run
17 self.write_fraction = 0.3 # Fraction of operations which are writes
18 self.wss_count = 16 # Files in the working set
19 self.tot_count = 32 # Total number of files created
20 self.filesize = 32 * 1024 # Size of files to work with
21 self.target_ops = 2 # Target operations/second/thread
24 for i in range(self.tot_count):
25 filename = "file-%d" % (i,)
26 fp = open(filename, 'w')
27 fp.write('\0' * self.filesize)
31 stop_time = time.time() + self.duration
35 if time1 >= stop_time: break
36 info = self._operation()
38 self.stats.append((time1, time2 - time1, info))
40 delay = time1 + (1.0 / self.target_ops) - time2
41 if delay > 0: time.sleep(delay)
44 """Run a single file system test (i.e., read or write a file)."""
46 filename = "file-%d" % (random.randrange(self.wss_count),)
48 if random.uniform(0.0, 1.0) < self.write_fraction:
49 fp = open(filename, 'w')
50 fp.write('\0' * self.filesize)
52 return ('write', filename)
54 fp = open(filename, 'r')
57 return ('read', filename)
60 duration = max(x[0] for x in stats) - min(x[0] for x in stats)
61 latencies = [x[1] for x in stats]
63 print "Experiment duration:", duration
64 print "Operation count:", len(stats)
65 print "Latencies:", latencies
66 print "Average latency:", sum(latencies) / len(latencies)
68 if __name__ == '__main__':
71 for i in range(THREADS):
74 t = threading.Thread(target=w.run)
86 print json.dumps(results, indent=2)