-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
locust scripts for apache performance testing #2180
- Loading branch information
Showing
10 changed files
with
120 additions
and
18 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``` | ||
cp settings.json.template settings.json | ||
$EDITOR settings.json | ||
./locust | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 120 |