Created
May 13, 2015 04:16
-
-
Save nad2000/55df85e0456768376d98 to your computer and use it in GitHub Desktop.
Simple flask app to stress-test multi-threading using curl and xargs
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
# RUN FORM BASH: | |
# echo http://127.0.0.1:5000/?{1..1000} | xargs -n 1 -P 1000 curl -s | |
from flask import Flask, Response | |
import time | |
request_count = 0 | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
def resp(): | |
global request_count | |
t0 = time.time() | |
yield "Hello there!\n" | |
yield "Previous reqest #{0}\n".format(request_count) | |
time.sleep(10) | |
request_count += 1 | |
yield "Request #{0}\n".format(request_count) | |
yield "Request took {0}\n".format(time.time() - t0) | |
return Response(resp(), mimetype="text/plain") | |
if __name__ == "__main__": | |
app.run(threaded=True, debug=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment