Skip to content

IsacEkeroth/examens-arbete

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

examens-arbete

Requirements

  • Bash Version 4+
  • Vegeta
  • jq
  • Python 3.9 (See requirements.txt per framework)

TODO?

  • Websockets
  • FastApi request models / no models
  • Frontend för att visa datan i d3?

ruff

Ruff is used for python linting

ruff . --fix

Run testing

Testing

Basic usage

./benchmark.sh [flags]
./benchmark.sh -t 30s -u http://localhost:7777 -m only -s '["raw_json"]' 

Usage help

./benchmark.sh -h
Usage: benchmark.sh [flags]
    -h                 Show help menu
    -l                 List all available stages
    -m <mode>          Mode: full, skip, only, low_load (full)
    -r <rate>          Requests per second, 0=inf (0)
    -s <stages>        Stages to include/exclude as JSON array, e.g., '["raw_json", "parse_url", "delay"]' (all)
    -t <duration>      Duration in si units (1s, 5m, 10h)
    -u <url>           Base URL of benchmark (http://localhost:5000)
    -w <max_workers>   Maximum number of workers for vegeta (100)

OS

MacOs

Due to MacOs shiping with bash 3.2 and this program relying on newer bash features. ./benchmark.sh points to a newer version of bash installed with brew.
If running on MacOs do

brew install bash

Other

Remove the first line of the code in ./benchmark.sh.
The first line should be the path to your bash installation example: #!/bin/bash

Vegeta report

To view the results of the benchmark use vegeta report, e.g.

vegeta report result.bin
vegeta report -type=json results.bin > metrics.json
vegeta results.bin plot > plot.html
vegeta report -type="hist[0,100ms,200ms,300ms]" results.bin

FastAPI

FastAPI presented with uvicorn under gunicorn

Setup

Create venv

/path/to/python -m venv ./venv

Activate venv

source ./venv/bin/activate

Install requirements

pip install -r ./requirements.txt

FastAPI server

start development server:

uvicorn main:app --reload

start production server:

gunicorn -k uvicorn.workers.UvicornWorker -w 12 -b 0.0.0.0:7777 main:app

Docker

Create image:

docker build -t fastapi .

Start image:

docker run -d -p 7777:7777 --name fastapi fastapi

Flask

Presented with Gunicorn running gevent workers

Setup

Create venv

/path/to/python -m venv ./venv

Activate venv

source ./venv/bin/activate

Install requirements

pip install -r ./requirements.txt

Flask server

Start development server:

flask

Start production server:

gunicorn -w 8 -b 0.0.0.0:7778 app:app

Docker

Create image:

docker build -t flask .

Start image:

docker run -d -p 7778:7778 --name flask flask

Frontend WIP

Setup

Install dependencies

yarn

Start dev server

yarn dev

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 54.6%
  • Shell 20.7%
  • HTML 11.4%
  • Dockerfile 5.0%
  • Python 4.5%
  • CSS 3.8%