Skip to content

Commit

Permalink
Merge pull request #20 from input-output-hk/edd/add-loadtests
Browse files Browse the repository at this point in the history
Load tests
  • Loading branch information
rvl authored Apr 21, 2021
2 parents 24e8536 + 07836c6 commit 80e5bfa
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/load/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RUN_TIME=1m
USERS=10
SPAWN_RATE=1
1 change: 1 addition & 0 deletions test/load/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
4 changes: 4 additions & 0 deletions test/load/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export SWARM_SIZE?=1

run:
docker-compose up --scale worker=$(SWARM_SIZE)
25 changes: 25 additions & 0 deletions test/load/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Load tests

The document describes how to run load tests against https://metadata.cardano-testnet.iohkdev.io/.
It is recommended to perform a load run before every release to gather results and make sure there is no performance deterioration or any unexpected behavior.

Performance tests are completed with locust.io, written in Python, and performed from a test engineers home computer. The users are ramped up at a rate of 10 per second until they hit the target Total Users. This is maintained for several minutes and results are then aggregated from across the entire run.

## To run the test

1. Start locust docker
```
$ cd test/load
$ make
```

2. Visit http://0.0.0.0:8089/ and run test from there.

## Pre-relese test

Total Users = 1000
Ramp up rate = 10

Execution time = 10 minutes from the point where all users ramp up.

Store results in https://github.com/input-output-hk/offchain-metadata-tools/wiki/Load-Tests-Results
Empty file added test/load/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions test/load/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'

services:
master:
image: locustio/locust
ports:
- "8089:8089"
volumes:
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --master --csv=/mnt/locust/results

worker:
image: locustio/locust
volumes:
- ./:/mnt/locust
command: -f /mnt/locust/locustfile.py --worker --master-host master
Empty file added test/load/generator/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions test/load/generator/properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from random import choice
from string import ascii_uppercase

properties = ["subject", "url", "name", "ticker", "policy", "logo", "description"]

def get_random_property():
return choice(properties)

def get_invalid_property():
return (''.join(choice(ascii_uppercase) for i in range(8)))

if __name__ == '__main__':
pass
29 changes: 29 additions & 0 deletions test/load/generator/subjects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from random import choice
from string import ascii_uppercase

subjects = ["2e6d83507419c027eac6eb9430b780c0793e2c1762b7bff56fbba6f5736f6d65636f696e",
"34250edd1e9836f5378702fbf9416b709bc140e04f668cc3552085184154414441636f696e",
"34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518",
"3e8777fa3ed835dd8036d2182918845c72a91b22c098439fd77dcbc350",
"446ffdf62c2474c0f84387b3ed0796b7d2daab0b282742dfad02da3f544553544e45544e465430303076303030",
"69b30e43bc5401bb34d0b12bd06cd9b537f33065aa49df7e8652739d4c51",
"6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7",
"789ef8ae89617f34c07f7f6a12e4d65146f958c0bc15a97b4ff169f16861707079636f696e",
"789ef8ae89617f34c07f7f6a12e4d65146f958c0bc15a97b4ff169f17375706572636f696e",
"789ef8ae89617f34c07f7f6a12e4d65146f958c0bc15a97b4ff169f174727565636f696e",
"789ef8ae89617f34c07f7f6a12e4d65146f958c0bc15a97b4ff169f1",
"9b87fdecd7a27e3b570fe821d790034a782d5248f4d22efc165c4d20796f7572636f696e",
"baa836fef09cb35e180fce4b55ded152907af1e2c840ed5218776f2f",
"c43a140cfe4476635776dbc5adea18604997348fc00607925165d4d4636f6c696e636f696e",
"c43a140cfe4476635776dbc5adea18604997348fc00607925165d4d46a616d6573636f696e",
"fc88532b68d36f5d951f44155166091a234a064250a6ae844128f8a4686f736b636f696e73"
]

def get_random_subject():
return choice(subjects)

def get_invalid_subject():
return (''.join(choice(ascii_uppercase) for i in range(56)))

if __name__ == '__main__':
pass
60 changes: 60 additions & 0 deletions test/load/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from locust import HttpUser, TaskSet, constant, task

from generator.subjects import get_random_subject, get_invalid_subject
from generator.properties import get_random_property, get_invalid_property

class QueryUser(HttpUser):
host = "https://metadata.cardano-testnet.iohkdev.io"

# between each task a user will wait 1 second
wait_time = constant(1)

# task(n) assigns the probability of that task being performed by the user.
# in this code, task(1) is equal to 10% and task(2) is equal to 20%

@task(2)
def get_metadata_subject(self):
subject = get_random_subject()
self.client.get(f"/metadata/{subject}")

@task(2)
def get_metadata_subject_properties(self):
subject = get_random_subject()

self.client.get(f"/metadata/{subject}/properties")

# @task(2)
# def get_metadata_subject_properties_property(self):
# subject = get_random_subject()
# property = get_random_property()

# self.client.get(f"/metadata/{subject}/properties/{property}")

# @task(1)
# def get_metadata_query(self):
# self.client.get(f"/metadata/query")

@task(1)
def get_metadata_subject_invalid(self):
subject = get_invalid_subject()

with self.client.get(f"/metadata/{subject}", catch_response=True) as response:
if response.status_code == 404:
response.success()

@task(1)
def get_metadata_subject_properties_invalid(self):
subject = get_invalid_subject()

with self.client.get(f"/metadata/{subject}/properties", catch_response=True) as response:
if response.status_code == 404:
response.success()

@task(1)
def get_metadata_subject_properties_property_invalid(self):
subject = get_invalid_subject()
property = get_invalid_property()

with self.client.get(f"/metadata/{subject}/properties/{property}", catch_response=True) as response:
if response.status_code == 404:
response.success()

0 comments on commit 80e5bfa

Please sign in to comment.