average runs

This commit is contained in:
José Henrique 2023-09-28 21:00:55 -03:00
parent 2f91c3636f
commit 2e3398f683
4 changed files with 43 additions and 28 deletions

View File

@ -13,6 +13,8 @@ ENDPOINTS = {
} }
BLUR_RADIUS = 5 BLUR_RADIUS = 5
AVG_RUNS = 3
API_REQUESTS = [ API_REQUESTS = [
('/status/ok', 'GET', range(0, 30_000, 5000), None), ('/status/ok', 'GET', range(0, 30_000, 5000), None),
('/image/save-big-image', 'POST', range(0, 10_000, 1_000), open('big-image.png', 'rb').read()), ('/image/save-big-image', 'POST', range(0, 10_000, 1_000), open('big-image.png', 'rb').read()),

View File

@ -1,6 +1,5 @@
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import os
from common import API_REQUESTS, FRAMEWORKS from common import API_REQUESTS, FRAMEWORKS
FRAMEWORKS = [f for f, _ in FRAMEWORKS] FRAMEWORKS = [f for f, _ in FRAMEWORKS]

View File

@ -2,11 +2,10 @@ import requests
import docker import docker
import concurrent.futures import concurrent.futures
import time import time
import sys
import os import os
from math import floor from math import floor
from init import init from init import init
from common import FRAMEWORKS, ENDPOINTS, API_REQUESTS from common import FRAMEWORKS, ENDPOINTS, API_REQUESTS, AVG_RUNS
init() init()
@ -62,10 +61,13 @@ def run_tests(endpoint, method, num_requests, metadata):
for num_request in num_requests: for num_request in num_requests:
if num_request <= 0: continue if num_request <= 0: continue
total_cpu, total_ram = 0, 0
total_time = 0
for run in range(AVG_RUNS):
ok_responses = 0 ok_responses = 0
bad_responses = 0 bad_responses = 0
server_errors = 0 server_errors = 0
cpu, ram = 0, 0
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor: with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
url = f'{URL_BASE}{endpoint}' url = f'{URL_BASE}{endpoint}'
@ -82,10 +84,13 @@ def run_tests(endpoint, method, num_requests, metadata):
if i == half: if i == half:
cpu, ram = get_resource_usage() cpu, ram = get_resource_usage()
total_cpu += float(cpu)
total_ram += float(ram)
concurrent.futures.wait(futures) concurrent.futures.wait(futures)
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
total_time += elapsed_time
for future in futures: for future in futures:
responses = future.result() responses = future.result()
@ -93,12 +98,20 @@ def run_tests(endpoint, method, num_requests, metadata):
bad_responses += responses[4] bad_responses += responses[4]
server_errors += responses[5] server_errors += responses[5]
print(f"{num_request}: {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second. [OK: {ok_responses}, Bad Request: {bad_responses}, Server Error: {server_errors}]]") print(f"[#{run}] {num_request}: {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second. [OK: {ok_responses}, Bad Request: {bad_responses}, Server Error: {server_errors}]]")
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
record_resource(files[1], num_request, cpu, ram) client = docker.from_env()
client.containers.get(CONTAINER_NAME).restart()
time.sleep(3) time.sleep(3)
cpu = total_cpu / AVG_RUNS
ram = total_ram / AVG_RUNS
elapsed_time = total_time / AVG_RUNS
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
record_resource(files[1], num_request, cpu, ram)
def get_resource_usage(): def get_resource_usage():
if CONTAINER_NAME == "": return 0, 0 if CONTAINER_NAME == "": return 0, 0

1
tcc-express Submodule

@ -0,0 +1 @@
Subproject commit 504b59278f6024219814649f2715b70561251c65