
DynamoDB increment load test
By:
jtlebigot on
Jul 24th, 2012 | syntax:
Python | size: 1.17 KB | hits: 35 | expires: Never
import threading
import sys
import time
import boto
worker = 15
units = 5
incr = 100000
itemid = 12
tableName = 'jttest-load-inc'
# Atomic counter :)
s = threading.Semaphore(0)
def createTable():
db = boto.connect_dynamodb()
scheme = db.create_schema('key', int)
table = db.create_table(tableName, scheme, 1000, 1000)
table.refresh(wait_for_active=wait_for_active)
class ThreadClass(threading.Thread):
def __init__ (self, target):
threading.Thread.__init__(self)
self.target = target
def run(self):
#Each thread needs its own // connexion as HTTP in python is not thread safe
db = boto.connect_dynamodb()
table = db.get_table(tableName)
item = table.new_item(self.target)
for i in range(incr/worker):
item.add_attribute('inc', 1)
item.save();
s.release()
def stressTest():
for i in range(worker):
t = ThreadClass(10+i%units)
t.start()
while threading.activeCount() > 1:
sys.stdout.write("Done {:4}/\r".format(s._Semaphore__value, incr))
time.sleep(1)
#createTable()
stressTest()