mirror of https://github.com/ivanch/tcc.git
adding boxplot
This commit is contained in:
parent
77aa085b0c
commit
62b8b70689
|
@ -1,8 +1,8 @@
|
|||
FRAMEWORKS = [
|
||||
('Actix', 'tcc-actix'),
|
||||
('ASP.NET', 'tcc-aspnet'),
|
||||
('Flask', 'tcc-flask'),
|
||||
('Express', 'tcc-express'),
|
||||
('Actix', 'tcc-actix', 'orange'),
|
||||
('ASP.NET', 'tcc-aspnet', 'blue'),
|
||||
('Flask', 'tcc-flask', 'green'),
|
||||
('Express', 'tcc-express', 'red'),
|
||||
]
|
||||
|
||||
ENDPOINTS = {
|
||||
|
@ -12,14 +12,13 @@ ENDPOINTS = {
|
|||
'Express': 'http://localhost:9084',
|
||||
}
|
||||
|
||||
BLUR_RADIUS = 5
|
||||
AVG_RUNS = 3
|
||||
AVG_RUNS = 5
|
||||
|
||||
API_REQUESTS = [
|
||||
('/status/ok', '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()),
|
||||
# (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),
|
||||
('/static/small-image.png', 'GET', range(0, 30_000, 5000), None),
|
||||
('/image/load-big-image', 'GET', range(0, 500, 50), None),
|
||||
|
|
|
@ -1,54 +1,63 @@
|
|||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
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):
|
||||
for i, framework in enumerate(FRAMEWORKS):
|
||||
plt.plot(x_data, y_data[i], markersize=1, linewidth=1, linestyle='solid', label=framework)
|
||||
def setBoxColors(bp):
|
||||
for i, box in enumerate(bp['boxes']):
|
||||
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.xlabel(x_label)
|
||||
plt.ylabel(y_label)
|
||||
plt.legend()
|
||||
plt.savefig(f'{filename}.png')
|
||||
|
||||
plt.clf()
|
||||
plt.close('all')
|
||||
if y_lim:
|
||||
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):
|
||||
frameworks[framework] = y_data[i]
|
||||
|
||||
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)
|
||||
h, = plt.plot([], c=FRAMEWORKS_COLORS[i], label=framework)
|
||||
# h.set_visible(False)
|
||||
|
||||
plt.legend()
|
||||
plt.savefig(f'{filename}.png')
|
||||
|
||||
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])
|
||||
|
||||
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__':
|
||||
endpoints = [config[0] for config in API_REQUESTS]
|
||||
|
|
|
@ -61,14 +61,13 @@ def run_tests(endpoint, method, num_requests, metadata):
|
|||
for num_request in num_requests:
|
||||
if num_request <= 0: continue
|
||||
|
||||
total_cpu, total_ram = 0, 0
|
||||
total_time = 0
|
||||
|
||||
for run in range(AVG_RUNS):
|
||||
ok_responses = 0
|
||||
bad_responses = 0
|
||||
server_errors = 0
|
||||
|
||||
cpu, ram = 0, 0
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=THREADS) as executor:
|
||||
url = f'{URL_BASE}{endpoint}'
|
||||
|
||||
|
@ -84,13 +83,10 @@ def run_tests(endpoint, method, num_requests, metadata):
|
|||
|
||||
if i == half:
|
||||
cpu, ram = get_resource_usage()
|
||||
total_cpu += float(cpu)
|
||||
total_ram += float(ram)
|
||||
|
||||
concurrent.futures.wait(futures)
|
||||
|
||||
elapsed_time = time.time() - start_time
|
||||
total_time += elapsed_time
|
||||
|
||||
for future in futures:
|
||||
responses = future.result()
|
||||
|
@ -103,15 +99,11 @@ def run_tests(endpoint, method, num_requests, metadata):
|
|||
client = docker.from_env()
|
||||
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)
|
||||
|
||||
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():
|
||||
if CONTAINER_NAME == "": return 0, 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue