This commit is contained in:
José Henrique Ivanchechen 2023-09-03 12:08:25 -03:00
parent b55d7eba06
commit e19595ab6c
3 changed files with 54 additions and 18 deletions

View File

@ -23,6 +23,7 @@ namespace TCC.Controllers
mstream.Position = 0; mstream.Position = 0;
var result = ImageService.BoxBlurImage(mstream, radius); var result = ImageService.BoxBlurImage(mstream, radius);
mstream.Close();
var blurredImageStream = new MemoryStream(); var blurredImageStream = new MemoryStream();
result.Write(blurredImageStream); result.Write(blurredImageStream);
@ -49,6 +50,7 @@ namespace TCC.Controllers
MemoryStream mstream = new MemoryStream(); MemoryStream mstream = new MemoryStream();
await HttpContext.Request.Body.CopyToAsync(mstream); await HttpContext.Request.Body.CopyToAsync(mstream);
mstream.Position = 0; mstream.Position = 0;
mstream.Close();
return Ok(); return Ok();
} }

17
scripts/init.py Normal file
View File

@ -0,0 +1,17 @@
import requests
def download_file(url):
local_filename = url.split('/')[-1]
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
# If you have chunk encoded response uncomment if
# and set chunk_size parameter to None.
#if chunk:
f.write(chunk)
return local_filename
def init():
download_file('https://files.ivanch.me/api/public/dl/Dj0gkp-m/small-image.png')
download_file('https://files.ivanch.me/api/public/dl/FqHEPM1Q/big-image.png')

View File

@ -6,25 +6,31 @@ import sys
import os import os
from graph import generate_req_graph, generate_resource_graph from graph import generate_req_graph, generate_resource_graph
from math import floor from math import floor
from init import init
if len(sys.argv) != 3 or sys.argv[1] == '-h' or sys.argv[1] == '--help': if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
print("Usage: python testes.py <framework name> <container name>") print("Usage: python testes.py <framework name> [container name]")
sys.exit(1) sys.exit(1)
init()
THREADS = 10 THREADS = 10
FRAMEWORK_NAME = sys.argv[1] FRAMEWORK_NAME = sys.argv[1]
CONTAINER_NAME = sys.argv[2] CONTAINER_NAME = sys.argv[2] if len(sys.argv) > 2 else ""
URL_BASE = 'http://localhost:9080' URL_BASE = 'http://localhost:9080'
BLUR_RADIUS = 5
API_REQUESTS = [ API_REQUESTS = [
('/status/ok', range(0, 30_000, 5000)), ('/image/save-big-image', 'POST', range(0, 30_000, 50), open('big-image.png', 'rb').read()),
('/image/load-image', range(0, 30_000, 5000)), (f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 1_000, 50), open('small-image.png', 'rb').read()),
('/static/simpleimage.png', range(0, 30_000, 5000)), ('/status/ok', 'GET', range(0, 30_000, 5000), None),
('/image/load-big-image', range(0, 1_000, 200)), ('/image/load-image', 'GET', range(0, 30_000, 5000), None),
('/static/bigimage.png', range(0, 1_000, 200)), ('/static/simpleimage.png', 'GET', range(0, 30_000, 5000), None),
('/static/video.mp4', range(0, 10_000, 1_000)), ('/image/load-big-image', 'GET', range(0, 1_000, 200), None),
('/static/bigimage.png', 'GET', range(0, 1_000, 200), None),
('/static/video.mp4', 'GET', range(0, 10_000, 1_000), None),
] ]
def send_request(url): def send_request(url, method = 'GET', payload = None):
success = False success = False
responses = { responses = {
2: 0, # OK 2: 0, # OK
@ -33,7 +39,11 @@ def send_request(url):
} }
while not success: while not success:
try: try:
response = requests.get(url) response = None
if method == 'GET':
response = requests.get(url)
elif method == 'POST':
response = requests.post(url, data=payload, headers={'Content-Type': 'image/png'})
except: except:
continue continue
success = response.status_code == 200 success = response.status_code == 200
@ -44,8 +54,8 @@ def getFileNames(endpoint):
endpoint = endpoint.replace('/', '') endpoint = endpoint.replace('/', '')
files = [ files = [
f"req_{FRAMEWORK_NAME}_{endpoint}.csv", f"data/req_{FRAMEWORK_NAME}_{endpoint}.csv",
f"resource_{FRAMEWORK_NAME}_{endpoint}.csv", f"data/resource_{FRAMEWORK_NAME}_{endpoint}.csv",
] ]
return files return files
@ -58,7 +68,7 @@ def record_resource(filename, requests, cpu, ram):
with open(filename, "a") as file: with open(filename, "a") as file:
file.write(f"{requests},{cpu},{ram}\n") file.write(f"{requests},{cpu},{ram}\n")
def run_tests(endpoint, num_requests): def run_tests(endpoint, method, num_requests, metadata):
files = getFileNames(endpoint) files = getFileNames(endpoint)
for filename in files: for filename in files:
if os.path.exists(filename): if os.path.exists(filename):
@ -83,7 +93,7 @@ def run_tests(endpoint, num_requests):
half = floor(num_request/2) half = floor(num_request/2)
for i in range(num_request): for i in range(num_request):
futures.append(executor.submit(send_request, url)) futures.append(executor.submit(send_request, url, method, metadata))
if i == half: if i == half:
cpu, ram = get_resource_usage() cpu, ram = get_resource_usage()
@ -108,6 +118,8 @@ def run_tests(endpoint, num_requests):
time.sleep(3) time.sleep(3)
def get_resource_usage(): def get_resource_usage():
if CONTAINER_NAME == "": return 0, 0
try: try:
client = docker.from_env() client = docker.from_env()
stats = client.containers.get(CONTAINER_NAME).stats(stream=False) stats = client.containers.get(CONTAINER_NAME).stats(stream=False)
@ -132,7 +144,12 @@ def get_ram_usage(stats):
# percent = round(percentage, 2) # percent = round(percentage, 2)
return f"{percentage:.2f}" return f"{percentage:.2f}"
if __name__ == "__main__":
if not os.path.exists("data"):
os.mkdir("data")
else:
os.system("rm -rf data/*")
for endpoint, num_requests in API_REQUESTS: for endpoint, method, num_requests, metadata in API_REQUESTS:
print(f"# {endpoint}") print(f"# {endpoint}")
run_tests(endpoint, num_requests) run_tests(endpoint, method, num_requests, metadata)