Skip to content

Commit 86a793f

Browse files
committed
Add read benchmark support
1 parent 3673fe0 commit 86a793f

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

benchmarks/base.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,30 @@ def benchmark(thread_class):
131131
log.debug("Sleeping for two seconds...")
132132
time.sleep(2.0)
133133

134-
# Generate the INSERT query
135-
insert_query = "INSERT INTO {} (thekey".format(TABLE)
136-
for i in range(options.num_columns):
137-
insert_query += ", col{}".format(i)
138-
139-
insert_query += ") VALUES ('{key}'"
140134

141-
for i in range(options.num_columns):
142-
insert_query += ", {}".format(COLUMN_VALUES[options.column_type])
143-
insert_query += ")"
135+
# Generate the query
136+
if options.read:
137+
query = "SELECT * FROM {} WHERE thekey = '{{key}}'".format(TABLE)
138+
else:
139+
query = "INSERT INTO {} (thekey".format(TABLE)
140+
for i in range(options.num_columns):
141+
query += ", col{}".format(i)
144142

145-
values = None
143+
query += ") VALUES ('{key}'"
144+
for i in range(options.num_columns):
145+
query += ", {}".format(COLUMN_VALUES[options.column_type])
146+
query += ")"
146147

148+
values = None # we don't use that anymore. Keeping it in case we go back to prepared statements.
147149
per_thread = options.num_ops // options.threads
148150
threads = []
149151

150-
log.debug("Beginning inserts...")
152+
log.debug("Beginning {}...".format('reads' if options.read else 'inserts'))
151153
start = time.time()
152154
try:
153155
for i in range(options.threads):
154156
thread = thread_class(
155-
i, session, insert_query, values, per_thread,
157+
i, session, query, values, per_thread,
156158
cluster.protocol_version, options.profile)
157159
thread.daemon = True
158160
threads.append(thread)
@@ -225,6 +227,8 @@ def parse_options():
225227
help='Keep the data after the benchmark')
226228
parser.add_option('--column-type', type='str', dest='column_type', default='text',
227229
help='Specify the column type for the schema (supported: int, text, float, uuid, timestamp)')
230+
parser.add_option('--read', action='store_true', dest='read', default=False,
231+
help='Read mode')
228232

229233

230234
options, args = parser.parse_args()
@@ -269,6 +273,9 @@ def start_profile(self):
269273
if self.profiler:
270274
self.profiler.enable()
271275

276+
def run_query(self, key, **kwargs):
277+
return self.session.execute_async(self.query.format(key=key), **kwargs)
278+
272279
def finish_profile(self):
273280
if self.profiler:
274281
self.profiler.disable()

benchmarks/callback_full_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def insert_next(self, previous_result=sentinel):
4444
i = next(self.num_started)
4545
if i <= self.num_queries:
4646
key = "{}-{}".format(self.thread_num, i)
47-
future = self.session.execute_async(self.query.format(key=key), timeout=None)
47+
future = self.run_query(key, timeout=None)
4848
future.add_callbacks(self.insert_next, self.insert_next)
4949

5050
def run(self):

benchmarks/future_batches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run(self):
3636
break
3737

3838
key = "{}-{}".format(self.thread_num, i)
39-
future = self.session.execute_async(self.query.format(key=key))
39+
future = self.run_query(key)
4040
futures.put_nowait(future)
4141

4242
while True:

benchmarks/future_full_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def run(self):
3232
old_future.result()
3333

3434
key = "{}-{}".format(self.thread_num, i)
35-
future = self.session.execute_async(self.query.format(key=key))
35+
future = self.run_query(key)
3636
futures.put_nowait(future)
3737

3838
while True:

benchmarks/future_full_throttle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def run(self):
2727

2828
for i in range(self.num_queries):
2929
key = "{}-{}".format(self.thread_num, i)
30-
future = self.session.execute_async(self.query.format(key=key))
30+
future = self.run_query(key)
3131
futures.append(future)
3232

3333
for future in futures:

0 commit comments

Comments
 (0)