Skip to content

Instantly share code, notes, and snippets.

View kmuthukk's full-sized avatar

Kannan Muthukkaruppan kmuthukk

View GitHub Profile
@kmuthukk
kmuthukk / ysql_parallel_inserts.py
Last active April 18, 2019 03:11
sample python program to do single row inserts in parallel for YugaByte DB's YSQL (postgres compatible API)
import psycopg2;
import time
from multiprocessing.dummy import Pool as ThreadPool
num_threads=8
num_users=1000
num_msgs=50
table_name = "user_actions"
def create_table():
@kmuthukk
kmuthukk / ysql_parallel_writer_and_reader.py
Last active April 18, 2019 04:00
Sample python program that does parallel inserts into a user_actions table, then does both point reads and range reads against YugaByte DB's YSQL (postgres compatible API)
import psycopg2;
import time
import random
from multiprocessing.dummy import Pool as ThreadPool
# Load Phase params
num_write_threads=4
num_users=500
num_msgs=50
table_name = "user_actions"
@kmuthukk
kmuthukk / ysql_serializable_isolation_demo.py
Last active April 29, 2019 01:25
Demo of Serializable Isolation in YugaByte DB: Concurrent Transactions That Flip Color of Items
import psycopg2
from threading import Thread,Semaphore
from multiprocessing.dummy import Pool as ThreadPool
#
# The test uses the classic example of a set of black and white items to
# illustrate the need, in some situations, for transaction support with
# serializable isolation level.
#
# In this test two concurrent transactions- one that flips white colored
@kmuthukk
kmuthukk / ysql_join_example.py
Last active May 16, 2019 01:53
a parallel program to test simple join performance with YugaByte postgres-compatible YSQL API
# Dependencies:
# On CentOS you can install psycopg2 thus:
#
# sudo yum install postgresql-libs
# sudo yum install python-psycopg2
#
import psycopg2
import time
import random
@kmuthukk
kmuthukk / ysql_load_to_table_with_index.py
Last active May 25, 2019 00:20
Sample python program to load to a table with a secondary index using YugaByte DB's postgres compatible SQL API
import psycopg2;
from multiprocessing.dummy import Pool as ThreadPool
num_write_threads=2
num_users=10000
def create_table():
conn = psycopg2.connect("host=localhost dbname=postgres user=postgres port=5433")
conn.set_session(autocommit=True)
cur = conn.cursor()
@kmuthukk
kmuthukk / sql_user_actions_without_prepare.py
Last active August 11, 2019 03:43
Simple INSERTs into a user_actions table (without use of prepare step)
# On CentOS you can install psycopg2 thus:
#
# sudo yum install postgresql-libs
# sudo yum install python-psycopg2
import psycopg2;
import time
conn = psycopg2.connect("host=localhost dbname=postgres user=postgres port=5433")
@kmuthukk
kmuthukk / sql_user_actions_prep_stmt.py
Last active August 11, 2019 03:42
Simple INSERTs into a user_actions table (with use of prepare)
# On CentOS you can install psycopg2 thus:
#
# sudo yum install postgresql-libs
# sudo yum install python-psycopg2
import psycopg2;
import time
conn = psycopg2.connect("host=localhost dbname=postgres user=postgres port=5433")
# pip install yb-cassandra-driver
from cassandra.cluster import Cluster
import time
import random
from multiprocessing.dummy import Pool as ThreadPool
# Load Phase params
num_write_threads=4
num_users=500
package main
import (
"fmt"
"log"
"time"
"github.com/gocql/gocql"
)
@kmuthukk
kmuthukk / ycql_null_insert.py
Created October 26, 2019 05:52
Issue With Invalid/NULL Range Column
# pip install yb-cassandra-driver
from cassandra.cluster import Cluster
from cassandra.query import UNSET_VALUE
import time
import random
import os
from multiprocessing.dummy import Pool as ThreadPool