Created
May 30, 2012 22:49
-
-
Save srs81/2839409 to your computer and use it in GitHub Desktop.
Python code to test HappyBase library (HBase), and counter and put speeds
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 happybase | |
import time, random | |
# 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.clock() | |
for i in range(ITERATIONS): | |
number = str(random.randint(1, 10)) | |
table.counter_inc('row-key', 'cf:counter' + str(number)) | |
totaltime = time.clock() - starttime | |
print "Counter for " + str(ITERATIONS) + " times took: " + str(totaltime) + " seconds" | |
# Iterate with a put | |
starttime = time.clock() | |
for i in range(ITERATIONS): | |
number = str(random.randint(1, 10)) | |
table.put('row-key', {'cf:number' + str(number): '10'}) | |
totaltime = time.clock() - starttime | |
print "Put for " + str(ITERATIONS) + " times took: " + str(totaltime) + " seconds" | |
# 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