mirror of https://github.com/ivanch/tcc.git
Compare commits
5 Commits
81abfe0c30
...
2085b7d89b
Author | SHA1 | Date |
---|---|---|
José Henrique Ivanchechen | 2085b7d89b | |
José Henrique Ivanchechen | 150ec0e1d7 | |
José Henrique Ivanchechen | 659acde4ad | |
José Henrique Ivanchechen | af0bad0eeb | |
José Henrique Ivanchechen | 89f1418a08 |
|
@ -4,4 +4,6 @@ bin
|
|||
obj
|
||||
|
||||
*.png
|
||||
*.csv
|
||||
*.csv
|
||||
*.jpg
|
||||
*.mp4
|
|
@ -34,25 +34,13 @@ namespace TCC.Controllers
|
|||
[HttpGet("load-image")]
|
||||
public async Task<IActionResult> GetSimpleImage()
|
||||
{
|
||||
var result = ImageService.GetSimpleImage();
|
||||
|
||||
var imageStream = new MemoryStream();
|
||||
result.Write(imageStream);
|
||||
imageStream.Position = 0;
|
||||
|
||||
return File(imageStream, "image/png");
|
||||
return File(ImageService.GetSimpleImage(), "image/png");
|
||||
}
|
||||
|
||||
[HttpGet("load-big-image")]
|
||||
public async Task<IActionResult> GetBigImage()
|
||||
{
|
||||
var result = ImageService.GetBigImage();
|
||||
|
||||
var imageStream = new MemoryStream();
|
||||
result.Write(imageStream);
|
||||
imageStream.Position = 0;
|
||||
|
||||
return File(imageStream, "image/png");
|
||||
return File(ImageService.GetBigImage(), "image/png");
|
||||
}
|
||||
|
||||
[HttpPost("save-big-image")]
|
||||
|
|
|
@ -2,6 +2,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build-env
|
|||
WORKDIR /App
|
||||
|
||||
# Copy everything
|
||||
RUN apt update && apt install wget -y
|
||||
COPY * .
|
||||
|
||||
# Restore as distinct layers
|
||||
|
@ -10,16 +11,21 @@ RUN dotnet restore
|
|||
# Build a release
|
||||
RUN dotnet build -c Release -o out
|
||||
|
||||
RUN cd out && \
|
||||
wget https://files.ivanch.me/api/public/dl/QFCLgtrG/simpleimage.png && \
|
||||
wget https://files.ivanch.me/api/public/dl/E0VLgWbx/bigimage.png && \
|
||||
wget https://files.ivanch.me/api/public/dl/nTAYqZwD/video.mp4 && \
|
||||
rm -rf runtimes && \
|
||||
mkdir -p ./static && \
|
||||
cp simpleimage.png ./static && \
|
||||
cp bigimage.png ./static && \
|
||||
mv video.mp4 ./static
|
||||
|
||||
# Build runtime image
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim
|
||||
|
||||
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
|
||||
|
||||
COPY --from=build-env /App/out .
|
||||
|
||||
ENTRYPOINT ["dotnet", "/App/TCC.APP.dll"]
|
|
@ -4,13 +4,13 @@ namespace tcc_app
|
|||
{
|
||||
public static class ImageHelper
|
||||
{
|
||||
public static MagickImage SimpleImage;
|
||||
public static MagickImage BigImage;
|
||||
public static byte[] SimpleImage;
|
||||
public static byte[] BigImage;
|
||||
|
||||
static ImageHelper()
|
||||
{
|
||||
SimpleImage = new MagickImage("simpleimage.png");
|
||||
BigImage = new MagickImage("bigimage.png");
|
||||
SimpleImage = File.ReadAllBytes("static/simpleimage.png");
|
||||
BigImage = File.ReadAllBytes("static/bigimage.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using TCC.Services;
|
||||
|
||||
namespace TCC
|
||||
|
@ -18,9 +19,13 @@ namespace TCC
|
|||
options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set default value is: 30 MB
|
||||
});
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "static")),
|
||||
RequestPath = "/static"
|
||||
});
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -62,12 +62,12 @@ namespace TCC.Services
|
|||
file.Close();
|
||||
}
|
||||
|
||||
public MagickImage GetSimpleImage()
|
||||
public byte[] GetSimpleImage()
|
||||
{
|
||||
return ImageHelper.SimpleImage;
|
||||
}
|
||||
|
||||
public MagickImage GetBigImage()
|
||||
public byte[] GetBigImage()
|
||||
{
|
||||
return ImageHelper.BigImage;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to nginx!</title>
|
||||
<style>
|
||||
html {
|
||||
color-scheme: light dark;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 35em;
|
||||
margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to nginx!</h1>
|
||||
<p>
|
||||
If you see this page, the nginx web server is successfully installed and
|
||||
working. Further configuration is required.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For online documentation and support please refer to
|
||||
<a href="http://nginx.org/">nginx.org</a>.<br />
|
||||
Commercial support is available at
|
||||
<a href="http://nginx.com/">nginx.com</a>.
|
||||
</p>
|
||||
|
||||
<p><em>Thank you for using nginx.</em></p>
|
||||
</body>
|
||||
</html>
|
|
@ -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')
|
||||
|
|
|
@ -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 <name>")
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue