Skip to content

Commit

Permalink
locust scripts for apache performance testing #2180
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jun 24, 2015
1 parent a69ab8f commit e09810e
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 18 deletions.
18 changes: 0 additions & 18 deletions scripts/issues/2180/locust

This file was deleted.

2 changes: 2 additions & 0 deletions tests/locust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
settings.json
5 changes: 5 additions & 0 deletions tests/locust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```
cp settings.json.template settings.json
$EDITOR settings.json
./locust
```
22 changes: 22 additions & 0 deletions tests/locust/basic_test_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from locust import HttpLocust, TaskSet
from dataverse_tasks import homepage, random_dataset_page
import requests
requests.packages.urllib3.disable_warnings()


class BrowseAndDownloadBehavior(TaskSet):
tasks = {
homepage: 50,
random_dataset_page: 50,
}


class WebsiteUser(HttpLocust):
task_set = BrowseAndDownloadBehavior
min_wait = 5000 # min pause before new task
max_wait = 20000 # max pause before new task

"""
locust -f basic_test_01.py
http://127.0.0.1:8089/
"""
29 changes: 29 additions & 0 deletions tests/locust/dataverse_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from locust_settings import get_settings_info, KEY_PERSISTENT_IDS
import random


def get_locust_request_kwargs():
return dict(verify=False,) # allow a self-signed certificate


def homepage(l):
msg('> homepage')
l.client.get('/', **get_locust_request_kwargs())


def random_dataset_page(l):
msg('> random_dataset_page')

persistent_ids = get_settings_info(KEY_PERSISTENT_IDS)
assert persistent_ids is not None, 'No values found in creds file for %s' % KEY_PERSISTENT_IDS
assert len(
persistent_ids) > 0, 'No values found in creds file for list %s' % KEY_PERSISTENT_IDS

random_id = random.choice(persistent_ids)

dataset_url = '/dataset.xhtml?persistentId=%s' % random_id

l.client.get(dataset_url, **get_locust_request_kwargs())


def msg(s): print s
27 changes: 27 additions & 0 deletions tests/locust/locust
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
OUTDIR=out
mkdir -p $OUTDIR
HELP_CMD=`locust --help 2>/dev/null`
HELP_EXIT=$?
if [ $HELP_EXIT -ne 0 ]; then
echo "Please set up an Python virtualenv and install locust"
exit 1
fi
OUTFILE=$1
if [ "$1" = "apache" ] ; then
PORT=:8181
elif [ "$1" = "glassfish" ] ; then
PORT=""
else
echo "Please specify either apache or glassfish".
exit 1
fi
NUM=1
if [ ! -z "$2" ]; then
if [ "$2" -gt "$NUM" ] ; then
NUM=$2
fi
fi
for i in $(seq 1 $NUM); do
locust -f basic_test_01.py -c 2 -r 2 -n 4 --no-web --print-stats --host=https://shibtest.dataverse.org$PORT 2>&1 | tee $OUTDIR/$OUTFILE.`date +%s`.txt
done
24 changes: 24 additions & 0 deletions tests/locust/locust_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from os.path import isfile, join, dirname, abspath
import json

KEY_PERSISTENT_IDS = 'PERSISTENT_IDS'
STRESS_TEST_DIR = dirname(abspath(__file__))
SETTINGS_FILE = join(STRESS_TEST_DIR, 'settings.json')


def get_settings_info(key_name):
SETTINGS_LOOKUP = {}
assert isfile(SETTINGS_FILE), 'File not found: %s' % SETTINGS_FILE

if key_name in SETTINGS_LOOKUP:
return SETTINGS_LOOKUP.get(key_name)

json_settings = json.loads(open(SETTINGS_FILE, 'r').read())

assert key_name in json_settings, 'Key *%s* not found in settings file' % key_name

cred_value = json_settings.get(key_name)

SETTINGS_LOOKUP[key_name] = cred_value

return cred_value
3 changes: 3 additions & 0 deletions tests/locust/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locustio==0.7.2
flake8==2.3.0
autopep8==1.1.1
6 changes: 6 additions & 0 deletions tests/locust/settings.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"PERSISTENT_IDS": [
"doi:10.5072/FK2/AXO8TS",
"doi:10.5072/FK2/ONUS32"
]
}
2 changes: 2 additions & 0 deletions tests/locust/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120

0 comments on commit e09810e

Please sign in to comment.