Commit 1bf23c12 authored by Douglas's avatar Douglas

client script to run tests added

- can run write and/or read tests
- can choose between zblk formats
- can choose between all read test tools
parent 81b8a103
#!/usr/bin/env python
#encoding: utf-8
from subprocess import call
from time import sleep
from sys import argv
import requests
import pandas as pd
import numpy as np
from tabulate import tabulate
def run_write_tests(write_block_formats, how_many=5):
endpoint = 'http://zope:insecure@10.0.87.104:2150/erp5/portal_skins/erp5_wendelin_examples/pandas_out_of_core_write'
timings = {}
for zblk_format in write_block_formats:
timings[zblk_format] = []
for i in range(how_many):
# print 'Sending request to %s with %s' % (endpoint, zblk_format)
response = requests.get(endpoint, params={'zblk_format': zblk_format[-1]})
if response.status_code == 502:
restart_zope()
response = requests.get(endpoint, params={'zblk_format': zblk_format[-1]})
try:
response = response.json()
except:
print 'Error while processing response:'
print response.text
print 'Restarting zope again...'
restart_zope()
else:
timings[zblk_format].append(extract_result(response['result']))
return timings
def run_read_tests(cache_type='Hot Cache', how_many=5):
endpoint = 'http://zope:insecure@10.0.87.104:2150/erp5/portal_skins/erp5_wendelin_examples/pandas_out_of_core_read'
timings = {}
tools = get_test_tools()
for tool in tools:
timings[tool] = []
for i in range(how_many):
# print 'Sending request to %s with %s' % (endpoint, tool)
response = requests.get(endpoint, params={'tool': tool}).json()
timings[tool].append(extract_result(response['result']))
if 'cold' in cache_type.lower():
restart_zope()
clean_cache()
return timings
def get_test_tools():
return ['wendelin.pandas', 'wendelin.numpy', 'numpy.memory', 'numpy.memmap']
def extract_result(text):
return float(text.split('in ')[1].split(' ')[0])
def restart_zope():
zope_slapparts = [6, 7, 8]
zope_services = ['slappart%s:zope-0' % number for number in zope_slapparts]
command = ['slapos', 'node', 'restart']
command.extend(zope_services)
call(command)
sleep(75) # give zope some time to restart
def clean_cache():
command = 'free && sync && echo 3 > /proc/sys/vm/drop_caches && free'
call([command], shell=True)
def get_series(results):
series = {}
for key in results:
series[key] = pd.Series(results[key])
return series
def pretty_result(series, result_type=None, cache_type=None):
print '--- %s Cache %s ---' % (cache_type, result_type)
for key in series.iterkeys():
print '- %s' % key
print ' - min = %s' % series[key].min()
print ' - max = %s' % series[key].max()
print ' - average = %s' % series[key].mean()
print ' - stdev = %s' % series[key].std()
print ' - data = %s' % list(series[key])
def build_table(results):
index_name = 'Tool'
index = list(results.itervalues())[0]
result_hash = {
index_name: index,
}
for column in results.iterkeys():
result_hash[column] = []
for test_type in results.iterkeys():
for tool in results[test_type].iterkeys():
std = results[test_type][tool].std()
average = results[test_type][tool].mean()
std_percentage = std/average*100
result_hash[test_type].append(u'%.3f ± %.2f%%' % (average, std_percentage))
return tabulate(result_hash, headers='keys')
if __name__ == '__main__':
tests_to_run = argv[1].split(',')
# getting read results
if 'read' in tests_to_run:
cache_types = ['Hot Cache', 'Cold Cache']
read_series = {}
for cache_type in cache_types:
results = run_read_tests(cache_type=cache_type)
read_series[cache_type] = get_series(results)
print 'Read results:'
print build_table(read_series)
# getting write results
if 'write' in tests_to_run:
write_block_formats = ['ZBlk0', 'ZBlk1']
write_series = {'wendelin.core': get_series(run_write_tests(write_block_formats, 5))}
print 'Write results:'
print build_table(write_series)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment