mirror of https://github.com/ivanch/tcc.git
average runs
This commit is contained in:
parent
2f91c3636f
commit
2e3398f683
|
@ -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()),
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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,10 +61,13 @@ def run_tests(endpoint, method, num_requests, metadata):
|
|||
for num_request in num_requests:
|
||||
if num_request <= 0: continue
|
||||
|
||||
total_cpu, total_ram = 0, 0
|
||||
total_time = 0
|
||||
|
||||
for run in range(AVG_RUNS):
|
||||
ok_responses = 0
|
||||
bad_responses = 0
|
||||
server_errors = 0
|
||||
cpu, ram = 0, 0
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||
url = f'{URL_BASE}{endpoint}'
|
||||
|
@ -82,10 +84,13 @@ def run_tests(endpoint, method, num_requests, metadata):
|
|||
|
||||
if i == half:
|
||||
cpu, ram = get_resource_usage()
|
||||
total_cpu += float(cpu)
|
||||
total_ram += float(ram)
|
||||
|
||||
concurrent.futures.wait(futures)
|
||||
|
||||
elapsed_time = time.time() - start_time
|
||||
total_time += elapsed_time
|
||||
|
||||
for future in futures:
|
||||
responses = future.result()
|
||||
|
@ -93,12 +98,20 @@ def run_tests(endpoint, method, num_requests, metadata):
|
|||
bad_responses += responses[4]
|
||||
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}]]")
|
||||
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
|
||||
record_resource(files[1], num_request, cpu, ram)
|
||||
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
|
||||
|
||||
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
|
||||
record_resource(files[1], num_request, cpu, ram)
|
||||
|
||||
def get_resource_usage():
|
||||
if CONTAINER_NAME == "": return 0, 0
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 504b59278f6024219814649f2715b70561251c65
|
Loading…
Reference in New Issue