improving tests scripts

This commit is contained in:
José Henrique Ivanchechen 2024-03-24 19:31:53 -03:00
parent a920b36386
commit e547ae41d4
3 changed files with 21 additions and 41 deletions

View File

@ -34,14 +34,14 @@ ENDPOINTS = {
'Spring': 'http://localhost:9085', 'Spring': 'http://localhost:9085',
} }
AVG_RUNS = 5 AVG_RUNS = 30
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', 'POST', range(0, 30_000, 5000), (person_json, "application/json")), ('/simulation/json', 'POST', range(0, 30_000, 5000), (person_json, "application/json")),
('/simulation/protobuf', 'POST', range(0, 30_000, 5000), (person_proto, "application/protobuf")),
('/image/save-big-image', 'POST', range(0, 500, 50), (open('big-image.png', 'rb').read(), "image/png")), ('/image/save-big-image', 'POST', range(0, 500, 50), (open('big-image.png', 'rb').read(), "image/png")),
('/static/small-image.png', 'GET', range(0, 30_000, 5000), None), ('/static/small-image.png', 'GET', range(0, 30_000, 5000), None),
('/static/big-image.png', 'GET', range(0, 500, 50), None), ('/static/big-image.png', 'GET', range(0, 500, 50), None),
# ('/simulation/protobuf', 'POST', range(0, 30_000, 5000), (person_proto, "application/protobuf")),
] ]

View File

@ -10,19 +10,20 @@ FRAMEWORKS = [f for f, _, _ in FRAMEWORKS]
def setBoxColors(bp): def setBoxColors(bp):
for i, box in enumerate(bp['boxes']): for i, box in enumerate(bp['boxes']):
box.set(color=FRAMEWORKS_COLORS[i]) box.set(color=FRAMEWORKS_COLORS[i])
for i, median in enumerate(bp['medians']): box.set(facecolor=FRAMEWORKS_COLORS[i])
# median.set(color=FRAMEWORKS_COLORS[i])
median.set(color='white')
for i in range(len(FRAMEWORKS)): for i in range(len(FRAMEWORKS)):
bp['whiskers'][i*2].set(color=FRAMEWORKS_COLORS[i]) bp['whiskers'][i*2].set(color=FRAMEWORKS_COLORS[i])
bp['whiskers'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i]) bp['whiskers'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i])
for i in range(len(FRAMEWORKS)): for i in range(len(FRAMEWORKS)):
bp['caps'][i*2].set(color=FRAMEWORKS_COLORS[i]) bp['caps'][i*2].set(color=FRAMEWORKS_COLORS[i])
bp['caps'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i]) bp['caps'][i*2 + 1].set(color=FRAMEWORKS_COLORS[i])
for i, median in enumerate(bp['medians']):
median.set(color='white')
def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None): def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
print(filename)
old_x_data = x_data old_x_data = x_data
old_y_data = y_data old_y_data = y_data
@ -39,40 +40,20 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
for f in range(len(FRAMEWORKS)): for f in range(len(FRAMEWORKS)):
y_data[-1][f].append(old_y_data[f][i]) y_data[-1][f].append(old_y_data[f][i])
fig = figure() fig, axes = plt.subplots(ncols=len(x_data), sharey=True)
ax = axes()
all_positions = [] for ax, j in zip(axes, [i for i in range(len(x_data))]):
bp = ax.boxplot(y_data[j], showfliers=False, patch_artist=True, positions=[i for i in range(len(FRAMEWORKS))])
print(filename) ax.set(xlabel=x_data[j], xticklabels=['' for _ in range(len(FRAMEWORKS))])
# print(y_data) ax.margins(0.05)
for j in range(len(x_data)):
positions = [len(FRAMEWORKS)*j + i + 2*j for i in range(len(FRAMEWORKS))]
bp = boxplot(y_data[j], positions = positions, widths = 0.6, showfliers=False,
patch_artist=True)
all_positions.append(positions)
setBoxColors(bp) setBoxColors(bp)
if j % 2 == 1:
ax.set_facecolor('#f2f2f2')
for i in range(len(FRAMEWORKS)): # set title
medians = [] fig.suptitle(title)
for j in range(len(x_data)): fig.supxlabel(x_label)
medians.append(np.median(y_data[j][i])) fig.supylabel(y_label)
positions = [all_positions[x][i] for x in range(len(x_data))]
plt.plot(positions, medians, color=FRAMEWORKS_COLORS[i], marker='.', linestyle='--', linewidth=0.3)
avg_positions = []
for positions in all_positions:
avg = np.average(positions)
avg_positions.append(avg)
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)
if y_lim: if y_lim:
plt.ylim(y_lim) plt.ylim(y_lim)
@ -85,6 +66,7 @@ def plot_graph(x_data, y_data, title, x_label, y_label, filename, y_lim = None):
plt.legend() plt.legend()
plt.tight_layout() plt.tight_layout()
fig.subplots_adjust(hspace=0, wspace=0)
plt.savefig(f'{filename}.png') plt.savefig(f'{filename}.png')
plt.clf() plt.clf()

View File

@ -76,8 +76,6 @@ def run_tests(endpoint, method, num_requests, metadata):
start_time = time.time() start_time = time.time()
futures = [] futures = []
#with requests.Session() as session:
# futures = [executor.submit(send_request, session, url) for _ in range(num_request)]
half = floor(num_request/2) half = floor(num_request/2)
for i in range(num_request): for i in range(num_request):
@ -104,7 +102,7 @@ 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)
time.sleep(3) time.sleep(30)
def get_resource_usage(): def get_resource_usage():
if CONTAINER_NAME == "": return 0, 0 if CONTAINER_NAME == "": return 0, 0