Last active
December 30, 2016 21:17
-
-
Save zougloub/fc060612ba3a8492343fd9fc4fe3720c to your computer and use it in GitHub Desktop.
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
# 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 |
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
#!/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, | |
) |
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
#!/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, | |
) |
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
#!/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