mirror of https://github.com/ivanch/tcc.git
melhorando testes
This commit is contained in:
parent
6f93461ed9
commit
92245c468a
|
@ -1,4 +1,5 @@
|
||||||
.vs
|
.vs
|
||||||
bin
|
bin
|
||||||
obj
|
obj
|
||||||
*.png
|
*.png
|
||||||
|
*.csv
|
|
@ -34,11 +34,11 @@ namespace TCC.Controllers
|
||||||
[HttpGet("load-image")]
|
[HttpGet("load-image")]
|
||||||
public async Task<IActionResult> GetSimpleImage()
|
public async Task<IActionResult> GetSimpleImage()
|
||||||
{
|
{
|
||||||
var result = ImageService.GetSimpleImage();
|
//var result = ImageService.GetSimpleImage();
|
||||||
|
var result = System.IO.File.ReadAllBytes("simpleimage.png");
|
||||||
|
|
||||||
var imageStream = new MemoryStream();
|
var imageStream = new byte[result.Length];
|
||||||
result.Write(imageStream);
|
result.CopyTo(imageStream, 0);
|
||||||
imageStream.Position = 0;
|
|
||||||
|
|
||||||
return File(imageStream, "image/png");
|
return File(imageStream, "image/png");
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim
|
||||||
|
|
||||||
WORKDIR /App
|
WORKDIR /App
|
||||||
|
|
||||||
RUN wget https://files.ivanch.me/api/public/dl/QFCLgtrG/simpleimage.png && \
|
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 && \
|
wget https://files.ivanch.me/api/public/dl/E0VLgWbx/bigimage.png && \
|
||||||
rm -rf runtimes
|
rm -rf runtimes
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
def plot_graph(x, y, title, x_label, y_label, filename):
|
||||||
|
plt.plot(x, y, 'ro', markersize=1, linewidth=0.5, linestyle='solid')
|
||||||
|
plt.title(title)
|
||||||
|
plt.xlabel(x_label)
|
||||||
|
plt.ylabel(y_label)
|
||||||
|
plt.savefig(f'{filename}.png')
|
||||||
|
|
||||||
|
def getData(filename):
|
||||||
|
lines = []
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
x = []
|
||||||
|
y = []
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip().split(',')
|
||||||
|
if line:
|
||||||
|
x.append(int(line[0]))
|
||||||
|
y.append(float(line[1]))
|
||||||
|
|
||||||
|
return x, y
|
||||||
|
|
||||||
|
def generateGraph(filename, framework_name, endpoint_name):
|
||||||
|
x, y = getData(filename)
|
||||||
|
plot_graph(x, y, f'{framework_name} - {endpoint_name}', 'Number of requests', 'Requests per second', filename.split('.')[0])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
generateGraph('data.txt', 'ASP.NET', 'test')
|
|
@ -1,33 +1,65 @@
|
||||||
import requests
|
import requests
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
from graph import generateGraph
|
||||||
|
|
||||||
URL_BASE = 'http://localhost:5100'
|
if len(sys.argv) != 2 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
|
||||||
|
print("Usage: python testes.py <name>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
num_requests = [1000, 5000, 10_000, 50_000, 100_000, 500_000, 1_000_000]
|
FRAMEWORK_NAME = sys.argv[1]
|
||||||
|
URL_BASE = 'http://localhost:9080'
|
||||||
|
ENDPOINTS = [
|
||||||
|
'/status/ok',
|
||||||
|
'/image/load-image',
|
||||||
|
]
|
||||||
|
|
||||||
def send_request(session, url):
|
num_requests = [10, 1000, 5000, 10_000, 50_000, 100_000, 500_000, 1_000_000]
|
||||||
response = session.get(url)
|
|
||||||
|
def send_request(url):
|
||||||
|
success = False
|
||||||
|
while not success:
|
||||||
|
try:
|
||||||
|
response = requests.get(url)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
success = response.status_code == 200
|
||||||
return response.status_code
|
return response.status_code
|
||||||
|
|
||||||
def main():
|
def getFileName(endpoint):
|
||||||
for num_request in num_requests:
|
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)
|
||||||
|
|
||||||
|
for num_request in range(0, 50_000, 1000):
|
||||||
|
if num_request <= 0: continue
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
||||||
url = f'{URL_BASE}/status/ok'
|
url = f'{URL_BASE}{endpoint}'
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
futures = []
|
futures = []
|
||||||
with requests.Session() as session:
|
#with requests.Session() as session:
|
||||||
futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
|
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
|
||||||
|
futures = [executor.submit(send_request, url) for _ in range(num_request)]
|
||||||
|
|
||||||
concurrent.futures.wait(futures)
|
concurrent.futures.wait(futures)
|
||||||
|
|
||||||
elapsed_time = time.time() - start_time
|
elapsed_time = time.time() - start_time
|
||||||
|
|
||||||
successful_responses = sum(1 for future in futures if future.result() == 200)
|
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)
|
||||||
|
|
||||||
print(f"All requests completed in {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second.")
|
time.sleep(3)
|
||||||
print(f"Successful responses: {successful_responses}/{num_request}")
|
|
||||||
|
|
||||||
main()
|
for endpoint in ENDPOINTS:
|
||||||
|
run_tests(endpoint)
|
||||||
|
|
Loading…
Reference in New Issue