Created
July 4, 2012 16:08
-
-
Save duggan/3048076 to your computer and use it in GitHub Desktop.
Basic distributed filesystem write performance test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env python | |
import uuid | |
import time | |
import sys | |
import getopt | |
def main(): | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "fd:v", ["files=", "directory="]) | |
except getopt.GetoptError, err: | |
print str(err) | |
print usage() | |
sys.exit(2) | |
args = {} | |
for o,a in opts: | |
if o == "--files": | |
args[o] = int(a) | |
elif o == "--directory": | |
args[o] = str(a) | |
if "--files" not in args or "--directory" not in args: | |
print usage() | |
sys.exit(2) | |
total_start = time.time() | |
resultset = [] | |
failed_writes = 0 | |
for i in range(args['--files']): | |
id = uuid.uuid1() | |
filename = "%s/test_%s" % (args['--directory'], id) | |
print "writing to %s..." % filename | |
testdata = "content-%s" % id | |
start_time = time.time() | |
try: | |
with open(filename, 'w+') as f: | |
f.write(testdata) | |
except IOError as (errno, strerror): | |
failed_writes += 1 | |
single_write = float(time.time() - start_time) | |
print "Took %s seconds" % single_write | |
resultset.append(single_write) | |
print "\n----------------------------------------" | |
print "Files written: %d" % len(resultset) | |
print "Median write time: %.9f seconds" % median(resultset) | |
print "Fastest write: %.9f seconds" % min(float(n) for n in resultset) | |
print "Slowest write: %.9f seconds" % max(float(n) for n in resultset) | |
print "Failed writes: %d" % failed_writes | |
print "Total execution time: %.3f seconds" % (time.time() - total_start) | |
print "----------------------------------------" | |
def usage(program_name=None): | |
return """ | |
Usage: %s [arguments] | |
--files <int> Number of files to attempt writing. | |
--directory <string> Directory to write test files to. | |
""" % program_name | |
def median(pool): | |
copy = sorted(pool) | |
size = len(copy) | |
if size % 2 == 1: | |
return copy[(size - 1) / 2] | |
else: | |
return (copy[size/2 - 1] + copy[size/2]) / 2 | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment