Skip to content

Instantly share code, notes, and snippets.

@s3rius
Last active September 24, 2023 15:27
Show Gist options
  • Save s3rius/9453e36709c3f94814d813f1a100de0a to your computer and use it in GitHub Desktop.
Save s3rius/9453e36709c3f94814d813f1a100de0a to your computer and use it in GitHub Desktop.
ScyllaPy benchmarks

To run the benchmark install:

pip install scyllapy acsylla uvloop

And then run it with scylla ip address as the first positional argument. For example:

python benches.py "172.29.0.2" --uvloop

Observed results:

Installing uvloop
===== Using optimized driver!!! =====
############# 8000 inserts #############
ScyllaPy 0.17901256500044838
ACSYLLA  0.23505392798688263
############# 3000 selects #############
ScyllaPy 1.0957447310211137
ACSYLLA  3.5637781459954567
import argparse
import asyncio
import time
from acsylla import create_cluster, create_statement, Session
import scyllapy
async def build_insert_statement(session: Session, i: int):
statement = create_statement(
"INSERT INTO test (id, val) VALUES (?, ?)", parameters=2
)
statement.bind_list([i, i])
await session.execute(statement)
async def acsylla_run_selects(session: Session, num: int):
await asyncio.gather(
*[session.execute(create_statement("SELECT * FROM test;")) for _ in range(num)]
)
async def acsylla_run_inserts(session: Session, num: int):
await asyncio.gather(*[build_insert_statement(session, i) for i in range(num)])
async def scyllapy_run_selects(scylla: scyllapy.Scylla, num: int):
await asyncio.gather(*[scylla.execute("SELECT * FROM test;") for _ in range(num)])
async def scyllapy_run_inserts(scylla: scyllapy.Scylla, num: int):
await asyncio.gather(
*[
scylla.execute("INSERT INTO test(id, val) VALUES (?, ?)", (i, i))
for i in range(num)
]
)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("--uvloop", help="Use uvloop", action="store_true")
parser.add_argument("scylla_urls", help="Scylla Host IPs", nargs="+")
parser.add_argument(
"--num-inserts",
help="Number of inserts",
type=int,
default=1000,
)
parser.add_argument(
"--num-elements",
help="Number of elements",
type=int,
default=100,
)
parser.add_argument(
"--num-selects",
help="Number of selects",
type=int,
default=5000,
)
return parser.parse_args()
async def main(args: argparse.Namespace) -> None:
cluster = create_cluster(
args.scylla_urls,
retry_policy="fallthrough",
username="cassandra",
password="cassandra",
)
scyllapy_session = scyllapy.Scylla(
args.scylla_urls,
username="cassandra",
password="cassandra",
)
await scyllapy_session.startup()
await scyllapy_session.execute(
"CREATE KEYSPACE IF NOT EXISTS benchmarks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"
)
await scyllapy_session.use_keyspace("benchmarks")
acsylla_session = await cluster.create_session("benchmarks")
await scyllapy_session.execute(
"CREATE TABLE IF NOT EXISTS test (id INT PRIMARY KEY, val INT)"
)
print(f" {args.num_inserts} inserts ".center(40, "#"))
await scyllapy_session.execute("TRUNCATE test")
start = time.monotonic()
await scyllapy_run_inserts(scyllapy_session, args.num_inserts)
print("ScyllaPy", time.monotonic() - start)
await scyllapy_session.execute("TRUNCATE test")
start = time.monotonic()
await acsylla_run_inserts(acsylla_session, args.num_inserts)
print("ACSYLLA ", time.monotonic() - start)
print(f" {args.num_selects} selects ".center(40, "#"))
await scyllapy_session.execute("TRUNCATE test")
await scyllapy_run_inserts(scyllapy_session, args.num_elements)
start = time.monotonic()
await scyllapy_run_selects(scyllapy_session, args.num_selects)
print("ScyllaPy", time.monotonic() - start)
await scyllapy_session.execute("TRUNCATE test")
await acsylla_run_inserts(acsylla_session, args.num_elements)
start = time.monotonic()
await acsylla_run_selects(acsylla_session, args.num_selects)
print("ACSYLLA ", time.monotonic() - start)
if __name__ == "__main__":
args = parse_args()
if args.uvloop:
print("Installing uvloop")
import uvloop
uvloop.install()
asyncio.run(main(args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment