Skip to content

Commit 9fa5dbe

Browse files
committed
Create graph.py
1 parent fba05c2 commit 9fa5dbe

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

graph.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from __future__ import annotations
2+
3+
import matplotlib.cm as mplcm
4+
import matplotlib.colors as colors
5+
import matplotlib.pyplot as plt
6+
import numpy as np
7+
8+
threads = [1, 2, 4, 8, 16, 32, 64, 128, 256]
9+
10+
data = {
11+
"local_main": {
12+
"avg": [[0.01], [0.03], [0.05], [0.09], [0.21], [0.38], [0.95], [4.05], [11.11]],
13+
"p50": [[0.01], [0.02], [0.03], [0.05], [0.12], [0.25], [0.67], [3.22], [9.8]],
14+
"p90": [[0.02], [0.05], [0.11], [0.23], [0.52], [0.94], [2.01], [8.88], [23.47]],
15+
"p99": [[0.02], [0.05], [0.11], [0.23], [0.52], [0.94], [2.01], [8.88], [23.47]],
16+
"p100": [[0.04], [0.21], [0.3], [0.58], [1.22], [2.59], [7.25], [17.03], [25.38]],
17+
},
18+
"local_original_1.5": {
19+
"avg": [[0.01], [0.02], [0.04], [0.09], [0.2], [0.35], [0.65], [1.14], [2.21]],
20+
"p50": [[0.01], [0.01], [0.01], [0.02], [0.06], [0.09], [0.2], [0.45], [1.91]],
21+
"p90": [[0.02], [0.04], [0.11], [0.22], [0.49], [0.81], [1.87], [3.72], [4.76]],
22+
"p99": [[0.02], [0.04], [0.11], [0.22], [0.49], [0.81], [1.87], [3.72], [4.76]],
23+
"p100": [[0.04], [0.62], [1.11], [3.33], [4.71], [6.07], [5.64], [6.05], [6.76]],
24+
},
25+
"local_original_2": {
26+
"avg": [[0.01], [0.02], [0.04], [0.09], [0.18], [0.39], [0.63], [1.23], [2.28]],
27+
"p50": [[0.01], [0.01], [0.01], [0.02], [0.02], [0.06], [0.17], [0.41], [1.9]],
28+
"p90": [[0.01], [0.02], [0.08], [0.21], [0.33], [1.24], [1.83], [3.82], [4.91]],
29+
"p99": [[0.01], [0.02], [0.08], [0.21], [0.33], [1.24], [1.83], [3.82], [4.91]],
30+
"p100": [[0.04], [1.3], [1.54], [3.07], [3.72], [5.55], [5.44], [6.42], [7.06]],
31+
},
32+
"local_server_algo": {
33+
"avg": [[0.01], [0.02], [0.05], [0.1], [0.19], [0.36], [0.73], [1.23], [2.19]],
34+
"p50": [[0.01], [0.01], [0.01], [0.01], [0.03], [0.09], [0.19], [0.59], [2.04]],
35+
"p90": [[0.02], [0.04], [0.1], [0.22], [0.51], [1.07], [2.37], [3.58], [4.74]],
36+
"p99": [[0.02], [0.04], [0.1], [0.22], [0.51], [1.07], [2.37], [3.58], [4.74]],
37+
"p100": [[0.09], [0.65], [1.35], [2.87], [3.31], [4.4], [6.55], [5.84], [6.88]],
38+
},
39+
}
40+
41+
42+
metrics = ["avg", "p90", "p100"]
43+
metric_titles = {
44+
"avg": "Average Latency",
45+
"p50": "p50 Latency",
46+
"p90": "p90 Latency",
47+
"p99": "p99 Latency",
48+
"p100": "p100 (Max) Latency",
49+
}
50+
51+
plt.figure(figsize=(16, 4 * len(metrics)))
52+
NUM_COLORS = len(data.keys()) + 1
53+
cm = plt.get_cmap("gist_rainbow")
54+
cNorm = colors.Normalize(vmin=0, vmax=NUM_COLORS - 1)
55+
scalarMap = mplcm.ScalarMappable(norm=cNorm, cmap=cm)
56+
for i, metric in enumerate(metrics, 1):
57+
if metric in ["avg"]:
58+
ax = plt.subplot(len(metrics), 2, i)
59+
else:
60+
ax = plt.subplot(len(metrics), 2, (i - 1) * (2) + 1)
61+
ax.set_prop_cycle(color=[scalarMap.to_rgba(i) for i in range(NUM_COLORS)])
62+
order = []
63+
for label, vals in data.items():
64+
if metric not in vals:
65+
continue
66+
arr = np.concatenate(np.around(np.array(vals[metric]), decimals=2))
67+
order.append(plt.plot(threads, arr, "o-", label=label))
68+
69+
plt.title(metric_titles[metric])
70+
plt.xscale("log", base=2)
71+
plt.xlabel("Threads")
72+
plt.ylabel("Seconds")
73+
plt.xticks(threads, threads)
74+
plt.grid(True, which="both", axis="x", linestyle="--", alpha=0.5)
75+
plt.axhline(y=0, color="gray", linestyle="-")
76+
if metric != "p90":
77+
plt.legend().set_visible(False)
78+
else:
79+
plt.legend(loc=(1.01, 0.5), fontsize=8)
80+
81+
plt.tight_layout()
82+
plt.show()

0 commit comments

Comments
 (0)