Add twisted reactor to benchmarking tools
This commit is contained in:
@@ -26,6 +26,7 @@ dirname = os.path.dirname(os.path.abspath(__file__))
|
|||||||
sys.path.append(dirname)
|
sys.path.append(dirname)
|
||||||
sys.path.append(os.path.join(dirname, '..'))
|
sys.path.append(os.path.join(dirname, '..'))
|
||||||
|
|
||||||
|
import cassandra
|
||||||
from cassandra.cluster import Cluster
|
from cassandra.cluster import Cluster
|
||||||
from cassandra.io.asyncorereactor import AsyncoreConnection
|
from cassandra.io.asyncorereactor import AsyncoreConnection
|
||||||
from cassandra.policies import HostDistance
|
from cassandra.policies import HostDistance
|
||||||
@@ -44,21 +45,27 @@ try:
|
|||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
KEYSPACE = "testkeyspace"
|
have_twisted = False
|
||||||
|
try:
|
||||||
|
from cassandra.io.twistedreactor import TwistedConnection
|
||||||
|
have_twisted = True
|
||||||
|
supported_reactors.append(TwistedConnection)
|
||||||
|
except ImportError as exc:
|
||||||
|
log.exception("Error importing twisted")
|
||||||
|
pass
|
||||||
|
|
||||||
|
KEYSPACE = "testkeyspace" + str(int(time.time()))
|
||||||
TABLE = "testtable"
|
TABLE = "testtable"
|
||||||
|
|
||||||
|
|
||||||
def setup(hosts):
|
def setup(hosts):
|
||||||
|
log.info("Using 'cassandra' package from %s", cassandra.__path__)
|
||||||
|
|
||||||
cluster = Cluster(hosts)
|
cluster = Cluster(hosts)
|
||||||
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
|
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
|
||||||
|
try:
|
||||||
session = cluster.connect()
|
session = cluster.connect()
|
||||||
|
|
||||||
rows = session.execute("SELECT keyspace_name FROM system.schema_keyspaces")
|
|
||||||
if KEYSPACE in [row[0] for row in rows]:
|
|
||||||
log.debug("dropping existing keyspace...")
|
|
||||||
session.execute("DROP KEYSPACE " + KEYSPACE)
|
|
||||||
|
|
||||||
log.debug("Creating keyspace...")
|
log.debug("Creating keyspace...")
|
||||||
session.execute("""
|
session.execute("""
|
||||||
CREATE KEYSPACE %s
|
CREATE KEYSPACE %s
|
||||||
@@ -77,6 +84,8 @@ def setup(hosts):
|
|||||||
PRIMARY KEY (thekey, col1)
|
PRIMARY KEY (thekey, col1)
|
||||||
)
|
)
|
||||||
""" % TABLE)
|
""" % TABLE)
|
||||||
|
finally:
|
||||||
|
cluster.shutdown()
|
||||||
|
|
||||||
|
|
||||||
def teardown(hosts):
|
def teardown(hosts):
|
||||||
@@ -84,6 +93,7 @@ def teardown(hosts):
|
|||||||
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
|
cluster.set_core_connections_per_host(HostDistance.LOCAL, 1)
|
||||||
session = cluster.connect()
|
session = cluster.connect()
|
||||||
session.execute("DROP KEYSPACE " + KEYSPACE)
|
session.execute("DROP KEYSPACE " + KEYSPACE)
|
||||||
|
cluster.shutdown()
|
||||||
|
|
||||||
|
|
||||||
def benchmark(thread_class):
|
def benchmark(thread_class):
|
||||||
@@ -124,6 +134,7 @@ def benchmark(thread_class):
|
|||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
finally:
|
finally:
|
||||||
|
cluster.shutdown()
|
||||||
teardown(options.hosts)
|
teardown(options.hosts)
|
||||||
|
|
||||||
total = end - start
|
total = end - start
|
||||||
@@ -164,6 +175,8 @@ def parse_options():
|
|||||||
help='only benchmark with asyncore connections')
|
help='only benchmark with asyncore connections')
|
||||||
parser.add_option('--libev-only', action='store_true', dest='libev_only',
|
parser.add_option('--libev-only', action='store_true', dest='libev_only',
|
||||||
help='only benchmark with libev connections')
|
help='only benchmark with libev connections')
|
||||||
|
parser.add_option('--twisted-only', action='store_true', dest='twisted_only',
|
||||||
|
help='only benchmark with Twisted connections')
|
||||||
parser.add_option('-m', '--metrics', action='store_true', dest='enable_metrics',
|
parser.add_option('-m', '--metrics', action='store_true', dest='enable_metrics',
|
||||||
help='enable and print metrics for operations')
|
help='enable and print metrics for operations')
|
||||||
parser.add_option('-l', '--log-level', default='info',
|
parser.add_option('-l', '--log-level', default='info',
|
||||||
@@ -184,6 +197,11 @@ def parse_options():
|
|||||||
log.error("libev is not available")
|
log.error("libev is not available")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
options.supported_reactors = [LibevConnection]
|
options.supported_reactors = [LibevConnection]
|
||||||
|
elif options.twisted_only:
|
||||||
|
if not have_twisted:
|
||||||
|
log.error("Twisted is not available")
|
||||||
|
sys.exit(1)
|
||||||
|
options.supported_reactors = [TwistedConnection]
|
||||||
else:
|
else:
|
||||||
options.supported_reactors = supported_reactors
|
options.supported_reactors = supported_reactors
|
||||||
if not have_libev:
|
if not have_libev:
|
||||||
|
Reference in New Issue
Block a user