From 89f1418a085b0b8c71274c139119c7bb3b1ce188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique=20Ivanchechen?= Date: Tue, 29 Aug 2023 15:55:28 -0300 Subject: [PATCH] coisas --- .gitignore | 4 ++- ASP.NET/Dockerfile | 6 +++- ASP.NET/Program.cs | 6 ++++ ASP.NET/Properties/launchSettings.json | 2 +- ASP.NET/static/nginx.html | 33 ++++++++++++++++++++ scripts/graph.py | 5 +-- scripts/testes.py | 42 ++++++++++++++++++-------- 7 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 ASP.NET/static/nginx.html diff --git a/.gitignore b/.gitignore index 278bb12..459a142 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ bin obj *.png -*.csv \ No newline at end of file +*.csv +*.jpg +*.mp4 \ No newline at end of file diff --git a/ASP.NET/Dockerfile b/ASP.NET/Dockerfile index ff81a83..5aeda6e 100644 --- a/ASP.NET/Dockerfile +++ b/ASP.NET/Dockerfile @@ -18,7 +18,11 @@ WORKDIR /App RUN apt update && apt install wget -y && \ wget https://files.ivanch.me/api/public/dl/QFCLgtrG/simpleimage.png && \ wget https://files.ivanch.me/api/public/dl/E0VLgWbx/bigimage.png && \ - rm -rf runtimes + wget https://files.ivanch.me/api/public/dl/nTAYqZwD/video.mp4 && \ + rm -rf runtimes && \ + cp simpleimage.png ./static && \ + cp bigimage.png ./static && \ + mv video.mp4 ./static COPY --from=build-env /App/out . diff --git a/ASP.NET/Program.cs b/ASP.NET/Program.cs index 1a6b4d7..9f17c17 100644 --- a/ASP.NET/Program.cs +++ b/ASP.NET/Program.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.FileProviders; using TCC.Services; namespace TCC @@ -21,6 +22,11 @@ namespace TCC var app = builder.Build(); + app.UseStaticFiles(new StaticFileOptions + { + FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "static")), + RequestPath = "/static" + }); app.MapControllers(); app.Run(); diff --git a/ASP.NET/Properties/launchSettings.json b/ASP.NET/Properties/launchSettings.json index c972bd3..5b073a0 100644 --- a/ASP.NET/Properties/launchSettings.json +++ b/ASP.NET/Properties/launchSettings.json @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": false, "launchUrl": "weatherforecast", - "applicationUrl": "http://0.0.0.0:5100", + "applicationUrl": "http://0.0.0.0:9090", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/ASP.NET/static/nginx.html b/ASP.NET/static/nginx.html new file mode 100644 index 0000000..0ceac88 --- /dev/null +++ b/ASP.NET/static/nginx.html @@ -0,0 +1,33 @@ + + + + Welcome to nginx! + + + +

Welcome to nginx!

+

+ If you see this page, the nginx web server is successfully installed and + working. Further configuration is required. +

+ +

+ For online documentation and support please refer to + nginx.org.
+ Commercial support is available at + nginx.com. +

+ +

Thank you for using nginx.

+ + \ No newline at end of file diff --git a/scripts/graph.py b/scripts/graph.py index c81e09d..0ad4f1c 100644 --- a/scripts/graph.py +++ b/scripts/graph.py @@ -26,8 +26,9 @@ def getData(filename): def generateGraph(filename, framework_name, endpoint_name): x, y = getData(filename) - new_filename = ".".join(filename.split('.')[:-1]) + + new_filename = filename.replace('.txt', '').replace('.csv', '') plot_graph(x, y, f'{framework_name} - {endpoint_name}', 'Number of requests', 'Requests per second', new_filename) if __name__ == '__main__': - generateGraph('data.txt', 'ASP.NET', 'test') + generateGraph('data.txt', 'Teste', 'endpoint') diff --git a/scripts/testes.py b/scripts/testes.py index c38f0c3..2c085be 100644 --- a/scripts/testes.py +++ b/scripts/testes.py @@ -4,30 +4,36 @@ import time import sys import os from graph import generateGraph +from math import floor if len(sys.argv) != 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help': print("Usage: python testes.py ") sys.exit(1) +THREADS = 10 FRAMEWORK_NAME = sys.argv[1] -URL_BASE = 'http://localhost:9080' -ENDPOINTS = [ - '/status/ok', - '/image/load-image', +URL_BASE = 'http://172.26.48.1:9080' +API_REQUESTS = [ + ('/status/ok', range(0, 50_000, 5000)), + ('/image/load-image', range(0, 50_000, 5000)), + ('/image/load-big-image', range(0, 1_000, 10)), ] -#num_requests = [10, 1000, 5000, 10_000, 50_000, 100_000, 500_000, 1_000_000] -num_requests = range(0, 50_000, 5000) - def send_request(url): success = False + responses = { + 2: 0, # OK + 4: 0, # Bad Request + 5: 0, # Server Error + } while not success: try: response = requests.get(url) except: continue success = response.status_code == 200 - return response.status_code + responses[floor(response.status_code/100)] += 1 + return responses def getFileName(endpoint): endpoint = endpoint.replace('/', '_') @@ -37,7 +43,7 @@ def record(filename, requests, reqpersec): with open(filename, "a") as file: file.write(f"{requests},{reqpersec}\n") -def run_tests(endpoint): +def run_tests(endpoint, num_requests): filename = getFileName(endpoint) if os.path.exists(filename): os.remove(filename) @@ -45,7 +51,11 @@ def run_tests(endpoint): for num_request in num_requests: if num_request <= 0: continue - with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: + ok_responses = 0 + bad_responses = 0 + server_errors = 0 + + with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor: url = f'{URL_BASE}{endpoint}' start_time = time.time() @@ -59,12 +69,18 @@ def run_tests(endpoint): elapsed_time = time.time() - start_time - print(f"{num_request}: {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second.") + for future in futures: + responses = future.result() + ok_responses += responses[2] + 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(filename, num_request, f"{num_request/elapsed_time:.2f}") generateGraph(filename, FRAMEWORK_NAME, endpoint) time.sleep(3) -for endpoint in ENDPOINTS: +for endpoint, num_requests in API_REQUESTS: print(f"# {endpoint}") - run_tests(endpoint) + run_tests(endpoint, num_requests)