2023-08-23 14:01:18 +00:00
|
|
|
import requests
|
|
|
|
import concurrent.futures
|
|
|
|
import time
|
2023-08-24 23:52:15 +00:00
|
|
|
import sys
|
2023-08-24 23:57:34 +00:00
|
|
|
import os
|
2023-08-24 23:52:15 +00:00
|
|
|
from graph import generateGraph
|
2023-08-23 14:01:18 +00:00
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
if len(sys.argv) != 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
|
|
|
|
print("Usage: python testes.py <name>")
|
|
|
|
sys.exit(1)
|
2023-08-23 14:01:18 +00:00
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
FRAMEWORK_NAME = sys.argv[1]
|
|
|
|
URL_BASE = 'http://localhost:9080'
|
|
|
|
ENDPOINTS = [
|
|
|
|
'/status/ok',
|
|
|
|
'/image/load-image',
|
|
|
|
]
|
2023-08-23 14:01:18 +00:00
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
num_requests = [10, 1000, 5000, 10_000, 50_000, 100_000, 500_000, 1_000_000]
|
|
|
|
|
|
|
|
def send_request(url):
|
|
|
|
success = False
|
|
|
|
while not success:
|
|
|
|
try:
|
|
|
|
response = requests.get(url)
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
success = response.status_code == 200
|
2023-08-23 14:01:18 +00:00
|
|
|
return response.status_code
|
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
def getFileName(endpoint):
|
|
|
|
endpoint = endpoint.replace('/', '_')
|
|
|
|
return f"{FRAMEWORK_NAME}_{endpoint}.csv"
|
|
|
|
|
|
|
|
def record(filename, requests, reqpersec):
|
|
|
|
with open(filename, "a") as file:
|
|
|
|
file.write(f"{requests},{reqpersec}\n")
|
|
|
|
|
|
|
|
def run_tests(endpoint):
|
|
|
|
filename = getFileName(endpoint)
|
2023-08-24 23:57:34 +00:00
|
|
|
if os.path.exists(filename):
|
|
|
|
os.remove(filename)
|
2023-08-24 23:52:15 +00:00
|
|
|
|
|
|
|
for num_request in range(0, 50_000, 1000):
|
|
|
|
if num_request <= 0: continue
|
|
|
|
|
2023-08-23 14:01:18 +00:00
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
2023-08-24 23:52:15 +00:00
|
|
|
url = f'{URL_BASE}{endpoint}'
|
2023-08-23 14:01:18 +00:00
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
|
|
|
futures = []
|
2023-08-24 23:52:15 +00:00
|
|
|
#with requests.Session() as session:
|
|
|
|
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
|
|
|
|
futures = [executor.submit(send_request, url) for _ in range(num_request)]
|
2023-08-23 14:01:18 +00:00
|
|
|
|
|
|
|
concurrent.futures.wait(futures)
|
|
|
|
|
|
|
|
elapsed_time = time.time() - start_time
|
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
print(f"{num_request}: {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second.")
|
|
|
|
record(filename, num_request, f"{num_request/elapsed_time:.2f}")
|
|
|
|
generateGraph(filename, FRAMEWORK_NAME, endpoint)
|
2023-08-23 14:01:18 +00:00
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
time.sleep(3)
|
2023-08-23 14:01:18 +00:00
|
|
|
|
2023-08-24 23:52:15 +00:00
|
|
|
for endpoint in ENDPOINTS:
|
|
|
|
run_tests(endpoint)
|