add performance test make commands, dockerfile for locust, and rough draft of performance test (locust.py)

This commit is contained in:
Jonathan Math 2021-02-24 10:21:47 -05:00
parent 2ee9f32e0a
commit 8c736ac489
5 changed files with 47 additions and 0 deletions

View file

@ -79,3 +79,13 @@ deploy:
firewall:
- ansible-playbook ansible/provision.yml --tags firewall -l db
# performance tests
perf-cli:
locust -f perf/locust.py --headless -u $(users) -r $(rate) --run-time 5m --host=$(host)
perf-ui:
locust -f perf/locust.py
perf-docker:
- docker build . --file=./perf/Dockerfile --tag=perf-docker
- docker run -it -p 8089:8089 perf-docker locust -f locust.py

View file

@ -104,6 +104,16 @@ reader, and feed importer. To run the test suite:
`make test`
### Running a performance test
Performance tests use the locust performance testing tool. To run performance tests via CLI, use
`make perf-cli users=1 rate=1 host=https://nb.local.com`. Feel free to change the users, rate, and host
variables in the command to meet you needs.
You can also run locust performance tests using a UI by running `make perf-ui` and then navigating to
http://127.0.0.1:8089. This allows you to chart and export your performance data.
To run locust using docker, just run `make perf-docker` and navigate to http://127.0.0.1:8089
## Author

View file

@ -30,6 +30,7 @@ hiredis==1.1.0
httplib2==0.18.1
image==1.5.33
isodate==0.6.0
locust==1.4.3
lxml==4.6.2
mock==4.0.2
mongoengine==0.21.0

5
perf/Dockerfile Normal file
View file

@ -0,0 +1,5 @@
FROM python:3.9-slim
RUN apt-get update && apt-get install gcc -y
RUN pip3 install locust
COPY perf/locust.py /perf/locust.py
WORKDIR /perf/

21
perf/locust.py Normal file
View file

@ -0,0 +1,21 @@
import time
from locust import HttpUser, task, between
import os
import requests
class NB_PerfTest(HttpUser):
wait_time = between(1, 2.5)
@task
def homepage(self):
url = "/"
self.client.get(url, verify=False)
@task
def river(self):
url = "/api#/reader/river_stories"
self.client.get(url, verify=False)
@task
def load_single_feed(self):
url = "/site/1186180/best-of-metafilter"