Last active
December 16, 2015 12:19
-
-
Save dcarley/5433423 to your computer and use it in GitHub Desktop.
Test the effect of Unicorn's `check_client_connection` option on a queue of disconnected requests. For use with: https://github.com/nickstenning/timeouttest
This file contains hidden or 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
""" | |
Test the effect of Unicorn's `check_client_connection` option on a queue of | |
disconnected requests. For use with: | |
https://github.com/nickstenning/timeouttest | |
""" | |
import sys | |
import time | |
import requests | |
URL=sys.argv[1] | |
VHOST=sys.argv[2] | |
WAIT=10 | |
WORKERS=2 | |
MULTIPLIER=4 | |
TIMEOUT=0.01 | |
class Timer(object): | |
def __init__(self, title): | |
self.title = title | |
self.start = None | |
self.end = None | |
def __enter__(self): | |
self.start = time.time() | |
def __exit__(self, exc_type, exc_value, traceback): | |
self.end = time.time() | |
print("%s, took: %s" % (self.title, self.end - self.start)) | |
def block_workers(workers): | |
for i in range(0, workers): | |
try: | |
requests.get("%s/wait/%s" % (URL, WAIT), timeout=TIMEOUT, **req_args) | |
except requests.exceptions.SSLError: | |
pass | |
req_args = { | |
'verify': False, | |
'headers': {'host': VHOST}, | |
} | |
with Timer("Setting up disconnected clients"): | |
block_workers(WORKERS * MULTIPLIER) | |
with Timer("Blocked legit request"): | |
res = requests.get(URL, **req_args) | |
print("%s, %s" % ( | |
res.status_code, | |
res.text | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment