mirror of https://github.com/ivanch/tcc.git
novos graficos testes
This commit is contained in:
parent
f0fa227035
commit
2dbdbea018
|
@ -0,0 +1,10 @@
|
||||||
|
API_REQUESTS = [
|
||||||
|
('/status/ok', 'GET', range(0, 30_000, 5000), None),
|
||||||
|
('/image/save-big-image', 'POST', range(0, 10_000, 1_000), open('big-image.png', 'rb').read()),
|
||||||
|
(f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 1_000, 50), open('small-image.png', 'rb').read()),
|
||||||
|
('/image/load-small-image', 'GET', range(0, 30_000, 5000), None),
|
||||||
|
('/static/small-image.png', 'GET', range(0, 30_000, 5000), None),
|
||||||
|
('/image/load-big-image', 'GET', range(0, 500, 50), None),
|
||||||
|
('/static/big-image.png', 'GET', range(0, 500, 50), None),
|
||||||
|
('/static/video.mp4', 'GET', range(0, 10_000, 1_000), None),
|
||||||
|
]
|
|
@ -1,11 +1,18 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
from common import API_REQUESTS
|
||||||
|
|
||||||
|
FRAMEWORKS = ['Actix', 'ASP.NET', 'Flask']
|
||||||
|
|
||||||
|
def plot_graph(x_data, y_data, title, x_label, y_label, filename):
|
||||||
|
for i, framework in enumerate(FRAMEWORKS):
|
||||||
|
plt.plot(x_data, y_data[i], markersize=1, linewidth=1, linestyle='solid', label=framework)
|
||||||
|
|
||||||
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.title(title)
|
||||||
plt.xlabel(x_label)
|
plt.xlabel(x_label)
|
||||||
plt.ylabel(y_label)
|
plt.ylabel(y_label)
|
||||||
|
plt.legend()
|
||||||
plt.savefig(f'{filename}.png')
|
plt.savefig(f'{filename}.png')
|
||||||
|
|
||||||
plt.clf()
|
plt.clf()
|
||||||
|
@ -13,18 +20,22 @@ def plot_graph(x, y, title, x_label, y_label, filename):
|
||||||
|
|
||||||
def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
|
def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
|
||||||
requests = x_data
|
requests = x_data
|
||||||
resource = {
|
frameworks = {}
|
||||||
'CPU': [p[0] for p in y_data],
|
print(y_data)
|
||||||
'RAM': [p[1] for p in y_data],
|
for i, framework in enumerate(FRAMEWORKS):
|
||||||
}
|
frameworks[framework] = y_data[i]
|
||||||
|
|
||||||
x = np.arange(len(requests))
|
x = np.arange(len(requests))
|
||||||
width = 0.25
|
width = 0.10
|
||||||
multiplier = 0
|
multiplier = 0
|
||||||
|
|
||||||
fig, ax = plt.subplots(layout='constrained')
|
fig, ax = plt.subplots(layout='constrained')
|
||||||
|
|
||||||
for attribute, measurement in resource.items():
|
print(x)
|
||||||
|
for framework, measurements in frameworks.items():
|
||||||
|
print(framework, measurements)
|
||||||
|
|
||||||
|
for attribute, measurement in frameworks.items():
|
||||||
offset = width * multiplier
|
offset = width * multiplier
|
||||||
|
|
||||||
rects = ax.bar(x + offset, measurement, width, label=attribute)
|
rects = ax.bar(x + offset, measurement, width, label=attribute)
|
||||||
|
@ -36,8 +47,8 @@ def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
|
||||||
ax.set_ylabel(y_label)
|
ax.set_ylabel(y_label)
|
||||||
ax.set_title(title)
|
ax.set_title(title)
|
||||||
ax.set_xticks(x + (width/2), requests)
|
ax.set_xticks(x + (width/2), requests)
|
||||||
ax.legend(loc='upper left', ncols=len(resource.items()))
|
ax.legend(loc='upper left', ncols=len(frameworks.items()))
|
||||||
ax.set_ylim(0, 100)
|
ax.set_ylim(0, 120)
|
||||||
|
|
||||||
plt.savefig(f'{filename}.png')
|
plt.savefig(f'{filename}.png')
|
||||||
|
|
||||||
|
@ -75,15 +86,41 @@ def get_resource_data(filename):
|
||||||
return x, y
|
return x, y
|
||||||
|
|
||||||
def generate_req_graph(filename, framework_name, endpoint_name):
|
def generate_req_graph(filename, framework_name, endpoint_name):
|
||||||
x, y = get_data(filename)
|
x, _ = get_data(filename)
|
||||||
|
y = []
|
||||||
|
|
||||||
filename = filename.split('/')[-1]
|
for f in FRAMEWORKS:
|
||||||
new_filename = filename.replace('.csv', '')
|
newfile = filename.replace(framework_name, f)
|
||||||
plot_graph(x, y, f'{framework_name} - {endpoint_name}', 'Número de requisições', 'Requisições por segundo', new_filename)
|
_, y_data = get_resource_data(newfile)
|
||||||
|
|
||||||
|
y.append(y_data)
|
||||||
|
|
||||||
|
graph_file = f'req_{endpoint_name.replace("/", "").replace("?", "")}'
|
||||||
|
plot_graph(x, y, f'Requisições atendidas por segundo - {endpoint_name}', 'Número de requisições', 'Requisições/segundo', graph_file)
|
||||||
|
|
||||||
def generate_resource_graph(filename, framework_name, endpoint_name):
|
def generate_resource_graph(filename, framework_name, endpoint_name):
|
||||||
x, y = get_resource_data(filename)
|
x, _ = get_resource_data(filename)
|
||||||
|
|
||||||
filename = filename.split('/')[-1]
|
for resource_index, resource in enumerate(['cpu', 'ram']):
|
||||||
new_filename = filename.replace('.csv', '')
|
y = []
|
||||||
plot_resource_graph(x, y, f'{framework_name} - {endpoint_name}', 'Uso de recursos', 'Uso (%)', new_filename)
|
|
||||||
|
for f in FRAMEWORKS:
|
||||||
|
newfile = filename.replace(framework_name, f)
|
||||||
|
_, y_data = get_resource_data(newfile)
|
||||||
|
y.append([data[resource_index] for data in y_data])
|
||||||
|
|
||||||
|
graph_file = f'{resource}_{endpoint_name.replace("/", "").replace("?", "")}'
|
||||||
|
plot_resource_graph(x, y, f'Uso de {resource.upper()} - {endpoint_name}', 'Número de requisições', 'Uso (%)', graph_file)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
endpoints = [config[0] for config in API_REQUESTS]
|
||||||
|
|
||||||
|
for endpoint_name in endpoints:
|
||||||
|
framework_name = 'Actix'
|
||||||
|
endpoint_file = endpoint_name.replace('/', '')
|
||||||
|
|
||||||
|
filename = f'data/resource_Actix_{endpoint_file}.csv'
|
||||||
|
generate_resource_graph(filename, framework_name, endpoint_name)
|
||||||
|
|
||||||
|
filename = f'data/req_Actix_{endpoint_file}.csv'
|
||||||
|
generate_req_graph(filename, framework_name, endpoint_name)
|
||||||
|
|
|
@ -4,9 +4,9 @@ import concurrent.futures
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from graph import generate_req_graph, generate_resource_graph
|
|
||||||
from math import floor
|
from math import floor
|
||||||
from init import init
|
from init import init
|
||||||
|
from common import API_REQUESTS
|
||||||
|
|
||||||
if len(sys.argv) < 2 or 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]")
|
||||||
|
@ -19,16 +19,6 @@ FRAMEWORK_NAME = sys.argv[1]
|
||||||
CONTAINER_NAME = sys.argv[2] if len(sys.argv) > 2 else ""
|
CONTAINER_NAME = sys.argv[2] if len(sys.argv) > 2 else ""
|
||||||
URL_BASE = 'http://localhost:9090'
|
URL_BASE = 'http://localhost:9090'
|
||||||
BLUR_RADIUS = 5
|
BLUR_RADIUS = 5
|
||||||
API_REQUESTS = [
|
|
||||||
('/image/save-big-image', 'POST', range(0, 10_000, 1_000), open('big-image.png', 'rb').read()),
|
|
||||||
(f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 1_000, 50), open('small-image.png', 'rb').read()),
|
|
||||||
('/status/ok', 'GET', range(0, 30_000, 5000), None),
|
|
||||||
('/image/load-small-image', 'GET', range(0, 30_000, 5000), None),
|
|
||||||
('/static/small-image.png', 'GET', range(0, 30_000, 5000), None),
|
|
||||||
('/image/load-big-image', 'GET', range(0, 500, 50), None),
|
|
||||||
('/static/big-image.png', 'GET', range(0, 500, 50), None),
|
|
||||||
('/static/video.mp4', 'GET', range(0, 10_000, 1_000), None),
|
|
||||||
]
|
|
||||||
|
|
||||||
def send_request(url, method = 'GET', payload = None):
|
def send_request(url, method = 'GET', payload = None):
|
||||||
success = False
|
success = False
|
||||||
|
@ -112,9 +102,6 @@ def run_tests(endpoint, method, num_requests, metadata):
|
||||||
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
|
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
|
||||||
record_resource(files[1], num_request, cpu, ram)
|
record_resource(files[1], num_request, cpu, ram)
|
||||||
|
|
||||||
generate_req_graph(files[0], FRAMEWORK_NAME, endpoint)
|
|
||||||
generate_resource_graph(files[1], FRAMEWORK_NAME, endpoint)
|
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
def get_resource_usage():
|
def get_resource_usage():
|
||||||
|
@ -147,8 +134,6 @@ def get_ram_usage(stats):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if not os.path.exists("data"):
|
if not os.path.exists("data"):
|
||||||
os.mkdir("data")
|
os.mkdir("data")
|
||||||
else:
|
|
||||||
os.system("rm -rf data/*")
|
|
||||||
|
|
||||||
for endpoint, method, num_requests, metadata in API_REQUESTS:
|
for endpoint, method, num_requests, metadata in API_REQUESTS:
|
||||||
print(f"# {endpoint}")
|
print(f"# {endpoint}")
|
||||||
|
|
Loading…
Reference in New Issue