Skip to content

Instantly share code, notes, and snippets.

@ShyamsundarR
Created February 22, 2017 12:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShyamsundarR/dfbc2e717ed64b466222aed6d3ae5bf7 to your computer and use it in GitHub Desktop.
Save ShyamsundarR/dfbc2e717ed64b466222aed6d3ae5bf7 to your computer and use it in GitHub Desktop.
Sharing some quick pyhton code hack done for testing Gluster 3.10 release
import getopt, sys, subprocess, socket, os, time
mount_point = "/gluster-mount"
def main():
global mount_point
try:
opts, args = getopt.getopt(sys.argv[1:], "n:s:f:vm:t:", ["help", "output="])
except getopt.GetoptError as err:
# print help information and exit:
print err # will print something like "option -a not recognized"
usage()
sys.exit(2)
output = None
verbose = False
for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-s", "--size"):
size = a
elif o in ("-f", "--files"):
files = a
elif o in ("-n", "--sample-size"):
sample_size = a
elif o in ("-t", "--threads"):
thread_count = a
elif o in ("-m", "--mount-point"):
mount_point = a
else:
assert False, "unhandled option"
# Use default of 4 for thread count
try:
thread_count
except NameError:
thread_count = 4
print "Arguments used --> verbose: " + str(verbose) + " size: " + str(size) + " files: " + str(files) + " sample-size: " + str(sample_size) + " threads: " + str(thread_count) + " mount-point: " + mount_point
# Get hostnames
try:
clients = os.environ['CLIENTS']
except KeyError:
print "The environment variable CLIENTS must be set and contain a space separated list of IPs or hostnames"
sys.exit(1)
try:
servers = os.environ['SERVERS']
except KeyError:
print "The environment variable SERVERS must be set and contain a space separated list of IPs or hostnames"
sys.exit(1)
number_threads = 0
client_list = ""
for host in clients.split(" "):
if number_threads == 0:
client_list = host
else:
client_list = client_list + "," + host
number_threads = number_threads + 1
number_threads = number_threads * 4
print "Number threads = " + str(number_threads)
print "Client list = " + client_list
failed_test = False
# mount point extend for new space to test
# Test file create and read, by one thread and one client
# small, 64KB, 10000 files
# medium, 10MB, 1000 files
# large, 1GB, 16 files
# cleanup between create runs (use get_samples)
# mount_point+/1C1T/[small|medium|large]
# Test file create and read, by 2 threads/client and 4 clients
# small, 64KB, 1250 files
# medium, 10MB, 125 files
# large, 1GB, 4 files
# cleanup between create runs (use get_samples)
# mount_point+/4C2T/[small|medium|large]
# readdirahead testing without cleaning up the cache
# Single client listing the contents without cleaning the cache
# File create: one thread and one client, small, 64KB, 10000 files
mysize = 64
myfiles = 10000
my_mount_point = str(mount_point) + "/1C1T/small"
my_client_list = "10.21.76.20"
print "Running smallfile single client, single thread create test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "create",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "y",
verbose, sample_size, "y", my_mount_point)
print "The results for smallfile creates are: " + str(result1)
average_smallfile_create_1c1t = find_average(result1)
# Smallfile read
print "Running smallfile read test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "read",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for smallfile reads are: " + str(result1)
average_smallfile_read_1c1t = find_average(result1)
# Smallfile ls -l, no cache drop
print "Running smallfile ls -l test. No cache drop"
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "ls-l",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "n",
verbose, sample_size, "n", my_mount_point)
print "The results for smallfile listing are: " + str(result1)
average_smallfile_ls_nocachedrop = find_average(result1)
# Smallfile ls -l, cache drop
print "Running smallfile ls -l test. Cache drop"
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "ls-l",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for smallfile listing are: " + str(result1)
average_smallfile_ls_cachedrop = find_average(result1)
# File create: one thread and one client, medium, 10MB, 1000 files
mysize = 10240
myfiles = 1000
my_mount_point = str(mount_point) + "/1C1T/medium"
print "Running mediumfile single client, single thread create test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "create",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "y",
verbose, sample_size, "y", my_mount_point)
print "The results for mediumfile creates are: " + str(result1)
average_mediumfile_create_1c1t = find_average(result1)
# Smallfile read
print "Running mediumfile read test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "read",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for mediumfile reads are: " + str(result1)
average_mediumfile_read_1c1t = find_average(result1)
# File create: one thread and one client, large, 1GB, 16 files
mysize = 1 * 1024 * 1024
myfiles = 16
my_mount_point = str(mount_point) + "/1C1T/large"
print "Running largefile single client, single thread create test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "create",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "y",
verbose, sample_size, "y", my_mount_point)
print "The results for largefile creates are: " + str(result1)
average_largefile_create_1c1t = find_average(result1)
# largefile read
print "Running largefile read test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "read",
"--threads", "1", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", my_client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for mediumfile reads are: " + str(result1)
average_largefile_read_1c1t = find_average(result1)
# File create: two thread and four client, small, 64KB, 1250 files
mysize = 64
myfiles = 1250
my_mount_point = str(mount_point) + "/4C2T/small"
print "Running smallfile 4 client, 2 thread create test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "create",
"--threads", "2", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", client_list], "y",
verbose, sample_size, "y", my_mount_point)
print "The results for smallfile creates are: " + str(result1)
average_smallfile_create_4c2t = find_average(result1)
# Smallfile read
print "Running smallfile read test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "read",
"--threads", "2", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for smallfile reads are: " + str(result1)
average_smallfile_read_4c2t = find_average(result1)
# File create: two thread and four client, medium, 10MB, 125 files
mysize = 10240
myfiles = 125
my_mount_point = str(mount_point) + "/4C2T/medium"
print "Running mediumfile 4 client, 2 thread create test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "create",
"--threads", "2", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", client_list], "y",
verbose, sample_size, "y", my_mount_point)
print "The results for mediumfile creates are: " + str(result1)
average_mediumfile_create_4c2t = find_average(result1)
# Smallfile read
print "Running mediumfile read test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "read",
"--threads", "2", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for mediumfile reads are: " + str(result1)
average_mediumfile_read_4c2t = find_average(result1)
# File create: two thread and four client, large, 1GB, 4 files
mysize = 1 * 1024 * 1024
myfiles = 4
my_mount_point = str(mount_point) + "/4C2T/large"
print "Running largefile 4 client, 2 thread create test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "create",
"--threads", "2", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", client_list], "y",
verbose, sample_size, "y", my_mount_point)
print "The results for largefile creates are: " + str(result1)
average_largefile_create_4c2t = find_average(result1)
# Smallfile read
print "Running largefile read test."
(result1, result2) = get_samples(["python",
"/root/smallfile/smallfile_cli.py", "--operation", "read",
"--threads", "2", "--file-size", str(mysize), "--files", str(myfiles),
"--top", str(my_mount_point), "--remote-pgm-dir", "/root/smallfile/", "--host-set", client_list], "n",
verbose, sample_size, "y", my_mount_point)
print "The results for largefile reads are: " + str(result1)
average_largefile_read_4c2t = find_average(result1)
# Print report
print "Gluster Benchmark Kit report for " + time.strftime("%I:%M:%S")
print "Smallfile Creates 1C1T " + "64KB" + " file size: " + str(average_smallfile_create_1c1t)
print "Smallfile Reads 1C1T " + "64KB" + " file size: " + str(average_smallfile_read_1c1t)
print "Mediumfile Creates 1C1T " + "10MB" + " file size: " + str(average_mediumfile_create_1c1t)
print "Mediumfile Reads 1C1T " + "10MB" + " file size: " + str(average_mediumfile_read_1c1t)
print "Largefile Creates 1C1T " + "1GB" + " file size: " + str(average_largefile_create_1c1t)
print "Largefile Reads 1C1T " + "1GB" + " file size: " + str(average_largefile_read_1c1t)
print "Smallfile Creates 4C2T " + "64KB" + " file size: " + str(average_smallfile_create_4c2t)
print "Smallfile Reads 4C2T " + "64KB" + " file size: " + str(average_smallfile_read_4c2t)
print "Mediumfile Creates 4C2T " + "10MB" + " file size: " + str(average_mediumfile_create_4c2t)
print "Mediumfile Reads 4C2T " + "10MB" + " file size: " + str(average_mediumfile_read_4c2t)
print "Largefile Creates 4C2T " + "1GB" + " file size: " + str(average_largefile_create_4c2t)
print "Largefile Reads 4C2T " + "1GB" + " file size: " + str(average_largefile_read_4c2t)
print "Smallfile ls -l " + "64KB" + " file size: " + str(average_smallfile_ls_nocachedrop)
print "Smallfile ls -l " + "64KB" + " file size: " + str(average_smallfile_ls_cachedrop)
if failed_test == True:
sys.exit(1)
else:
sys.exit(0)
def usage():
print "Gluster Benchmark Kit Options:"
print " -h --help Print gbench options."
print " -v Verbose Output."
print " -s --size Record size for large files, file size for small files."
print " -f --files The nuber of files to create for smallfile tests."
print " -n --sample-size The number of samples to collect for each test."
print "Example: GlusterBench.py -s 64 -f 10000 -n 5 -v\n"
def make_report(size, average_smallfile_create, average_smallfile_read, average_smallfile_ls):
print "Gluster Benchmark Kit report for " + time.strftime("%I:%M:%S")
print "Smallfile Creates " + str(size) + " file size: " + str(average_smallfile_create)
print "Smallfile Reads " + str(size) + " file size: " + str(average_smallfile_read)
print "Smallfile ls -l " + str(size) + " file size: " + str(average_smallfile_ls)
def run_command(command_in):
p = subprocess.Popen(command_in, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while(True):
retcode = p.poll() #returns None while subprocess is running
line = p.stdout.readline()
yield line
if(retcode is not None):
break
# extract result from iozone test in KB/sec
def extract_iozone_result(logfn):
logfn = logfn.splitlines(True)
result1 = None
result2 = None
for l in logfn:
if l.__contains__('Children see throughput'):
tokens = l.split()
tokenct = len(tokens)
assert str(tokens[tokenct-1]).upper() == 'KB/SEC' # line ends with 'KB/sec'
result = float(tokens[tokenct-2].strip())
if not result1: result1 = result
elif not result2: result2 = result
return (result1, result2)
def run_iozone(iozone_in):
output = ""
for line in run_command(iozone_in):
output = output + line
return output
# extract result from smallfile in file/sec
def extract_smallfile_result(logfn):
logfn = logfn.splitlines(True)
for l in logfn:
if l.__contains__('files/sec'):
tokens = l.split()
tokenct = len(tokens)
result = float(tokens[0].strip())
return result
def get_samples(command_in, cleanup, verbose, sample_size, drop_cache, mypath):
global mount_point
my_samples = []
my_samples2 = []
sample_number = int(sample_size)
if drop_cache == 'n':
sample_number = sample_number + 1
for x in range(0, sample_number):
print "About to gather sample --> " + str(x)
if verbose == True:
print "Running command --> " + str(command_in)
current_sample = run_iozone(command_in)
if "iozone" in command_in:
(result1, result2) = extract_iozone_result(current_sample)
else:
result1 = extract_smallfile_result(current_sample)
result2 = ""
if verbose == True:
print current_sample
if (drop_cache == 'y') or (x == (sample_number - 1)):
print "Adding the current sample to the list: " + str(result1)
my_samples.append(result1)
my_samples2.append(result2)
cmd = "sh /root/sync-drop-caches.sh"
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
print "Dropping cache"
while True:
out = p.stderr.read(1)
if out == '' and p.poll() != None:
break
if out != '':
sys.stdout.write(out)
sys.stdout.flush()
# no drop cache, first iteration builds the cache, so ignore its output
elif x != 0:
print "Adding the current sample to the list: " + str(result1)
my_samples.append(result1)
my_samples2.append(result2)
if x == (sample_number - 1):
print "No cleanup on " + str(x) + " iteration."
elif cleanup == "y":
cmd = "rm -rf " + str(mypath) + "/*"
print cmd
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
print "Cleaning up files."
while True:
out = p.stderr.read(1)
if out == '' and p.poll() != None:
break
if out != '':
sys.stdout.write(out)
sys.stdout.flush()
else:
pass
return (my_samples, my_samples2)
def find_average(samples_in):
length_in = len(samples_in)
total = 0
for x in range(0, length_in):
total = total + int(samples_in[x])
average = total / length_in
return average
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment