Calmcode - fastapi: async one

Can we measure the async performance in FastAPI?

1 2 3 4 5 6 7 8 9

Async Code

This is the code that we've added to in this part;

import time
import asyncio

def sleep_slow():
    return {"status": "done"}

async def sleep_fast():
    await asyncio.sleep(1)
    return {"status": "done"}

If you get an error while running this it might be a python version issue. Make sure that you're using a recent version of python (3.6 and up).


To use boom make sure it is installed first via:

brew install boom

Once that's dealt with, you can run the following commands;

boom -c 200 -n 200
boom -c 200 -n 200

In both commands boom with send a total of (defined via -n) 200 requests and will do it with a concurrency of 200 (defined via -c). Concurrency is just a fancy word of saying "at the same time". If you'd like boom to send 100 requests in batches of 20 at a time you'd use this command;

boom -c 20 -n 100