Make NFS rsize/wsize configurable in the microbenchmark runs.
[bluesky.git] / microbench / microbench.py
1 #!/usr/bin/python
2
3 import os, subprocess, sys, time
4
5 MNTDIR = '/mnt/bluesky'
6 SERVER = 'c09-45.sysnet.ucsd.edu'
7
8 class TestClient:
9     def setup_client(self, export):
10         print "Mounting file system..."
11         subprocess.check_call(['mount', '-t', 'nfs',
12                                '-o', 'vers=3,tcp,rw,soft,intr',
13                                export, MNTDIR])
14
15     def cleanup_client(self):
16         print "Unmounting file system..."
17         subprocess.check_call(['umount', '-f', MNTDIR])
18
19     def run(self, proc, args=(), export=(SERVER + ":/export")):
20         self.setup_client(export)
21         startdir = os.getcwd()
22         try:
23             os.chdir(MNTDIR)
24             results = proc(*args)
25         finally:
26             os.chdir(startdir)
27             self.cleanup_client()
28         return results
29
30 class TestCommands:
31     def serial_stat(self):
32         files = ["file-%d" % (i,) for i in range(8)]
33
34         times = []
35         for f in files:
36             start = time.time()
37             os.stat(f)
38             times.append(time.time() - start)
39
40         return times
41
42     def serial_read(self):
43         files = ["file-%d" % (i,) for i in range(8)]
44
45         times = []
46         for f in files:
47             start = time.time()
48             open(f).read()
49             times.append(time.time() - start)
50
51         return times
52
53     def serial_write(self):
54         files = ["write-%d" % (i,) for i in range(8)]
55
56         times = []
57         buf = "A" * 32768
58         for f in files:
59             start = time.time()
60             fp = open(f, 'w')
61             fp.write(buf)
62             fp.close()
63             times.append(time.time() - start)
64
65         return times
66
67     def large_write(self):
68         buf = "A" * 1048576
69
70         start = time.time()
71         fp = open("largefile", 'w')
72         for i in range(128): fp.write(buf)
73         fp.close()
74
75         return [time.time() - start]
76
77     def large_read(self):
78         buf = None
79
80         start = time.time()
81         fp = open("largefile")
82         while buf != "":
83             buf = fp.read(1048576)
84         fp.close()
85
86         return [time.time() - start]
87
88     def shell(self):
89         subprocess.call(['/bin/sh'])
90
91 if __name__ == '__main__':
92     cmd = sys.argv[1]
93     args = sys.argv[2:]
94     if not cmd.startswith("_"):
95         fun = getattr(TestCommands(), cmd)
96         client = TestClient()
97         result = client.run(fun, args)
98         print "Results:", result