Skip to content

Commit

Permalink
client side scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
omerktz committed Apr 25, 2017
1 parent e087b34 commit 2ee633f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
16 changes: 16 additions & 0 deletions client side/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import requests
import sys
import time
def client(u,p):
timer = time.time
start_ref = timer()
requests.get('https://shielded-wildwood-60311.herokuapp.com/static')
end_ref = timer()
start_query = timer()
requests.get('https://shielded-wildwood-60311.herokuapp.com/dynamic?user='+u+'&pass='+p)
end_query = timer()
return ((end_query-start_query),(end_ref-start_ref))

if __name__ == "__main__":
(query,ref) = client(sys.argv[1],sys.argv[2])
print 'query: '+str(query)+'\nreference: '+str(ref)
26 changes: 26 additions & 0 deletions client side/clients.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from client import client
import sys
import numpy
u = sys.argv[1]
p = sys.argv[2]
num_reps = int(sys.argv[3])
def print_now(s,newline=True):
if newline:
print s
else:
print s,
sys.stdout.flush()
print_now('initializing...\t',False)
client(u,p)
print_now('Done!')
print_now('sampling...')
vals = []
for i in range(num_reps):
print_now('\r\t'+str(i+1)+'/'+str(num_reps),False)
vals.append(client(u,p))
print_now('\nDone!\n')
querys = map(lambda x:x[0],vals)
refs = map(lambda x:x[1],vals)
print 'query: '+str(numpy.mean(querys))+' ('+str(numpy.std(querys))+')'
print 'reference: '+str(numpy.mean(refs))+' ('+str(numpy.std(refs))+')'
print '(averaged over '+str(num_reps)+' repetitions)'
33 changes: 33 additions & 0 deletions client side/crowd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import requests
from multiprocessing import Pool
import random
import signal

import sys
num_processes = int(sys.argv[1])

server = 'https://shielded-wildwood-60311.herokuapp.com/'
def sendRequest():
i = int(random.uniform(0,3))
if i == 0:
requests.get(server+'/static')
else:
r = random.randint(0,499999)+1
if i == 1:
r += 500000
requests.get(server+'dynamic?user=user'+str(r)+'&pass=pass'+str(r))

def sendRequests():
while True:
sendRequest()

def stopRequests(pool):
print 'Killing processes'
sys.stdout.flush()
pool.terminate()
sys.exit(0)

p = Pool(processes=num_processes)
signal.signal(signal.SIGINT, lambda s,f: stopRequests(p))
print "Crowding server at "+server+" using "+str(num_processes)+" processes"
p.apply(sendRequests(),range(num_processes))

0 comments on commit 2ee633f

Please sign in to comment.