Skip to content

Instantly share code, notes, and snippets.

@yimaihortonworks
Last active January 26, 2016 06:59
Show Gist options
  • Select an option

  • Save yimaihortonworks/3b41495b6a8b4226e818 to your computer and use it in GitHub Desktop.

Select an option

Save yimaihortonworks/3b41495b6a8b4226e818 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pyhs2
import sys
import threading
import time
user_name = sys.argv[1]
pw = sys.argv[2]
hs2 = sys.argv[3]
concurrency = int(sys.argv[4])
attempts = int(sys.argv[5])
def worker(thread_id):
print 'started'
with pyhs2.connect(
host=hs2,
port=10000,
authMechanism="PLAIN",
user=user_name,
password=pw,
database='default'
) as conn:
with conn.cursor() as cur:
for i in range(attempts):
cur.execute("select count(1) from sample_07")
print "attempt: %d-%d" % (thread_id,i)
time.sleep(1)
return
threads = []
for i in range(concurrency):
t = threading.Thread(target=worker,args=[i])
threads.append(t)
t.start()
for t in threads:
t.join()
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment