Skip to content

Commit

Permalink
update locust and add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Jun 16, 2023
1 parent bd58613 commit 27de719
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
20 changes: 20 additions & 0 deletions resources/locust/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Performance test for grobid-quantities

> conda create --name locust python=3.9 pip
> pip install locust
> cd resources/locust
Start the master
> locust --config master.conf
Start the worker (in this example we need at least one worker)
> locust --worker
Connect to the locust interface on http://localhost:8089

You can run the locust without interface by
1. set headless = True in the master.conf
2. specify an output html file ``--output output.html`` when you start the master
> locust --config master.conf
26 changes: 9 additions & 17 deletions resources/locust/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@

from locust import HttpUser, task, between

import json


class QuickstartUser(HttpUser):
wait_time = between(5, 9)

test_data = []
text_documents = []

@task
def process_text(self):
n = random.randint(0, len(self.test_data) - 1)
paragraph = self.test_data[n]
n = random.randint(0, len(self.text_documents) - 1)
text_document = self.text_documents[n]
headers = {"Accept": "application/json"}
files = {'text': str(paragraph)}
self.client.post(url="/quantities/service/processQuantityText", files=files,
headers=headers, name="quantity_text")
files = {"text": text_document}
self.client.post("/service/processQuantityText", files=files, headers=headers, name="processQuantityText")

# @task(3)
# def view_item(self):
# # item_id = random.randint(1, 10000)
# # self.client.get(f"/item?id={item_id}", name="/item")
# pass
#
def on_start(self):
with open("testData.txt", 'r') as fp:
lines = fp.readlines()
if len(self.text_documents) == 0:
with open("testData.txt", 'r') as fp:
lines = fp.readlines()

self.test_data.extend(lines)
self.text_documents.extend(lines)
9 changes: 9 additions & 0 deletions resources/locust/master.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# master.conf in current directory
locustfile = locustfile.py
headless = false
master = true
expect-workers = 1
host = http://localhost:8060
users = 100
spawn-rate = 10
run-time = 10m

0 comments on commit 27de719

Please sign in to comment.