-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtester.py
More file actions
396 lines (367 loc) · 12.4 KB
/
Copy pathtester.py
File metadata and controls
396 lines (367 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# Author Navraj Chohan
# This program is the client side tester to dbtranstest
import sys
import time
import math
import test_functions
import getopt
import threading
tf = test_functions
DEFAULT_IP = ["128.111.55.223"]
DEFAULT_PORT = [8080]
DEFAULT_RATE = 1 # per second
DEFAULT_BATCH_SIZE = 1
DEFAULT_TRIAL_LENGTH = 1
ID_KEY_LENGTH = 15
DEFAULT_TRIALS = 1
DEFAULT_TESTS = ["batchput"]
VALID_TESTS = ["put","get","delete","query","increment","allowance","query","batchput","batchget","batchdelete","batchincrement","batchallowance"]
SINGLE_TESTS = VALID_TESTS[0:6]
BATCH_TESTS = VALID_TESTS[7:]
DEBUG = False
PUTCOUNTVALUE = "1"
INCREMENTVALUE = "1"
VALID_QUERY_KIND = ["Accumulator", "Parent", "Child"]
DEFAULT_QUERY_KIND = VALID_QUERY_KIND[0]
DEFAULT_OFFSET = 1
def padString(string):
zero_padded_id = ("0" * (ID_KEY_LENGTH - len(string))) + string
return zero_padded_id
def generateKeys(numOfKeys, offset = 1):
keys = []
for ii in range(offset, offset + numOfKeys + 1):
keys.append(padString(str(ii)))
return keys
def getBatchKeyString(keys):
return ':'.join(keys)
def getIPsAndPorts(file):
FILE = open(file, "r")
contents = FILE.readlines()
ips = []
ports = []
for line in contents:
if line[0] == '#':
continue
tokens = line.split(':')
ip = tokens[0]
port = tokens[1].rstrip()
ips.append(ip)
ports.append(port)
return ips,ports
""" Latency test:
Do X puts for a counter, time it
Do X gets for those same counters, time it
Do Y number of repeat queries, time each
Do X increments on those same counters, time it
Do X gets on each counter to verify
Do X delets on all counters, time it
"""
def usage():
print "Usage:"
print "-r or --request for number of request per second"
print "-l or --lenth for number of seconds per trial"
print "-b or --batch_size for size of a batch request"
print "-t or --trials for the number of trials"
print "-y or --tests for which test to run"
print "\tFormat is test1:test2:test3:....testN"
print "\tValid test include:",VALID_TESTS
print "-s or --slave_file for location of slave file"
print "\tFormat of file should be a ip:port for each line"
print "-o or --output to specify the output file"
print "-k for query kind"
print "\t valid types are Accumulator, Child, and Parent"
print "-d for debug"
print "-f or --offset for key offset number"
print "\t useful for having multiple clients during testing"
print "Examples:"
print "TODO"
def main(argv):
debug = DEBUG
ips = DEFAULT_IP
ports = DEFAULT_PORT
req_per_sec = DEFAULT_RATE
batch_size = DEFAULT_BATCH_SIZE
num_trials = DEFAULT_TRIALS
trial_length = DEFAULT_TRIAL_LENGTH
tests = DEFAULT_TESTS
query_kind = DEFAULT_QUERY_KIND
offset = DEFAULT_OFFSET
output_file = ""
try:
opts, args = getopt.getopt(argv, "k:r:s:b:t:l:y:o:f:ud",
["kind=",
"request=",
"slave_file=",
"batch_size=",
"trials=",
"length=",
"tests=",
"output=",
"offset=",
"usage",
"debug"])
except getopt.GetoptError:
usage()
sys.exit(1)
for opt, arg in opts:
if opt in ("-r", "--request"):
req_per_sec = int(arg)
if debug: print "Number of request per second:",arg
if opt in ("-s", "--slave_file"):
ips, ports = getIPsAndPorts(arg)
if debug: print "IPs:",str(ips)
if debug: print "Ports:",str(ports)
if opt in ("-b", "--batch_size"):
batch_size = int(arg)
if debug: print "Batch size:",batch_size
if opt in ("-t", "--trials"):
num_trials = int(arg)
if debug: print "Number of trials",num_trials
if opt in ("-k", "--kind"):
query_kind = arg
if debug: print "Kind of query:",query_kind,"seconds"
if query_kind not in VALID_QUERY_KIND:
print "%s is not a valid kind of query type"%query_kind
exit(1)
if opt in ("-l", "--length"):
trial_length = int(arg)
if debug: print "Length of test:",trial_length,"seconds"
if opt in ("-y", "--tests"):
tests = arg
tests = tests.split(":")
error = False
for ii in tests:
if ii not in VALID_TESTS:
error = True
print "Test \"" + ii + "\" is not a valid test"
if error:
usage()
exit(1)
if debug: print "Running tests:",tests
if opt in ("-o", "--output"):
output_file = arg
if debug: print "Output file:",output_file
if opt in ("-u", "--usage"):
usage()
exit(0)
if opt in ("-d", "--debug"):
debug = True
if debug: print "Debug mode is on"
if opt in ("-f", "--offset"):
offset = int(arg)
if debug: print "Offset is:",offset
error = False
# Primes the database if needed (Hbase in particular)
if debug: print "Accessing web page",ips[0],":",ports[0]
ret = tf.Root(ips[0], ports[0])
if ret != "Hello From DB Trans Tester":
error = True
print "Error accessing web page",ips[ii],":",ports[ii]
# Check to see that all slaves are running
for ii in range(0, len(ips)):
if debug: print "Accessing web page",ips[ii],":",ports[ii]
ret = tf.MainIndex(ips[ii], ports[ii])
if ret != "Hello From DB Trans Tester":
error = True
print "Error accessing web page",ips[ii],":",ports[ii]
if error:
print "exiting due to errors..."
exit(1)
results = {}
for ii in tests:
total_data = []
if ii in SINGLE_TESTS or ii in BATCH_TESTS:
if debug: print "Running Single Test"
for kk in range(0, num_trials):
output = single_test(ips,
ports,
req_per_sec,
trial_length,
batch_size,
ii,
query_kind,
offset,
debug)
total_data.append(output)
if debug: print "Method:",ii,",Output:\n",output
results[ii] = total_data
logit(output_file, results)
stats(results)
def logit(output_file, results):
if output_file:
for r in results:
ofile = open(output_file + "_" + r, "w")
for ii in results[r]:
ofile.write(ii)
#file.write('\n#\n')
ofile.close()
def getTotal(points):
total = 0
for ii in points:
total += float(ii)
return total
def getAverage(points, total = None):
if total == None:
total = getTotal(points)
if len(points) == 0:
return 0
return total/len(points)
def getStDev(points, average=None):
total = 0;
if average == None:
average = getAverage(points)
for ii in points:
total += (float(ii) - average) * (float(ii) - average)
if len(points) == 0:
return 0
return math.sqrt(total/len(points))
def stats(results):
for key in results:
total = 0
avg = 0
min = 9999
max = 0
stdev = 0
numFailed = 0
timings = []
print "Key:",key
for ii in results[key]:
lines = ii.split('\n')
isSuccess = False
for line in lines:
if line.startswith("<html>"):
# Timeout error in appscale
isSuccess = False
numFailed += 1
if line.startswith("Success:"):
if line.endswith("True"):
isSuccess = True
else:
isSuccess = False
numFailed += 1
if line.startswith("Timings:") and isSuccess:
tokens = line.split(':')
times = tokens[1]
times = times.split(',')
for index, tt in enumerate(times):
tt.rstrip('\n')
times[index] = float(tt)
timings += times
for ii in timings:
if ii < min:
min = ii
if ii > max:
max = ii
total = getTotal(timings)
avg = getAverage(timings, total)
stdev = getStDev(timings, avg)
print "Average:",avg
print "Total:",total
print "Total Number:",len(timings)
print "Stdev:",stdev
print "Min:",min
print "Max:",max
print "Number of failures:",numFailed
print "="*80
class testThread(threading.Thread):
def setup(self, keyset1, keyset2, ip, port, command, batch_size, query_kind, debug=False):
self.ip_ = ip
self.port_ = port
self.command_ = command
self.keyset1_ = keyset1
self.keyset2_ = keyset2
self.batch_size_ = batch_size
self.query_kind_ = query_kind
self.debug_ = debug
self.status_ = "init"
self.output_ = ""
self.start_ = time.time()
self.end_ = 0
if self.debug_: print "ip: %s, port: %s, command: %s"\
%(self.ip_,self.port_,self.command_)
def run(self):
self.status_ = "running"
if self.debug_: print "Thread %s run function: %s"\
%(str(self),(self.command_ + "_test"))
function = getattr(self, self.command_ + "_test")
self.output_ = function()
if self.debug_: print "Thread %s done"%(str(self))
self.status_ = "terminated"
self.end_ = time.time()
def put_test(self):
result = tf.PutCount(self.ip_, self.port_, self.keyset1_[0], PUTCOUNTVALUE)
return result
def get_test(self):
result = tf.GetCount(self.ip_, self.port_, self.keyset1_[0])
return result
def delete_test(self):
result = tf.DeleteCount(self.ip_, self.port_, self.keyset1_[0])
return result
def increment_test(self):
result = tf.Increment(self.ip_, self.port_, self.keyset1_[0], INCREMENTVALUE)
return result
def allowance_test(self):
tf.CreateParentChild(self.ip_, self.port_, self.keyset1_[0], self.keyset2_[0])
result = tf.GiveAllowance(self.ip_, self.port_, self.keyset1_[0], self.keyset2_[0], PUTCOUNTVALUE)
return result
def query_test(self):
return tf.Query(self.ip_, self.port_, self.query_kind_)
def batchput_test(self):
result = tf.BatchPutCount(self.ip_, self.port_, self.keyset1_, PUTCOUNTVALUE)
return result
def batchget_test(self):
result = tf.BatchGetCount(self.ip_, self.port_, self.keyset1_)
return result
def batchdelete_test(self):
result = tf.BatchDeleteCount(self.ip_, self.port_, self.keyset1_)
return result
def batchincrement_test(self):
result = tf.BatchIncrement(self.ip_, self.port_, self.keyset1_, PUTCOUNTVALUE)
return result
def batchallowance_test(self):
tf.CreateParentChild(self.ip_, self.port_, self.keyset1_[0], self.keyset2_[0])
result = tf.BatchGiveAllowance(self.ip_, self.port_, self.keyset1_[0], self.keyset2_[0], PUTCOUNTVALUE, self.batch_size_)
return result
# returns results of a single trial
def single_test(ips, ports, rps, trial_length, batch_size, method, query_kind, offset, debug = DEBUG):
#log = logger()
log = ""
total_request = rps * trial_length * batch_size * len(ips)
keys1 = generateKeys(total_request, offset)
keys2 = generateKeys(total_request, 1 + len(keys1))
if debug: print "Total keyspace 1:",keys1
if debug: print "Total keyspace 2:",keys2
if debug: print "ips %s, ports %s, rps %s, trial_length %s, debug %s" %(ips, ports, rps, trial_length, debug)
if debug: print "Sending a total of %d request"%total_request
key_index = 0
threadlist = []
for length in range(0, trial_length):
for ii in range(0,rps):
# send as threaded request
for index, ip in enumerate(ips):
if debug: print "Sending to ",ip,"on port",ports[index]
thread = testThread()
threadlist.append(thread)
keysub1 = keys1[key_index:key_index + batch_size]
keysub2 = keys2[key_index:key_index + batch_size]
if debug: print "key space 1:",keysub1
if debug: print "key space 2:",keysub2
thread.setup(keysub1, keysub2, ip, ports[index], method, batch_size, query_kind, debug)
thread.start()
key_index += batch_size
time.sleep(1)
for thread in threadlist:
thread.join()
if debug: print "Joining thread %s"%str(thread)
if thread.status_ == "terminated":
log += "Method:"+thread.command_ + "\n"
log += "RTT Start:"+ str(thread.start_) + "\n"
log += "RTT End:"+str(thread.end_)+ "\n"
log += "RTT Time:"+str(thread.end_ - thread.start_)+ "\n"
log += thread.output_
log += "#\n"
else:
print "Error with thread after join with status %s"%thread.status_
return log
if __name__ == '__main__':
main(sys.argv[1:])