Skip to content

Commit 48cfcd0

Browse files
committed
make benchmarks work in py 2.6
PYTHON-434
1 parent 4fd7c29 commit 48cfcd0

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

benchmarks/base.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import cassandra
3131
from cassandra.cluster import Cluster
3232
from cassandra.io.asyncorereactor import AsyncoreConnection
33-
from cassandra.policies import HostDistance
3433

3534
log = logging.getLogger()
3635
handler = logging.StreamHandler()
@@ -39,6 +38,16 @@
3938

4039
logging.getLogger('cassandra').setLevel(logging.WARN)
4140

41+
_log_levels = {
42+
'CRITICAL': logging.CRITICAL,
43+
'ERROR': logging.ERROR,
44+
'WARN': logging.WARNING,
45+
'WARNING': logging.WARNING,
46+
'INFO': logging.INFO,
47+
'DEBUG': logging.DEBUG,
48+
'NOTSET': logging.NOTSET,
49+
}
50+
4251
have_libev = False
4352
supported_reactors = [AsyncoreConnection]
4453
try:
@@ -91,11 +100,11 @@ def setup(options):
91100

92101
log.debug("Creating table...")
93102
create_table_query = """
94-
CREATE TABLE {} (
103+
CREATE TABLE {0} (
95104
thekey text,
96105
"""
97106
for i in range(options.num_columns):
98-
create_table_query += "col{} {},\n".format(i, options.column_type)
107+
create_table_query += "col{0} {1},\n".format(i, options.column_type)
99108
create_table_query += "PRIMARY KEY (thekey))"
100109

101110
try:
@@ -134,22 +143,22 @@ def benchmark(thread_class):
134143

135144
# Generate the query
136145
if options.read:
137-
query = "SELECT * FROM {} WHERE thekey = '{{key}}'".format(TABLE)
146+
query = "SELECT * FROM {0} WHERE thekey = '{{key}}'".format(TABLE)
138147
else:
139-
query = "INSERT INTO {} (thekey".format(TABLE)
148+
query = "INSERT INTO {0} (thekey".format(TABLE)
140149
for i in range(options.num_columns):
141-
query += ", col{}".format(i)
150+
query += ", col{0}".format(i)
142151

143152
query += ") VALUES ('{key}'"
144153
for i in range(options.num_columns):
145-
query += ", {}".format(COLUMN_VALUES[options.column_type])
154+
query += ", {0}".format(COLUMN_VALUES[options.column_type])
146155
query += ")"
147156

148157
values = None # we don't use that anymore. Keeping it in case we go back to prepared statements.
149158
per_thread = options.num_ops // options.threads
150159
threads = []
151160

152-
log.debug("Beginning {}...".format('reads' if options.read else 'inserts'))
161+
log.debug("Beginning {0}...".format('reads' if options.read else 'inserts'))
153162
start = time.time()
154163
try:
155164
for i in range(options.threads):
@@ -235,7 +244,11 @@ def parse_options():
235244

236245
options.hosts = options.hosts.split(',')
237246

238-
log.setLevel(options.log_level.upper())
247+
level = options.log_level.upper()
248+
try:
249+
log.setLevel(_log_levels[level])
250+
except KeyError:
251+
log.warn("Unknown log level specified: %s; specify one of %s", options.log_level, _log_levels.keys())
239252

240253
if options.asyncore_only:
241254
options.supported_reactors = [AsyncoreConnection]

0 commit comments

Comments
 (0)