Skip to content

Instantly share code, notes, and snippets.

@nad2000
Created May 13, 2015 04:16
Show Gist options
  • Save nad2000/55df85e0456768376d98 to your computer and use it in GitHub Desktop.
Save nad2000/55df85e0456768376d98 to your computer and use it in GitHub Desktop.
Simple flask app to stress-test multi-threading using curl and xargs
# 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