forked from apache/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_request_metrics_local_remote_test.py
197 lines (149 loc) · 6.29 KB
/
client_request_metrics_local_remote_test.py
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
188
189
190
191
192
193
194
195
196
197
from dtest import Tester, create_ks
from tools.jmxutils import JolokiaAgent, make_mbean
import pytest
since = pytest.mark.since
@since('4.1')
class TestClientRequestMetricsLocalRemote(Tester):
def test_write_and_read(self):
session, node = setup_test(self)
read_metrics = ClientRequestMetricsContainer(node, 'Read')
write_metrics = ClientRequestMetricsContainer(node, 'Write')
# Get initial results:
r1_r = ClientRequestMetricsSnapshot(read_metrics)
r1_w = ClientRequestMetricsSnapshot(write_metrics)
# Run Write test:
for i in murmur3_hashes.keys():
session.execute(
"INSERT INTO ks.test (id, ord, val) VALUES ({}, 1, 'aaaa');".format(i)
)
# Collect results:
r2_r = ClientRequestMetricsSnapshot(read_metrics)
r2_w = ClientRequestMetricsSnapshot(write_metrics)
# Run Read test:
for i in murmur3_hashes.keys():
session.execute(
"SELECT (id, ord, val) FROM ks.test WHERE id={};".format(i)
)
# Collect results:
r3_r = ClientRequestMetricsSnapshot(read_metrics)
r3_w = ClientRequestMetricsSnapshot(write_metrics)
assert 0 <= (r2_w.remote_requests - r1_w.remote_requests)
assert 0 <= (r2_r.local_requests - r1_r.local_requests)
assert 0 == (r2_r.remote_requests - r1_r.remote_requests)
assert 0 == (r3_w.local_requests - r2_w.local_requests)
assert 0 == (r3_w.remote_requests - r2_w.remote_requests)
assert 0 < (r3_r.remote_requests - r2_r.remote_requests)
def test_batch_and_slice(self):
session, node = setup_test(self)
read_metrics = ClientRequestMetricsContainer(node, 'Read')
write_metrics = ClientRequestMetricsContainer(node, 'Write')
# Get initial results:
r1_r = ClientRequestMetricsSnapshot(read_metrics)
r1_w = ClientRequestMetricsSnapshot(write_metrics)
# Run batch test:
query = 'BEGIN BATCH '
for i in murmur3_hashes.keys():
for y in range(0, 50):
query += "INSERT INTO ks.test (id, ord, val) VALUES ({}, {}, 'aaa')".format(i, y)
query += 'APPLY BATCH;'
session.execute(query)
# Collect results:
r2_r = ClientRequestMetricsSnapshot(read_metrics)
r2_w = ClientRequestMetricsSnapshot(write_metrics)
# Run read range test:
for i in murmur3_hashes.keys():
session.execute("""
SELECT (id, ord, val) FROM ks.test
WHERE id={}
AND ord > 0
AND ord < 100;
""".format(i))
# Collect results:
r3_r = ClientRequestMetricsSnapshot(read_metrics)
r3_w = ClientRequestMetricsSnapshot(write_metrics)
assert 0 <= (r2_w.remote_requests - r1_w.remote_requests)
assert 0 <= (r2_r.local_requests - r1_r.local_requests)
assert 0 == (r2_r.remote_requests - r1_r.remote_requests)
assert 0 == (r3_w.local_requests - r2_w.local_requests)
assert 0 == (r3_w.remote_requests - r2_w.remote_requests)
assert 0 < (r3_r.remote_requests - r2_r.remote_requests)
def test_paxos(self):
session, node = setup_test(self)
read_metrics = ClientRequestMetricsContainer(node, 'Read')
write_metrics = ClientRequestMetricsContainer(node, 'Write')
# Get initial results:
r1_r = ClientRequestMetricsSnapshot(read_metrics)
r1_w = ClientRequestMetricsSnapshot(write_metrics)
# Run write test:
for i in murmur3_hashes.keys():
session.execute(
"UPDATE ks.test SET val='aaa' WHERE id={} AND ord=0".format(i)
)
# Collect results:
r2_r = ClientRequestMetricsSnapshot(read_metrics)
r2_w = ClientRequestMetricsSnapshot(write_metrics)
assert 0 <= (r2_w.remote_requests - r1_w.remote_requests)
assert 0 <= (r2_r.local_requests - r1_r.local_requests)
assert 0 == (r2_r.remote_requests - r1_r.remote_requests)
murmur3_hashes = {
5: -7509452495886106294,
10: -6715243485458697746,
16: -5477287129830487822,
13: -5034495173465742853,
11: -4156302194539278891,
1: -4069959284402364209,
19: -3974532302236993209,
8: -3799847372828181882,
2: -3248873570005575792,
4: -2729420104000364805,
18: -2695747960476065067,
15: -1191135763843456182,
20: 1388667306199997068,
7: 1634052884888577606,
6: 2705480034054113608,
9: 3728482343045213994,
14: 4279681877540623768,
17: 5467144456125416399,
12: 8582886034424406875,
3: 9010454139840013625
}
class ClientRequestMetricsContainer:
def __init__(self, node, scope):
self.node = node
self.local_requests_mbean = make_mbean(
'metrics',
type='ClientRequest',
scope=scope,
name='LocalRequests'
)
self.remote_requests_mbean = make_mbean(
'metrics',
type='ClientRequest',
scope=scope,
name='RemoteRequests'
)
def get_local_requests(self):
with JolokiaAgent(self.node) as jmx:
return jmx.read_attribute(self.local_requests_mbean, 'Count')
def get_remote_requests(self):
with JolokiaAgent(self.node) as jmx:
return jmx.read_attribute(self.remote_requests_mbean, 'Count')
class ClientRequestMetricsSnapshot:
def __init__(self, client_request_metrics):
self.local_requests = client_request_metrics.get_local_requests()
self.remote_requests = client_request_metrics.get_remote_requests()
def setup_schema(session):
create_ks(session, 'ks', 1)
session.execute("CREATE TABLE test (id int,ord int,val varchar,PRIMARY KEY (id, ord));""")
def setup_test(obj):
cluster = obj.cluster
cluster.populate(2)
node = cluster.nodelist()[0]
node2 = cluster.nodelist()[1]
cluster.start()
# wait for auth setup so we don't have to compensate for the reads/writes it may trigger
node.watch_log_for("Created default superuser role 'cassandra'", timeout=60)
session = obj.patient_exclusive_cql_connection(node)
obj.patient_exclusive_cql_connection(node2)
setup_schema(session)
return session, node