Last active
November 22, 2023 23:56
-
-
Save feliperyan/621c348144acaadd863882ab245206e7 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
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) |
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/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" |
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
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