-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotter.py
More file actions
187 lines (159 loc) · 7.06 KB
/
plotter.py
File metadata and controls
187 lines (159 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import matplotlib.pyplot as plt
import numpy as np
def plot_all_vs_contention(metrics_lists, fixed_threads):
"""
Plots throughput vs contention for a fixed number of threads.
Args:
metrics_list (list of dict): Each dict should have keys 'throughput', 'contention', 'num_threads'
fixed_threads (int): The fixed number of threads to filter by
method_name (str): The concurrency control method name (e.g., 'CCC', 'OCC')
"""
# Filter data for fixed threads
occ_metrics = metrics_lists[0]
twoPL_metrics = metrics_lists[1]
filtered_occ = [m for m in occ_metrics if m['num_threads'] == fixed_threads]
filtered_twoPL = [m for m in twoPL_metrics if m['num_threads'] == fixed_threads]
if not filtered_occ and not filtered_twoPL:
print(f"No data found for {fixed_threads} threads.")
return
occ_contentions = [m['contention'] for m in filtered_occ]
occ_throughputs = [m['throughput'] for m in filtered_occ]
occ_aborts = [m['aborts'] for m in filtered_occ]
occ_response_times = [m['average_response_time'] for m in filtered_occ]
twoPL_contentions = [m['contention'] for m in filtered_twoPL]
twoPL_throughputs = [m['throughput'] for m in filtered_twoPL]
twoPL_aborts = [m['aborts'] for m in filtered_twoPL]
twoPL_response_times = [m['average_response_time'] for m in filtered_twoPL]
# Plot OCC and TwoPL on the same graph for comparison
plt.figure(figsize=(6, 4))
plt.plot(occ_contentions, occ_throughputs, marker='o', color='red')
plt.plot(twoPL_contentions, twoPL_throughputs, marker='s', color='blue')
plt.legend(['OCC', '2PL'])
title = f'Throughput vs Contention (Threads: {fixed_threads})'
plt.title(title)
plt.xlabel('Contention')
plt.ylabel('Throughput')
plt.grid(True)
plt.savefig(f'Graph_t_vs_c_threads_{fixed_threads}.png')
plt.show()
plt.figure(figsize=(6, 4))
plt.plot(occ_contentions, occ_aborts, marker='o', color='red')
plt.plot(twoPL_contentions, twoPL_aborts, marker='s', color='blue')
plt.legend(['OCC', '2PL'])
title = f'Aborts vs Contention (Threads: {fixed_threads})'
plt.title(title)
plt.xlabel('Contention')
plt.ylabel('Aborts')
plt.grid(True)
plt.savefig(f'Graph_a_vs_c_threads_{fixed_threads}.png')
plt.show()
plt.figure(figsize=(6, 4))
plt.plot(occ_contentions, occ_response_times, marker='o', color='red')
plt.plot(twoPL_contentions, twoPL_response_times, marker='s', color='blue')
plt.legend(['OCC', '2PL'])
title = f'Average Response Time vs Contention (Threads: {fixed_threads})'
plt.title(title)
plt.xlabel('Contention')
plt.ylabel('Average Response Time (s)')
plt.grid(True)
plt.savefig(f'Graph_r_vs_c_threads_{fixed_threads}.png')
plt.show()
def plot_all_vs_threads(metrics_lists, fixed_contention):
"""
Plots throughput vs number of threads for a fixed contention.
Args:
metrics_list (list of dict): Each dict should have keys 'throughput', 'contention', 'num_threads'
fixed_contention (float): The fixed contention value to filter by
method_name (str): The concurrency control method name (e.g., 'CCC', 'OCC')
"""
occ_metrics = metrics_lists[0]
twoPL_metrics = metrics_lists[1]
filtered_occ = [m for m in occ_metrics if m['contention'] == fixed_contention]
filtered_twoPL = [m for m in twoPL_metrics if m['contention'] == fixed_contention]
# Filter data for fixed contention
if not filtered_occ and not filtered_twoPL:
print(f"No data found for contention {fixed_contention}.")
return
occ_num_threads = [m['num_threads'] for m in filtered_occ]
occ_throughputs = [m['throughput'] for m in filtered_occ]
occ_aborts = [m['aborts'] for m in filtered_occ]
occ_response_times = [m['average_response_time'] for m in filtered_occ]
twoPL_num_threads = [m['num_threads'] for m in filtered_twoPL]
twoPL_throughputs = [m['throughput'] for m in filtered_twoPL]
twoPL_aborts = [m['aborts'] for m in filtered_twoPL]
twoPL_response_times = [m['average_response_time'] for m in filtered_twoPL]
plt.figure(figsize=(6, 4))
plt.plot(occ_num_threads, occ_throughputs, marker='o', color='red')
plt.plot(twoPL_num_threads, twoPL_throughputs, marker='s', color='blue')
plt.legend(['OCC', '2PL'])
title = f'Throughput vs Number of Threads (Contention: {fixed_contention})'
plt.title(title)
plt.xlabel('Number of Threads')
plt.ylabel('Throughput')
plt.grid(True)
plt.savefig(f'Graph_t_vs_t_contention_{fixed_contention}.png')
plt.show()
plt.figure(figsize=(6, 4))
plt.plot(occ_num_threads, occ_aborts, marker='o', color='red')
plt.plot(twoPL_num_threads, twoPL_aborts, marker='s', color='blue')
title = f'Aborts vs Number of Threads (Contention: {fixed_contention})'
plt.legend(['OCC', '2PL'])
plt.title(title)
plt.xlabel('Number of Threads')
plt.ylabel('Aborts')
plt.grid(True)
plt.savefig(f'Graph_a_vs_t_contention_{fixed_contention}.png')
plt.show()
plt.figure(figsize=(6, 4))
plt.plot(occ_num_threads, occ_response_times, marker='o', color='red')
plt.plot(twoPL_num_threads, twoPL_response_times, marker='s', color='blue')
title = f'Average Response Time vs Number of Threads (Contention: {fixed_contention})'
plt.legend(['OCC', '2PL'])
plt.title(title)
plt.xlabel('Number of Threads')
plt.ylabel('Average Response Time (s)')
plt.grid(True)
plt.savefig(f'Graph_r_vs_t_contention_{fixed_contention}.png')
plt.show()
def plot_resp_time_distribution(occ_response_times, twoPL_response_times):
plt.figure(figsize=(7,4))
combined = occ_response_times + twoPL_response_times
bins = np.arange(min(combined), max(combined)+2) - 0.5
plt.hist(
occ_response_times,
bins=bins,
alpha=0.6,
label="OCC (Validation)",
edgecolor="black"
)
plt.hist(
twoPL_response_times,
bins=bins,
alpha=0.6,
label="2PL (CCC)",
edgecolor="black"
)
plt.title("Distribution of Transaction Response Times")
plt.xlabel("Response Time")
plt.ylabel("Frequency")
plt.legend()
plt.grid(True, linestyle="--", alpha=0.5)
plt.tight_layout()
plt.savefig("Graph_resp_time_distribution.png", dpi=300)
plt.show()
# Example usage (you can remove this when integrating)
if __name__ == "__main__":
# Sample data
sample_metrics = [
{'throughput': 100, 'contention': 0.1, 'num_threads': 5},
{'throughput': 90, 'contention': 0.2, 'num_threads': 5},
{'throughput': 80, 'contention': 0.3, 'num_threads': 5},
{'throughput': 70, 'contention': 0.4, 'num_threads': 5},
{'throughput': 65, 'contention': 0.5, 'num_threads': 5},
{'throughput': 60, 'contention': 0.6, 'num_threads': 5},
{'throughput': 110, 'contention': 0.1, 'num_threads': 10},
{'throughput': 95, 'contention': 0.1, 'num_threads': 15},
{'throughput': 85, 'contention': 0.1, 'num_threads': 20},
]
plot_all_vs_contention(sample_metrics, 5)
plot_all_vs_threads(sample_metrics, 0.1)