Skip to content

Commit

Permalink
Updated performance benchmarking scripts (konveyor#179)
Browse files Browse the repository at this point in the history
* Updated to remove \ from General and low/medium confidence technologies

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>

* Updated to not recommend baseOS for operator images

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>

* Removed operator catalog specific rules

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>

* eval -> ast.literal_eval

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>

* Fixed typo

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>

* Updated performance benchmarking scripts

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>

Signed-off-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>
Co-authored-by: MIHIR CHOUDHURY <choudhury@us.ibm.com>
  • Loading branch information
2 people authored and lamwassi committed Dec 9, 2022
1 parent 26345b8 commit 3afe156
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 43 deletions.
9 changes: 8 additions & 1 deletion config/test.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[test]
[service]
host=http://localhost
port=8000
ctrserv=podman
image=quay.io/konveyor/tackle-container-advisor
version=v1.1.0
memlim=4000m

[payload]
file=CIO_full_tech_summary_only.json
130 changes: 88 additions & 42 deletions test/performance/run_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,103 @@
from concurrent.futures import ThreadPoolExecutor
import json
import time
import subprocess

def call_tca(url):
start = time.time()
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
resp = requests.post(url, data=json.dumps(data), headers=headers)
return time.time()-start,resp

def get_performance_data(n_user, n_data):
global data
actual_len = len(data)
if n_data != 0:
required_data = n_data
else:
required_data = actual_len
quo = required_data // actual_len
rem = required_data % actual_len
data = quo * data + data[:rem]
# print('Payload size : ', len(data), 'records')

assert(n_user > 0)
# print('No of concurrent user : ',n_user)

urls = [host+':'+port+'/standardize']*n_user

# os.system('podman run --name tca -d -p 8000:8000 -m 4000m quay.io/konveyor/tackle-container-advisor:v1.1.0 > /dev/null')
with open(os.devnull, 'wb') as devnull:
cmd = ctrserv + ' run --name tca -d -p 8000:'+port+ ' -m '+memlim+' '+image+':'+version
subprocess.check_call(cmd, shell=True, stdout=devnull, stderr=subprocess.STDOUT)

try:
status_code = 400
while status_code != 200:
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
resp = requests.get(host+':'+port+'/health_check', headers=headers)
status_code = resp.status_code

with ThreadPoolExecutor() as pool:
results = pool.map(call_tca, urls)

result = {}
result['n_user'] = n_user
result['n_data'] = len(data)
result['succ_rate'] = 0
result['avg_resp_time'] = 0
for i,whole_resp in enumerate(list(results)):
time_taken, resp_code = whole_resp
result['avg_resp_time'] += round(time_taken,2)
if resp_code.status_code == 201:
result['succ_rate'] += 1

result['succ_rate'] = result['succ_rate']/n_user
result['avg_resp_time'] = round(result['avg_resp_time']/n_user, 2)
except Exception as e:
print("Exception = ", e)

with open(os.devnull, 'wb') as devnull:
cmd = ctrserv + ' stats --no-stream --format=json tca > stats.json'
subprocess.check_call(cmd, shell=True, stdout=devnull, stderr=subprocess.STDOUT)
cmd = ctrserv + ' stop tca'
subprocess.check_call(cmd, shell=True, stdout=devnull, stderr=subprocess.STDOUT)
cmd = ctrserv + ' rm tca'
subprocess.check_call(cmd, shell=True, stdout=devnull, stderr=subprocess.STDOUT)

with open('stats.json', 'r') as stats_file:
stats = json.load(stats_file)
result['server'] = stats[0]

return result

logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(name)s:%(levelname)s in %(filename)s:%(lineno)s - %(message)s", filemode='w')
config = configparser.ConfigParser()
test = os.path.join("config", "test.ini")
config = configparser.ConfigParser()
test = os.path.join("config", "test.ini")
config.read(test)
try:
host = config['test']['host']
port = config['test']['port']
host = config['service']['host']
port = config['service']['port']
ctrserv= config['service']['ctrserv']
image = config['service']['image']
version= config['service']['version']
memlim = config['service']['memlim']
file = config['payload']['file']
except KeyError as k:
logging.error(f'{k} is not a key in your test.ini file.')
exit()

with open(os.path.join("test", "performance", "small.json")) as f:
data = None
with open(os.path.join("test", "performance", file)) as f:
data = json.load(f)

actual_len = len(data)
dpts = [(1,10), (1,100), (1,1000), (1,5000)]
results = []
for pt in dpts:
print("Working on", pt)
result = get_performance_data(pt[0], pt[1])
results.append(result)
with open(os.path.join("test", "performance", "results.json"), 'w') as f:
json.dump(results, f, indent=4)

try:
required_data = int(sys.argv[2])
except IndexError:
required_data = 1000

quo = required_data // actual_len
rem = required_data % actual_len
data = quo * data + data[:rem]
print('Payload size : ', len(data), 'records')

try:
n_user = int(sys.argv[1])
except IndexError:
n_user = 1

print('No of concurrent user : ',n_user)

urls = [host+':'+port+'/entity-standardizer']*n_user

def call_tca(url):
start = time.time()
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
resp = requests.post(url, data=json.dumps(data), headers=headers)
return time.time()-start,resp


with ThreadPoolExecutor() as pool:
results = pool.map(call_tca, urls)

success = 0
for i,whole_resp in enumerate(list(results)):
time_taken, resp_code = whole_resp
if resp_code.status_code == 201:
success += 1
print(f'User {i+1} Time taken : {round(time_taken,2)}s Response Code : {resp_code.status_code}')

print(f'Passed - {success}/{n_user}')

0 comments on commit 3afe156

Please sign in to comment.