Created
April 20, 2023 02:36
-
-
Save kmuthukk/13b6928c0e4be87ace3595d926daa7f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import time | |
from cassandra.cluster import Cluster, ExecutionProfile | |
cluster = Cluster(['127.0.0.1']) | |
profile = ExecutionProfile() | |
profile.request_timeout = 60 | |
session = cluster.connect() | |
session.execute('CREATE KEYSPACE IF NOT EXISTS ybdemo;') | |
session.execute('DROP TABLE IF EXISTS ybdemo.ugent;') | |
session.execute("CREATE TABLE IF NOT EXISTS ybdemo.ugent (id int PRIMARY KEY, data jsonb) with transactions = {'enabled': 'true'};") | |
prepared = session.prepare("INSERT INTO ybdemo.ugent(id, data) VALUES (?, ?)") | |
for i in range (0,23): | |
size = 2**i | |
if (size > 4 * 1024 * 1024): | |
size = 4 * 1024 * 1024 | |
data = dict(text='#'*size) | |
data = json.dumps(data, sort_keys=True) | |
num_rows = 10 | |
try: | |
ts = time.time() | |
for j in range(0, num_rows): | |
bound = prepared.bind((i, data)) | |
session.execute(bound) | |
except Exception as e: | |
raise | |
finally: | |
print("Size of JSON=" + str(len(data)), "Insert Time: " + str((time.time() - ts) * 1000 / num_rows) + " ms") | |
prepared_select = session.prepare("SELECT * FROM ybdemo.ugent where id = ?") | |
for i in range (0,23): | |
num_rows = 10 | |
try: | |
ts = time.time() | |
for j in range(0, num_rows): | |
bound = prepared_select.bind((i,)) | |
results = session.execute(bound) | |
except Exception as e: | |
raise | |
finally: | |
row_size = len(results[0].data) | |
print("Size of JSON=" + str(row_size), "Select Time: " + str((time.time() - ts) * 1000 / num_rows) + " ms") | |
cluster.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on RF=1 devserver, on 2.17.0.0 version of YugabyteDB.