Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2014 15:57
Show Gist options
  • Save anonymous/10285909 to your computer and use it in GitHub Desktop.
Save anonymous/10285909 to your computer and use it in GitHub Desktop.
[PATCH] Set SO_REUSEADDR on outgoing TCP connections - tests
#!/usr/bin/env python
import socket
import random
import itertools
import sys
HOSTS=["www.bbc.co.uk", "guardian.co.uk", "dailymail.co.uk", "reddit.com"]
request = '''
GET / HTTP/1.1
User-Agent: curl/7.32.0
Accept: */*
Host: %s
'''
request = "\r\n".join(request.strip().split("\n")) + '\r\n\r\n'
portno = random.randint(50000, 65000)
for m in itertools.count(1):
print "Trying %i concurrent connections" % (m,)
sockets = []
for i in range(m):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', portno+i))
s.connect(("127.0.0.1", 8080))
s.send(request % (HOSTS[i % len(HOSTS)],))
sockets.append( s )
#print "Connection %i ok" % (i,)
for s in sockets:
if "HTTP/1.1 500 " in s.recv(32):
print "error on connection %i (max=%i)" % (i,m)
sys.exit(1)
for s in sockets:
s.close()
#!/usr/bin/env python
import socket
import random
import time
import errno
import itertools
request = '''
GET /test/stream.aspx HTTP/1.1
User-Agent: curl/7.32.0
Accept: */*
Host: www.debugtheweb.com
'''
request = "\r\n".join(request.strip().split("\n")) + '\r\n\r\n'
portno = random.randint(50000, 65000)
sockets = []
for i in itertools.count(1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', portno+i))
s.connect(("127.0.0.1", 8080))
s.send(request)
sockets.append( s )
if "HTTP/1.1 500 " in s.recv(100):
print "error on connection %i " % (i,)
break
print "Connection %i ok" % (i,)
worker_processes 1;
daemon off;
error_log stderr info;
pid /tmp/nginx.pid;
events {
}
http {
server {
listen 8080;
resolver 8.8.8.8;
location / {
proxy_bind 192.168.97.137; # your local IP
proxy_next_upstream off;
proxy_pass $scheme://$host$uri;
proxy_buffering off;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment