Skip to content

Commit

Permalink
Add load testing utility
Browse files Browse the repository at this point in the history
  • Loading branch information
shonfeder committed Nov 11, 2024
1 parent 8764d54 commit b838fbe
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/load-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
32 changes: 32 additions & 0 deletions test/load-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Load Tests

This directory contains a [locust](https://locust.io/) script for load testing
ocaml.org endpoints.

## Running the load tests

1. Start the test framework running with

``` sh
./main.sh
```

2. Navigate to http://0.0.0.0:8089

3. Configure
- the max number of users to simulate
- the number of new users to add to the simulation every second
- the host (`https://staging.ocaml.org`, `https://ocaml.org`, etc.)

## Reviewing the load tests

- Click "Stop" when you are finished running your test.
- Review the various tabs, or click "Download data" for options to download the
test results.
- You can also review prometheus metrics about the staging and prod servers at
https://status.ocaml.ci.dev/d/be358r0z9ai9sf/ocaml-org

## Adding new routines

Tests are defined as "tasks" (sequences of site traversal) in
[./locustfile.py](./locustfile.py).
Binary file not shown.
34 changes: 34 additions & 0 deletions test/load-test/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
#
import random
from locust import HttpUser, task, between

# obtained via https://random-word-api.herokuapp.com/word?number=200
words = ["sacraria","seedcake","philtered","leadiest","cloverleafs","snaffle","lyrisms","ankhs","bedtimes","carrier","restabling","playlets","occupation","overreport","printers","scintigraphic","spa","corsages","enwound","gossipmonger","hydragog","waterlily","avulsions","sonneteerings","spilt","hemocytes","tamandus","rais","minaret","coliseums","ultramicrotome","attribute","phosphite","scincoids","scooting","frightfulnesses","carbamides","sculpture","irresponsive","overtasks","expertise","weet","consociations","tulles","hared","pigginesses","oversimple","theologs","adverb","inamoratas","teeny","rapacities","assonant","metestrus","cyanohydrin","smiting","polychete","merest","tautological","phyllopod","petahertz","plainspokenness","pavior","penitently","omikrons","cigarlike","foetal","diebacks","downlight","kinship","warmish","titleholders","suppositions","resuscitations","tiffing","outsung","homed","alternated","cranks","piaster","allotters","nonirradiated","protohistories","finned","decouple","shahs","foeman","perfidious","soarers","thoroughpins","gastrulating","thrivers","convention","roughened","uncircumcised","clabbering","leadscrew","panfuls","nilgais","evolver","overvoting","furrower","ichthyosaurs","internalizes","borschts","regrouping","lordlier","roguish","microseismicity","besmiling","mattoids","cholerically","fibrosarcomas","farinha","curricles","triradiate","beringed","electrolysis","kashmirs","dirdums","ignorami","otalgic","lusciously","blotty","pizzaz","educe","pendant","disposable","autolyzes","outjutting","interfused","operagoers","fustian","theretofore","dean","unsullied","goitrogenic","ultrasafe","potboil","geochemistries","outdesigned","ephedras","woodlore","illuminatingly","guardrooms","sheldrakes","leachable","theistically","reconception","beachboys","recriminates","almuds","changeabilities","flareups","machinate","verbalizations","dendrologist","unkept","copulatives","restyles","parceled","caecilians","mortgager","thunderstones","labarums","wiliness","hydroplane","already","unlatch","swineherds","alternate","whodunit","hoodiest","sainted","detract","inspiring","fantastically","macaws","adsorbs","thickets","blogs","greenfields","ariettes","camphor","hornpipe","uninventive","boatyard","boomiest","lollingly","congresspersons","painter","radiocarbons","impiously","unfeigned","matchlocks","screwballs","stickies","muddlers","resentful","meats"]

class OcamlOrgUsere(HttpUser):
wait_time = between(1, 5) # range of seconds a user waits between clicks

@task
def landing(self):
self.client.get("/")
self.client.get("/install")
self.client.get("/p/core/latest/doc/index.html")
self.client.get("/docs/tour-of-ocaml")

@task
def top_level_pages(self):
self.client.get("/docs")
self.client.get("/platform")
self.client.get("/packages")
self.client.get("/community")
self.client.get("/changelog")
self.client.get("/play")
self.client.get("/industrial-users")
self.client.get("/academic-users")

@task
def package_searches(self):
query = random.choice(words)
self.client.get(f"/packages/autocomplete?q={query}")
self.client.get(f"/packages/search?q={query}")
5 changes: 5 additions & 0 deletions test/load-test/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

docker run -p 8089:8089 -v "$SCRIPT_DIR":/mnt/locust locustio/locust -f /mnt/locust/locustfile.py

0 comments on commit b838fbe

Please sign in to comment.