Skip to content

Commit b5b763e

Browse files
author
ppanero
committed
benchmark: populating your instance and stress test with locust
1 parent cc0f81a commit b5b763e

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

docs/deployment/benchmark.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Benchmarking your Invenio instance
2+
3+
The operations that we are going to run in this section can be highly
4+
demanding. Therefore, you might not want to run them against a production
5+
instance since it might cause downtime.
6+
7+
Nonetheless, we want to have an environment that resembles as close as
8+
possible to our InvenioRDM instance. In consequence, we might want to add some
9+
data to our instance in order to have some records to stress-test against.
10+
11+
## Populate your instance
12+
13+
!!! info "Already populated instances"
14+
If you already have content in the instance this step is not needed.
15+
16+
We are going to create some demo records using a new CLI command.
17+
We are going to use `invenio` commands. You can lunch a job using the
18+
[provided job templates](https://github.com/inveniosoftware/helm-invenio/tree/master/jobs)
19+
(recommended) or execute them in a web container's terminal.
20+
21+
!!! warning "OpenShift commands"
22+
The following commands assume you are using OpenShift. For bare
23+
Kubernetes, commands might be slightly different.
24+
25+
**Launch a job**
26+
27+
You will need to either download the file from [here](https://github.com/inveniosoftware/helm-invenio/tree/master/jobs)
28+
or go to the `jobs` folder if you have the [helm-invenio](https://github.com/inveniosoftware/helm-invenio)
29+
repository cloned in your machine.
30+
31+
The following job will be executed by a worker and create 10 demo records.
32+
33+
``` console
34+
$ oc process -f job.yml --param JOB_NAME='demo-data' \
35+
--param JOB_COMMAND='invenio rdm-records demo' | oc create -f -
36+
```
37+
38+
**Execution in a web container**
39+
40+
To populate the instance with the alternative method, you need to connect to a
41+
running pod, activate python3 and execute the command:
42+
43+
```console
44+
$ oc get pods # List all pods
45+
$ oc exec -it <web-pod-id> bash # Connect to a web pod
46+
$ . scl_source enable rh-python36 # Activate python3
47+
$ invenio rdm-records demo # Create 10 demo records
48+
```
49+
50+
This methods populate the instance with 10 records. If you need more, you can
51+
run it multiple times. However, obtaining a high number of records might be
52+
time consuming with this method. In that case, you can use bulk indexing, you
53+
can find more documentation on how to do it [here](https://github.com/inveniosoftware/helm-invenio/tree/master/benchmark#populate-your-instance).
54+
55+
## Benchmark
56+
57+
In order to test the load that your instance is able to stand, you can use
58+
[Locust](https://docs.locust.io/en/stable/). [Here](https://github.com/inveniosoftware/helm-invenio/blob/master/benchmark/locustfile.py)
59+
you can find a `locustfile.py` file ready to test an Invenio instance. Let's
60+
test it!
61+
62+
First install locust:
63+
64+
``` console
65+
$ pip install locust
66+
```
67+
68+
The given locust file makes use of some values that you might want to
69+
adjust to your instance:
70+
71+
``` python
72+
RECID = 'h2kh0-vfq12'
73+
NON_EXISTING_RECID = 9999
74+
SEARCH_QUERY = "Baker"
75+
```
76+
77+
`RECID` represents the ID of a record that exists in the instance, while
78+
`NON_EXISTING_RECID` represents one that doesn't. Finally, `SEARCH_QUERY`
79+
should contain a string that matches a limited amount of records. The
80+
purpose of this query is to test when only certain records are returned.
81+
A full query (i.e. all records) is also tested.
82+
83+
Then, in order to lunch the tests you need to be in the directory where the
84+
`locustfile.py` is:
85+
86+
``` console
87+
$ curl https://raw.githubusercontent.com/inveniosoftware/helm-invenio/master/benchmark/locustfile.py \
88+
-o /path/where/to/save/locustfile.py
89+
$ cd /path/where/to/save/
90+
$ locust
91+
```
92+
93+
Once it is running, you can navigate to [the web interface](http://localhost:8089)
94+
and set the amount of users/and users joining per second. Play with these
95+
numbers until you reach the number of requests per second (shown in the top
96+
right) that you are looking for.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ nav:
4848
- Kubernetes: 'deployment/kubernetes.md'
4949
- System components: 'deployment/services.md'
5050
- Configuration: 'deployment/configuration.md'
51+
- Benchmarking: 'deployment/benchmark.md'
5152

5253

5354
# Customization

0 commit comments

Comments
 (0)