Skip to content

Instantly share code, notes, and snippets.

@feliperyan
Last active November 22, 2023 23:56
Show Gist options
  • Save feliperyan/621c348144acaadd863882ab245206e7 to your computer and use it in GitHub Desktop.
Save feliperyan/621c348144acaadd863882ab245206e7 to your computer and use it in GitHub Desktop.
import asyncio
from quart import Quart, request
app = Quart(__name__)
@app.route('/', methods=['GET'])
async def sleep():
await asyncio.sleep(4)
print("received request")
return 'Slept for 400ms'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
#!/bin/bash
echo "At 4 secs each, 5 concurrent reqs should take 20 secs in sync and 4 secs in async"
start_time=$(date +%s)
for i in {1..5}; do
curl http://0.0.0.0:8000 > /dev/null 2>&1 &
done
wait
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo "Total time: ${elapsed_time} seconds"
from flask import Flask, request
import time
app = Flask(__name__)
@app.route('/', methods=['GET'])
def sleep():
time.sleep(4)
return 'Slept for 4000ms'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment