Skip to content

Commit

Permalink
Merge pull request #75 from o19s/load-test
Browse files Browse the repository at this point in the history
Adding basic load test
  • Loading branch information
epugh authored Feb 29, 2024
2 parents c6ad6a3 + e93c4a4 commit 639f5ee
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ build
*.ipr
*.iws
build-idea/
out/
out/

venv/
__pycache__/
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,28 @@ Delete the store:

```
curl -X DELETE http://localhost:9200/_plugins/ubi/awesome
```
```

## Load Test

The `load-test` directory contains a basic load testing example. The purpose of the files under `load-test` are to provide a means of testing the plugin's ability to receive and store a large number of events over time. To use the load test, first start OpenSearch on `localhost:9200`, and then:

```
cd load-test
source ./venv/bin/activate
./run.sh
```

The test will run for 10 seconds. The number of events sent will be shown along with the `_count` of events in the store:

```
Type Name # reqs # fails | Avg Min Max Med | req/s failures/s
--------|----------------------------------------------------------------------------|-------|-------------|-------|-------|-------|-------|--------|-----------
POST /_plugins/ubi/mystore 8 0(0.00%) | 8 6 9 8 | 0.81 0.00
--------|----------------------------------------------------------------------------|-------|-------------|-------|-------|-------|-------|--------|-----------
Aggregated 8 0(0.00%) | 8 6 9 8 | 0.81 0.00
Found 8 indexed
```

This shows 8 total requests made by locust, and 8 events are in the index. The idea being we can assert that the number of events sent matches the events stored in the index.
24 changes: 24 additions & 0 deletions load-test/load-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
from locust import HttpUser, between, task

class OpenSearchUBIClient(HttpUser):
wait_time = between(1, 2)

@task
def event_task(self):
headers = {
"Content-Type": "application/json"
}
data = {
"type": "instant-search",
"keywords": "khgkj",
"timestamp": "1705596607509",
"url": "file:///C:/jason/_dev/search/OpenSearch/src/search-collector/demo/order.html",
"ref": "",
"lang": "en-US",
"session": "npckcy4",
"channel": "demo-channel",
"query": ""
}

self.client.post("/_plugins/ubi/mystore", headers=headers, json=data)
1 change: 1 addition & 0 deletions load-test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locust==2.23.1
17 changes: 17 additions & 0 deletions load-test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

# Delete the store if it exists.
curl -X DELETE http://localhost:9200/_plugins/ubi/mystore

# Create the store
curl -X PUT http://localhost:9200/_plugins/ubi/mystore

# Insert events
locust -f load-test.py --headless -u 1 -r 1 --run-time 10s --host http://localhost:9200

# Let events index.
sleep 2

# Get count of indexed events.
EVENTS=`curl -s http://localhost:9200/.mystore_events/_count | jq .count`
echo "Found $EVENTS indexed"

0 comments on commit 639f5ee

Please sign in to comment.