Skip to content

Commit

Permalink
Added new tokens (@t for time and @m for process-unique marker)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankur Goyal committed Jul 25, 2012
1 parent 5effd30 commit bbc6dd9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
3 changes: 2 additions & 1 deletion runner
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import stress.server
#!/usr/bin/env python

import stress.server
stress.server.main()
52 changes: 43 additions & 9 deletions stress/query_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bisect import bisect_right
import datetime
import logging
import os
import random
Expand All @@ -9,23 +10,43 @@
STRING_TOKEN = "^"
NUMBER_TOKEN = "@"

# Can use anything after G for arbitrary tokens
TIME_TOKEN = "@T"
MARK_TOKEN = "@M"

# These are ordered very specifically so that
# if i < j, SPLIT_TOKENS[i] is not a prefix of
# SPLIT_TOKENS[j]
ALL_PARAM_TOKENS = ["@M", "@T", "@", "^"]

# Final Types
OLD_STRING = 0
NEW_STRING = 1
OLD_NUMBER = 2
NEW_NUMBER = 3

def split_and_fold(string_list, c):
def split_and_fold(s, c):
build = []
for i, s in enumerate(string_list):
spl = s.split(c)
for j, piece in enumerate(spl):
if j > 0:
build.append(c)
build.append(piece)
spl = s.split(c)
for i, piece in enumerate(spl):
if i > 0:
build.append(c)
build.append(piece)

return build

def tokenize_query(query):
string_list = [query]
for i, c in enumerate(ALL_PARAM_TOKENS):
build = []
for j, s in enumerate(string_list):
if s in ALL_PARAM_TOKENS[:i]:
build.append(s)
else:
build.extend(split_and_fold(s, c))
string_list = build
return string_list

# Very simple heuristics. Uses old numbers with select queries
def parse_query(qlist):
qtype = qlist[0].lstrip().split()[0].lower()
Expand Down Expand Up @@ -73,9 +94,18 @@ def get_random_string(prefix, n):
s = prefix + "|" + str(ret)
return s[:n]

def get_global_marker(prefix):
return prefix

global_time = datetime.datetime.now()
def get_random_time():
global global_time
current_time = int("%.4d%.2d%.2d%.2d%.2d%.2d" % global_time.timetuple()[:6])
global_time += datetime.timedelta(seconds = 1)
return str(current_time)

def generate_query_function(query):
qlist = split_and_fold([query], STRING_TOKEN)
qlist = split_and_fold(qlist, NUMBER_TOKEN)
qlist = tokenize_query(query)
qlist = parse_query(qlist)
build = []
for q in qlist:
Expand All @@ -87,6 +117,10 @@ def generate_query_function(query):
build.append("get_old_random_number(prefix)")
elif q == NEW_NUMBER:
build.append("get_new_random_number(prefix)")
elif q == TIME_TOKEN:
build.append("get_random_time()")
elif q == MARK_TOKEN:
build.append("get_global_marker(prefix)")
else:
build.append(repr(q))
ret = ','.join(build)
Expand Down
3 changes: 2 additions & 1 deletion stress/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import time
import traceback
import uuid

from query_table import QueryTable

Expand Down Expand Up @@ -40,7 +41,7 @@
def worker(index, info_pipe, qps_array, qps_query_table, nworkers, client_arguments):
try:
global worker_on
prefix = str(os.getpid())
prefix = str(uuid.uuid4().int & (2**16-1))

# create connection and run sanity check (show tables)
conn = _mysql.connect(**client_arguments)
Expand Down

0 comments on commit bbc6dd9

Please sign in to comment.