Here's the flask app that we're running;
# flaskapp.py
from flask import Flask, jsonify
import time
app = Flask(__name__)
@app.route('/hello/')
def hello_json():
return jsonify({"message": "hello world again"})
@app.route('/sleep/')
def hello_sleep():
time.sleep(0.1)
return jsonify({"message": "slept"})
Here's the command to run the flask app;
export FLASK_APP=flaskapp.py; flask run --port 8000
Here's the user definition for locust;
import random
from locust import HttpUser, between, task, tag
class WebsiteUser(HttpUser):
wait_time = between(1, 1.5)
@task
def attempt(self):
self.client.get("/hello/")
@task
def sleep(self):
self.client.get("/sleep/")
As a final reminder: think hard about what you would like to benchmark. Otherwise you may risk that you're measuring something that is not that useful for your app.