... locust: setup


Note that to get started with this series of videos you will need to install some packages.

pip install locust fastapi uvicorn flask

We're going to need two files. One file fastapp.py will contain the webapp that we're going to benchmark and another file benchmark.py will contain a definition of the average user that will use said webapp. This is the contents of fastapp.py:

from fastapi import FastAPI

app = FastAPI()

def root():
    return {"message": "hello world"}

You can run this service locally by running;

uvicorn fastapp:app --reload --workers 1

The --workers flag is set so that we're more sure that we're benchmarking fastapi instead of uvicorn. This is the contents of benchmark.py:

from locust import HttpUser, between, task

class WebsiteUser(HttpUser):
    wait_time = between(2, 4)

    def attempt(self):

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider signing up for the newsletter.