in scripts/reader_loadtest.py [0:0]
def thread_func(endpoint, username, password, schema, max_id, iterations):
# Specify that query_count is a global variable
global query_count
global lock
# Loop Indefinitely
while True:
try:
# Resolve the endpoint
host = socket.gethostbyname(endpoint)
# Connect to the reader endpoint
conn = pymysql.connect(host=host, user=username, password=password, database=schema, autocommit=True)
# Run multiple queries per connection
for iter in range(iterations):
# Generate a random number to use as the lookup value
# we will arbitrarily switch between a few query types
key_value = random.randrange(1, max_id)
key_offset = random.randrange(1, 1000)
query_type = random.randrange(0,5)
# queries of multiple types
if query_type == 0:
# Point query
sql_command = "SELECT SQL_NO_CACHE * FROM sbtest1 WHERE id= %d;" % key_value
elif query_type == 1:
# Range query
sql_command = "SELECT SQL_NO_CACHE *, SHA2(c, 512), SQRT(k) FROM sbtest1 WHERE id BETWEEN %d AND %d ORDER BY id DESC LIMIT 10;" % (key_value, key_value + key_offset)
elif query_type == 2:
# Aggregation
sql_command = "SELECT SQL_NO_CACHE k, COUNT(k), SQRT(SUM(k)), SQRT(AVG(k)) FROM sbtest1 WHERE id BETWEEN %d AND %d GROUP BY k ORDER BY k;" % (key_value, key_value + key_offset)
elif query_type == 3:
# Point query with hashing
sql_command = "SELECT SQL_NO_CACHE id, SHA2(c, 512) AS token FROM sbtest1 WHERE id= %d;" % key_value
elif query_type == 4:
# Point query with hashing
sql_command = "CALL minute_rollup(%d);" % (key_offset * 10)
# run query
with conn.cursor() as cursor:
cursor.execute(sql_command)
cursor.close()
# Increment the executed query count
with lock:
query_count += 1
# Close the connection
conn.close()
except:
# Display any exception information
print(sys.exc_info()[1])