Add locust perf testing
This commit is contained in:
@@ -4,21 +4,23 @@ Provides a REST API to Photowall database.
|
||||
|
||||
## Installation
|
||||
|
||||
Make sure that your system has Python version 3.4 installed. If you dont have it here is how you install it on Ubuntu 12.04:
|
||||
```
|
||||
$ sudo add-apt-repository ppa:fkrull/deadsnakes
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install python3.4 python3.4-dev build-essential libpq-dev
|
||||
```
|
||||
Make sure that your system has Python version 3.6 installed.
|
||||
|
||||
Next its recommended that you create a [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/) of python 3.4 and install all packages in it.
|
||||
Next its recommended that you create a [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/) of python 3.6 and install all packages in it.
|
||||
To do that execute the following commands in your project folder:
|
||||
```
|
||||
$ virtualenv -p /usr/bin/python3.4 venv
|
||||
$ virtualenv -p /usr/bin/python3.6 venv
|
||||
$ source venv/bin/activate
|
||||
$ pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Local testing with docker
|
||||
Make sure you edit `docker-compose.yml` with correct environment variables.
|
||||
This will launch the production image and listen on port 1881.
|
||||
```
|
||||
$ docker-compose up --force-recreate --build -d
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is available [here](docs)
|
||||
@@ -55,3 +57,10 @@ The staging branch is automatically synced from master on new commits to master.
|
||||
To run unit tests:
|
||||
|
||||
`$ python -m unittest`
|
||||
|
||||
## Performance testing with Locust
|
||||
Run locally
|
||||
```
|
||||
$ pip install locust
|
||||
$ USERNAME=user locust --host=http://localhost:1881
|
||||
```
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import random
|
||||
import os
|
||||
from locust import HttpLocust, TaskSet, task, between
|
||||
|
||||
|
||||
"""
|
||||
## Performance testing with Locust
|
||||
Run locally
|
||||
```
|
||||
$ pip install locust
|
||||
$ USERNAME=user locust --host=http://localhost:1880
|
||||
```
|
||||
"""
|
||||
username = os.environ.get("USERNAME")
|
||||
password = ""
|
||||
|
||||
products = {
|
||||
"58339",
|
||||
"46768",
|
||||
"48067",
|
||||
"60643",
|
||||
"62101",
|
||||
}
|
||||
|
||||
markets = {
|
||||
"SE",
|
||||
"GB",
|
||||
"NO",
|
||||
"DE"
|
||||
}
|
||||
|
||||
product_query = {
|
||||
"wallpaper?width=100&height=100",
|
||||
"canvas?width=100&height=70",
|
||||
"poster?width=70&height=50",
|
||||
"framed-print?sku=GLOBAL-CFP-20x28"
|
||||
}
|
||||
|
||||
|
||||
def random_product():
|
||||
return random.sample(products, 1)[0]
|
||||
|
||||
def random_market():
|
||||
return random.sample(markets, 1)[0]
|
||||
|
||||
def random_product_query():
|
||||
return random.sample(product_query, 1)[0]
|
||||
|
||||
|
||||
class QueryTaskSet(TaskSet):
|
||||
def on_start(self):
|
||||
self.client.auth = (username, password)
|
||||
|
||||
@task(10)
|
||||
def product_price(self):
|
||||
""" get random product with details"""
|
||||
self.client.get("/prices/{0}&territory={1}&product={2}".format(random_product_query(), random_market(),random_product()))
|
||||
|
||||
@task(1)
|
||||
def stop(self):
|
||||
self.interrupt()
|
||||
|
||||
|
||||
class UserBehaviour(TaskSet):
|
||||
tasks = {QueryTaskSet: 10}
|
||||
|
||||
|
||||
class Api2Locust(HttpLocust):
|
||||
task_set = UserBehaviour
|
||||
wait_time = between(0.100, 3)
|
||||
Reference in New Issue
Block a user