Skip to content

Instantly share code, notes, and snippets.

@zougloub
Last active December 30, 2016 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zougloub/fc060612ba3a8492343fd9fc4fe3720c to your computer and use it in GitHub Desktop.
Save zougloub/fc060612ba3a8492343fd9fc4fe3720c to your computer and use it in GitHub Desktop.
# Create a big file (sparse)
truncate --size=100G huge.bin
# check the stuff to make sure it's not a virus
cat *.py *.sh
# Run this in one terminal
./twisted_0_stream_server.py
# Run this in another
./twisted_1_proxy_server.py
# Run this in yet another, repeat as needed to observe the heap growth of the other(s)
./twisted_2_client
# Run htop/top/... to watch the above scripts
#!/usr/bin/env python
# -*- coding: utf-8 vi:noet
# Serves a huge file, to be created by using
# truncate --size=100G huge.bin
import klein
import twisted.web.static
class WebService(object):
app = klein.Klein()
@app.route('/huge.bin', branch=True)
def get_static(self, request):
res = twisted.web.static.File("huge.bin")
return res
if __name__ == '__main__':
ws = WebService()
ws.app.run(
"0.0.0.0", 8001,
)
#!/usr/bin/env python
# -*- coding: utf-8 vi:noet
# Serves a huge file, to be created by using
# truncate --size=100G huge.bin
import klein
import treq
import twisted.web.static
class WebService(object):
app = klein.Klein()
@app.route('/', methods=("GET",))
def get_proxy(self, request):
def stream_response(response, r):
for key, values in response.headers.getAllRawHeaders():
for value in values:
request.setHeader(key, value)
request.setResponseCode(200)
def collector(data, *args, **kw):
if request._disconnected:
print("Warning, client was disconnected, stopping download!")
r.finish()
return
return request.write(data)
d = treq.collect(response, collector)
d.addCallback(lambda _: request.finish())
return d
url = "http://localhost:8001/huge.bin"
req_upstream = treq.request(request.method, url)
req_upstream.addCallback(stream_response, req_upstream)
return req_upstream
if __name__ == '__main__':
ws = WebService()
ws.app.run(
"0.0.0.0", 8002,
)
#!/bin/sh
for x in $(seq 1 1 100); do
( curl --silent http://localhost:8002/ | head --bytes=1048576 > /dev/null & );
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment