@@ -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 ()
0 commit comments