Skip to content

Commit

Permalink
Merge pull request kofemann#1 from paulmillar/development/add-no-parent
Browse files Browse the repository at this point in the history
Add --no-container option, support no directories
  • Loading branch information
kofemann authored May 23, 2018
2 parents ca21271 + 734242b commit d28e98b
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions mdbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
-d, --dirs <N> : number of generated directories to generate
-s, --size <N> : size of generated files in B/K/M/G
-n, --no-clean : do not delete created files and directories
--no-container : do not create the 'mdbench.<name>.<pid>' directory
-h, --help : help message
and PATH points to the directory where tests should run. Current directory
is used if not specified.
If number of generated directories is 0 then files are created within
the container directory ("mdbench.<name>.<pid>") or in PATH if
--no-container is specified.
The file size can be specified in human friendly format, e.g.: 1K, 256M. 4G.
'''

Expand Down Expand Up @@ -64,14 +69,20 @@ def make_dirs(root, count):
os.mkdir( gen_dir(root, i) )

def make_files(root, dir_count, file_count, size = 0):
for j in range(file_count):
for i in range(dir_count):
mkfile(gen_file( gen_dir(root, i), j ), size, 1024)
for j in range(file_count):
if dir_count > 0:
for i in range(dir_count):
mkfile(gen_file( gen_dir(root, i), j ), size, 1024)
else:
mkfile(gen_file(root, j), size, 1024)

def del_files(root, dir_count, file_count):
for i in range(dir_count):
for j in range(file_count):
os.remove(gen_file( gen_dir(root, i), j ))
for j in range(file_count):
if dir_count > 0:
for i in range(dir_count):
os.remove(gen_file( gen_dir(root, i), j ))
else:
os.remove(gen_file(root, j))

def del_dirs(root, count):
for i in range(count):
Expand All @@ -82,9 +93,13 @@ def stat_dirs(root, count):
os.stat( gen_dir(root, i) )

def stat_files(root, dir_count, file_count):
for i in range(dir_count):
for j in range(file_count):
os.stat(gen_file( gen_dir(root, i), j ))
for j in range(file_count):
if dir_count > 0:
for i in range(dir_count):
os.stat(gen_file( gen_dir(root, i), j ))
else:
os.stat(gen_file(root, j))


def mkfile(fname, size = 0, chunk = 65536, sync = False) :
n_chunks = size // chunk
Expand Down Expand Up @@ -128,10 +143,11 @@ def main():
file_count = FILE_COUNT
file_size = FILE_SIZE
cleanup = True
createContainer = True

try:
options, remainder = getopt.gnu_getopt(sys.argv[1:], 'f:d:s:nh', \
['files=','dirs=','size=','no-clean','help'])
['files=','dirs=','size=','no-clean','no-container','help'])
except getopt.GetoptError as err:
print str(err)
usage()
Expand All @@ -145,6 +161,8 @@ def main():
file_size = get_size(arg)
elif opt in ('-n', '--no-clean'):
cleanup = False
elif opt in ('--no-container'):
createContainer = False
elif opt in ('-h', '--help'):
usage()

Expand All @@ -153,31 +171,35 @@ def main():

path = remainder[0]

root = '%s/mdbench.%s.%d' % (path, socket.gethostname(), os.getpid())
root = '%s/mdbench.%s.%d' % (path, socket.gethostname(), os.getpid()) if createContainer else path

if createContainer:
os.mkdir(root)

os.mkdir(root)
elapsed, result = bench_run( make_dirs, root, dir_count )
in_sec = total_seconds(elapsed)
print '%.2f dir creates per second' % (dir_count/in_sec)

elapsed, result = bench_run( make_files, root, dir_count, file_count , file_size)
in_sec = total_seconds(elapsed)
print '%.2f file creates per second' % ((dir_count*file_count)/in_sec)
count = (dir_count if dir_count > 0 else 1) * file_count
print '%.2f file creates per second' % (count/in_sec)

elapsed, result = bench_run( stat_files, root, dir_count, file_count )
in_sec = total_seconds(elapsed)
print '%.2f file stats per second' % ((dir_count*file_count)/in_sec)
print '%.2f file stats per second' % (count/in_sec)

if cleanup:
elapsed, result = bench_run( del_files, root, dir_count, file_count )
in_sec = total_seconds(elapsed)
print '%.2f file removes per second' % ((dir_count*file_count)/in_sec)
print '%.2f file removes per second' % (count/in_sec)

elapsed, result = bench_run( del_dirs, root, dir_count )
in_sec = total_seconds(elapsed)
print '%.2f dir removes per second' % (dir_count/in_sec)

os.rmdir(root)
if createContainer:
os.rmdir(root)

if __name__ == '__main__':
main()

0 comments on commit d28e98b

Please sign in to comment.