Calmcode - locust: setup

Install and setup Locust in Python.

1 2 3 4 5 6 7 8

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 will contain the webapp that we're going to benchmark and another file will contain a definition of the average user that will use said webapp. This is the contents of

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

from locust import HttpUser, between, task

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

    def attempt(self):