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
|
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()),
|
||||||
|
|
|
@ -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]
|
||||||
|
|
|
@ -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,43 +61,57 @@ 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
|
||||||
|
|
||||||
ok_responses = 0
|
total_cpu, total_ram = 0, 0
|
||||||
bad_responses = 0
|
total_time = 0
|
||||||
server_errors = 0
|
|
||||||
cpu, ram = 0, 0
|
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
|
for run in range(AVG_RUNS):
|
||||||
url = f'{URL_BASE}{endpoint}'
|
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 = []
|
start_time = time.time()
|
||||||
#with requests.Session() as session:
|
|
||||||
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
|
|
||||||
|
|
||||||
half = floor(num_request/2)
|
futures = []
|
||||||
for i in range(num_request):
|
#with requests.Session() as session:
|
||||||
futures.append(executor.submit(send_request, url, method, metadata))
|
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
|
||||||
|
|
||||||
if i == half:
|
half = floor(num_request/2)
|
||||||
cpu, ram = get_resource_usage()
|
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:
|
elapsed_time = time.time() - start_time
|
||||||
responses = future.result()
|
total_time += elapsed_time
|
||||||
ok_responses += responses[2]
|
|
||||||
bad_responses += responses[4]
|
for future in futures:
|
||||||
server_errors += responses[5]
|
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(files[0], num_request, f"{num_request/elapsed_time:.2f}")
|
||||||
record_resource(files[1], num_request, cpu, ram)
|
record_resource(files[1], num_request, cpu, ram)
|
||||||
|
|
||||||
time.sleep(3)
|
|
||||||
|
|
||||||
def get_resource_usage():
|
def get_resource_usage():
|
||||||
if CONTAINER_NAME == "": return 0, 0
|
if CONTAINER_NAME == "": return 0, 0
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 504b59278f6024219814649f2715b70561251c65
|
Loading…
Reference in New Issue