9
TOTAL_NUM_ACCOUNTS = 100000
11
MASTER_BINDPORT = 9999
12
MY_IP = commands.getoutput("ifconfig").split("\n")[1].split()[1][5:]
13
#REQUEST_AMMOUNT_SET = [10,100,1000,10000]
14
REQUEST_AMMOUNT_SET = [10,100,1000,10000]
16
# IP and port for each slave
21
soapserver = SOAPpy.SOAPServer((MY_IP, MASTER_BINDPORT))
29
print "--target or -t for targer web server (ip:port)"
30
print "--slaves or -s for slaves which are clients (ip:port)"
31
print "--prime or -p for prime (with --target flag)"
32
print "--xdelete or -x for deleting all accounts (with --target flag)"
35
class SoapThread(threading.Thread):
38
soapserver.registerFunction(query_results)
42
soapserver.serve_forever()
44
class RequestThread(threading.Thread):
45
def setup(self, serv, totalrequest):
47
self.nreq = totalrequest
52
self.success, self.nreq = self.server.run()
56
print "thread output: ",self.success, self.nreq
59
def readFile(slavefile):
60
FILE = open(slavefile, "r")
61
contents = FILE.readlines()
66
tokens = line.split(':')
68
port = tokens[1].rstrip()
69
host.append((ip,port))
72
def runSlaves(slaves, targets, numreq):
75
global MASTER_BINDPORT
77
# Load balance the number of request
78
# Thread for each slave
81
req_left = int(numreq)
83
# Each slave can only handle up to 350 requests
88
# Soap connection to slave
89
server = SOAPpy.SOAPProxy("http://" + ii[0] + ":" + str(ii[1]))
91
server.setup(targets, requests, seed_counter)
96
rt.setup(server, numreq)
103
if DEBUG: print "Starting slave..."
110
total += int(ii.nreq)
111
success += int(ii.success)
112
if DEBUG: print "success and total:",success,total
113
return [success, total]
117
global REQUEST_AMMOUNT_SET
120
print "# concurrent request, avg successes, all samples, "
121
for ii in REQUEST_AMMOUNT_SET:
124
dataset = RESULTS[ii]
130
warnings += "Trial with " + str(kk) + " has an incorrect number of reported items.\n "
131
print str(ii)+","+str(success/TRIALS)+","+str(total)
132
if total != ii * TRIALS:
133
warnings += str(ii) + " had " + str(total) + " request reported"
134
warnings += ". It should have been " + str(ii * TRIALS)
145
global REQUEST_AMMOUNT_SET
154
opts, args = getopt.getopt(argv, "t:s:pdx",
160
except getopt.GetoptError:
164
for opt, arg in opts:
165
if opt in ("-p", "--prime"):
167
if opt in ("--xdelete","-x"):
169
if opt in ("-t", "--targets"):
170
target_file = str(arg)
171
if opt in ("-s", "--slaves"):
172
slave_file = str(arg)
174
print "Debugging turned on"
177
if target_file == "":
181
targets = readFile(target_file)
184
print "No targets given"
188
# Use the first ip and port to prime the DB
189
firsttarget = targets[0]
191
port = firsttarget[1]
192
for ii in range(0, TOTAL_NUM_ACCOUNTS/1000):
193
# ii is the offset, batches of 1k each
194
ret = tf.BatchCreateAccount(ip, port, 1000,ii * 1000,1000)
196
print "Done creating accounts."
197
ret = tf.Root(ip, port)
198
print "Priming tables"
204
firsttarget = targets[0]
206
port = firsttarget[1]
207
for ii in range(0, TOTAL_NUM_ACCOUNTS/100):
208
# ii is the offset, batches of 1k each
209
ret = tf.BatchDeleteAccount(ip, port, 100,ii * 100, 1000)
211
print "Done deleting accounts."
219
slaves = readFile(slave_file)
221
print "No slaves given"
225
# Start a thread for accumulating responses
226
#soap_thread = SoapThread()
229
global REQUEST_AMMOUNT_SET
233
shortest_time = 999999
234
if DEBUG: print "Slave:",slaves
235
for index,ii in enumerate(REQUEST_AMMOUNT_SET):
236
if DEBUG: print "Requesting",ii,"concurent threads"
238
for kk in range(0,TRIALS):
239
# runslaves command works in parallel with synchronous request
241
print "Running trial ",kk
243
result = runSlaves(slaves, targets, str(ii))
245
print "result of trial:",result
248
total_time += end - start
249
if (end - start) > highest_time:
250
highest_time = end - start
251
if (end - start) < shortest_time:
252
shortest_time = end - start
256
print "Average time taken:",(total_time/num_runs)
257
print "Longest time for a run:",highest_time
258
print "Shortest time for a run:",shortest_time
261
if __name__ == "__main__":