adding boxplot

This commit is contained in:
José Henrique 2023-10-29 19:01:24 -03:00
parent 77aa085b0c
commit 62b8b70689
3 changed files with 60 additions and 60 deletions

View File

@ -1,8 +1,8 @@
FRAMEWORKS = [ FRAMEWORKS = [
('Actix', 'tcc-actix'), ('Actix', 'tcc-actix', 'orange'),
('ASP.NET', 'tcc-aspnet'), ('ASP.NET', 'tcc-aspnet', 'blue'),
('Flask', 'tcc-flask'), ('Flask', 'tcc-flask', 'green'),
('Express', 'tcc-express'), ('Express', 'tcc-express', 'red'),
] ]
ENDPOINTS = { ENDPOINTS = {
@ -12,18 +12,17 @@ ENDPOINTS = {
'Express': 'http://localhost:9084', 'Express': 'http://localhost:9084',
} }
BLUR_RADIUS = 5 AVG_RUNS = 5
AVG_RUNS = 3
API_REQUESTS = [ API_REQUESTS = [
('/status/ok', 'GET', range(0, 30_000, 5000), None), ('/status/ok', 'GET', range(0, 30_000, 5000), None),
('/simulation/harmonic-progression?n=100000', 'GET', range(0, 30_000, 5000), None), ('/simulation/harmonic-progression?n=100000', 'GET', range(0, 30_000, 5000), None),
('/simulation/json', 'GET', range(0, 30_000, 5000), None),
('/image/save-big-image', 'POST', range(0, 500, 50), open('big-image.png', 'rb').read()), ('/image/save-big-image', 'POST', range(0, 500, 50), open('big-image.png', 'rb').read()),
# (f'/image/blur?radius={BLUR_RADIUS}', 'POST', range(0, 500, 50), open('small-image.png', 'rb').read()),
('/image/load-small-image', '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), ('/static/small-image.png', 'GET', range(0, 30_000, 5000), None),
('/image/load-big-image', 'GET', range(0, 500, 50), None), ('/image/load-big-image', 'GET', range(0, 500, 50), None),
('/static/big-image.png', '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), ('/static/video.mp4', 'GET', range(0, 10_000, 1_000), None),
('/static/nginx.html', 'GET', range(0, 30_000, 5000), None), ('/static/nginx.html', 'GET', range(0, 30_000, 5000), None),
] ]

View File

@ -1,54 +1,63 @@
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from common import API_REQUESTS, FRAMEWORKS from common import API_REQUESTS, FRAMEWORKS
from pylab import plot, show, savefig, xlim, figure, \
ylim, legend, boxplot, setp, axes
FRAMEWORKS = [f for f, _ in FRAMEWORKS] FRAMEWORKS_COLORS = [c for _, _, c in FRAMEWORKS]
FRAMEWORKS = [f for f, _, _ in FRAMEWORKS]
def plot_graph(x_data, y_data, title, x_label, y_label, filename): def setBoxColors(bp):
for i, framework in enumerate(FRAMEWORKS): for i, box in enumerate(bp['boxes']):
plt.plot(x_data, y_data[i], markersize=1, linewidth=1, linestyle='solid', label=framework) box.set(color=FRAMEWORKS_COLORS[i])
def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
old_x_data = x_data
old_y_data = y_data
x_data = []
y_data = []
for i in range(len(old_x_data)):
if old_x_data[i] not in x_data:
x_data.append(old_x_data[i])
y_data.append([])
for f in range(2):
y_data[-1].append([])
for f in range(2):
y_data[-1][f].append(old_y_data[f][i])
fig = figure()
ax = axes()
all_positions = []
for j in range(len(x_data)):
positions = [len(FRAMEWORKS)*j + i + 1 for i in range(len(FRAMEWORKS))]
bp = boxplot(y_data[j], positions = positions, widths = 0.6)
all_positions.append(positions)
setBoxColors(bp)
avg_positions = []
for positions in all_positions:
avg_positions.append(np.average(positions))
ax.set_xticks(avg_positions)
ax.set_xticklabels([str(x) for x in x_data])
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.clf() if y_lim:
plt.close('all') plt.ylim(y_lim)
def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
requests = x_data
frameworks = {}
print(y_data)
for i, framework in enumerate(FRAMEWORKS): for i, framework in enumerate(FRAMEWORKS):
frameworks[framework] = y_data[i] h, = plt.plot([], c=FRAMEWORKS_COLORS[i], label=framework)
# h.set_visible(False)
x = np.arange(len(requests))
width = 0.2
multiplier = 0
fig, ax = plt.subplots(layout='constrained', figsize=(7.5, 5))
print(x)
for framework, measurements in frameworks.items():
print(framework, measurements)
for attribute, measurement in frameworks.items():
offset = width * multiplier
rects = ax.bar(x + offset, measurement, width, label=attribute)
ax.bar_label(rects, padding=3)
multiplier += 1
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
ax.set_title(title)
ax.set_xticks(x + (width*1.5), requests)
ax.legend(loc='upper left', ncols=len(frameworks.items()))
ax.set_ylim(0, 115)
plt.legend()
plt.savefig(f'{filename}.png') plt.savefig(f'{filename}.png')
plt.clf() plt.clf()
@ -116,7 +125,7 @@ def generate_resource_graph(filename, framework_name, endpoint_name):
y.append([data[resource_index] for data in y_data]) y.append([data[resource_index] for data in y_data])
graph_file = f'{resource}_{endpoint_name.replace("/", "").replace("?", "")}' 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', f'Uso de {resource.upper()} (%)', graph_file) plot_graph(x, y, f'Uso de {resource.upper()} - {endpoint_name}', 'Número de requisições', f'Uso de {resource.upper()} (%)', graph_file)
if __name__ == '__main__': if __name__ == '__main__':
endpoints = [config[0] for config in API_REQUESTS] endpoints = [config[0] for config in API_REQUESTS]

View File

@ -61,14 +61,13 @@ def run_tests(endpoint, method, num_requests, metadata):
for num_request in num_requests: for num_request in num_requests:
if num_request <= 0: continue if num_request <= 0: continue
total_cpu, total_ram = 0, 0
total_time = 0
for run in range(AVG_RUNS): for run in range(AVG_RUNS):
ok_responses = 0 ok_responses = 0
bad_responses = 0 bad_responses = 0
server_errors = 0 server_errors = 0
cpu, ram = 0, 0
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor: with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
url = f'{URL_BASE}{endpoint}' url = f'{URL_BASE}{endpoint}'
@ -84,13 +83,10 @@ def run_tests(endpoint, method, num_requests, metadata):
if i == half: if i == half:
cpu, ram = get_resource_usage() cpu, ram = get_resource_usage()
total_cpu += float(cpu)
total_ram += float(ram)
concurrent.futures.wait(futures) concurrent.futures.wait(futures)
elapsed_time = time.time() - start_time elapsed_time = time.time() - start_time
total_time += elapsed_time
for future in futures: for future in futures:
responses = future.result() responses = future.result()
@ -103,15 +99,11 @@ def run_tests(endpoint, method, num_requests, metadata):
client = docker.from_env() client = docker.from_env()
client.containers.get(CONTAINER_NAME).restart() client.containers.get(CONTAINER_NAME).restart()
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
record_resource(files[1], num_request, cpu, ram)
time.sleep(3) time.sleep(3)
cpu = total_cpu / AVG_RUNS
ram = total_ram / AVG_RUNS
elapsed_time = total_time / AVG_RUNS
record(files[0], num_request, f"{num_request/elapsed_time:.2f}")
record_resource(files[1], num_request, cpu, ram)
def get_resource_usage(): def get_resource_usage():
if CONTAINER_NAME == "": return 0, 0 if CONTAINER_NAME == "": return 0, 0