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
AVG_RUNS = 3
API_REQUESTS = [
('/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()),

View File

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

View File

@ -2,11 +2,10 @@ import requests
import docker
import concurrent.futures
import time
import sys
import os
from math import floor
from init import init
from common import FRAMEWORKS, ENDPOINTS, API_REQUESTS
from common import FRAMEWORKS, ENDPOINTS, API_REQUESTS, AVG_RUNS
init()
@ -62,43 +61,57 @@ def run_tests(endpoint, method, num_requests, metadata):
for num_request in num_requests:
if num_request <= 0: continue
ok_responses = 0
bad_responses = 0
server_errors = 0
cpu, ram = 0, 0
total_cpu, total_ram = 0, 0
total_time = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
url = f'{URL_BASE}{endpoint}'
for run in range(AVG_RUNS):
ok_responses = 0
bad_responses = 0
server_errors = 0
start_time = time.time()
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
url = f'{URL_BASE}{endpoint}'
futures = []
#with requests.Session() as session:
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
start_time = time.time()
half = floor(num_request/2)
for i in range(num_request):
futures.append(executor.submit(send_request, url, method, metadata))
futures = []
#with requests.Session() as session:
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
if i == half:
cpu, ram = get_resource_usage()
half = floor(num_request/2)
for i in range(num_request):
futures.append(executor.submit(send_request, url, method, metadata))
concurrent.futures.wait(futures)
if i == half:
cpu, ram = get_resource_usage()
total_cpu += float(cpu)
total_ram += float(ram)
elapsed_time = time.time() - start_time
concurrent.futures.wait(futures)
for future in futures:
responses = future.result()
ok_responses += responses[2]
bad_responses += responses[4]
server_errors += responses[5]
elapsed_time = time.time() - start_time
total_time += elapsed_time
for future in futures:
responses = future.result()
ok_responses += responses[2]
bad_responses += responses[4]
server_errors += responses[5]
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}]]")
client = docker.from_env()
client.containers.get(CONTAINER_NAME).restart()
time.sleep(3)
cpu = total_cpu / AVG_RUNS
ram = total_ram / AVG_RUNS
elapsed_time = total_time / AVG_RUNS
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}]]")
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
record_resource(files[1], num_request, cpu, ram)
time.sleep(3)
def get_resource_usage():
if CONTAINER_NAME == "": return 0, 0

1
tcc-express Submodule

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