Last active
November 20, 2015 17:15
-
-
Save ChrisMacNaughton/9796425ca31b1b301dd9 to your computer and use it in GitHub Desktop.
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/bin/python | |
print "About to benchmark ceph" | |
import threading; | |
import subprocess; | |
import random; | |
import time; | |
import sys; | |
import re; | |
def create_testfile(size): | |
cmd = ["dd", "if=/dev/urandom", "of=testfile.txt", "bs={}".format(size), "count=1"] | |
subprocess.call(cmd) | |
def put(filename, blocksize): | |
cmd = ["rados", "-p", "data", "-b", "{}".format(blocksize), "put", filename, "testfile.txt"] | |
subprocess.call(cmd) | |
def get(filename): | |
cmd = ["rados", "-p", "data", "get", filename, "testout.txt"] | |
subprocess.call(cmd) | |
def rm(filename): | |
cmd = ["rados", "-p", "data", "rm", filename] | |
subprocess.call(cmd) | |
def bench(filename, num, blocksize): | |
print "Starting benchmark thread #{}".format(num) | |
time.sleep(random.randrange(1,20)) | |
i = 0 | |
while(True): | |
i = i + 1 | |
working_filename = "{}-thread-{}-{}".format(filename, num, i) | |
# print "About to put {}".format(working_filename) | |
put(working_filename, blocksize) | |
# print "About to get {}".format(working_filename) | |
get(working_filename) | |
# print "About to rm {}".format(working_filename) | |
rm(working_filename) | |
hostname = subprocess.check_output('hostname').strip() | |
filename = "test-{}".format(hostname) | |
size = sys.argv[1] # size is in MB | |
if size is None: | |
size = "1M"; | |
create_testfile(size); | |
threads_count = sys.argv[2]; | |
if threads_count is None: | |
threads_count = "16"; | |
size_without_letters = re.sub(r'\D', "", size) | |
blocksize = int(size_without_letters) * 1024 * 1024 | |
threads = [] | |
for i in range(int(threads_count)): | |
t = threading.Thread(target=bench, args=[filename, i, blocksize]) | |
threads.append(t) | |
t.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment