forked from heroku/php-getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |