Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wbolster/2854570 to your computer and use it in GitHub Desktop.
Save wbolster/2854570 to your computer and use it in GitHub Desktop.
Python code to test HappyBase library (HBase), and counter and put speeds
#!/usr/bin/env python
import logging
import random
import time
import happybase
logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# Number of test iterations
ITERATIONS = 10000
# Make the HBase connection
connection = happybase.Connection()
# Create the test table, with a column family
connection.create_table('mytable', {'cf': {}})
# Open the table
table = connection.table('mytable')
# Iterate with a counter increment
starttime = time.time()
for i in range(ITERATIONS):
number = str(random.randint(1, 10))
table.counter_inc('row-key', 'cf:counter' + str(number))
totaltime = time.time() - starttime
print "Counter for %d times took %.2f seconds" % (ITERATIONS, totaltime)
# Iterate with a put
starttime = time.time()
with table.batch() as b:
for i in range(ITERATIONS):
number = str(random.randint(1, 10))
b.put('row-key', {'cf:number' + str(number): '10'})
totaltime = time.time() - starttime
print "Put for %d times took %.2f seconds" % (ITERATIONS, totaltime)
# Disable and delete the table
connection.disable_table('mytable')
connection.delete_table('mytable')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment