This is how you'd Bench a Grape!
Project description
This is how you Bench a Grape!
locust benchmarks for chatgrape with websockets/wamp and long polling as well as websocket stability reports.
Installation from PyPi Package
pip install benchgrape
virtualenv recommended, see below
PyPi package installation in virtualenv
sudo apt install python3-venv python3-pip
pip3 install virtualenv
mkdir benchgrape
cd benchgrape
virtualenv -p python3 .
source ./bin/activate
pip install benchgrape
benchgrape --help
Upgrading
pip install --upgrade benchgrape
Deployments (currently broken and not maintained)
Docker
Included is a basic Dockerfile
for building and distributing Bench Grape
,
and can be built with the included make
helper:
make docker
docker run -it benchgrape --help
Usage
Test Websocket Stability
connect a good amount of websockets to a server and monitor their stability. can be done with a single user which is passed in the args.
benchgrape benchmark websocket-stability --url http://localhost --port 8000 --username admin --password 'quote-if-special-chars' --org 1 --websockets 10 --activity mechanical_keyboard
go to the web interface and have fun
Single User Benchmark
does crazy requests and tries to massacre your grape server
benchgrape benchmark single-user --url http://localhost --port 8000 --username admin --password admin --org 1 --websockets 10 --activity mechanical_keyboard
Multi User Benchmark
This feature is work in progress! Login multiple different users
Generating Credentials in Grape for multiple users
grape@deploy:/srv/grape$ python manage.py shell_plus
# do not user all users, use "filter" for bechmark users!
import json
tokens = []
for u in User.objects.all():
t, _=Token.objects.get_or_create(user=u)
tokens.append(t.key)
data = {
'tokens': tokens,
}
with open('/tmp/benchmark_tokens.json', 'w') as outfile:
json.dump(data, outfile)
exit
exit
docker cp 1504c01d3679:/tmp/benchmark_tokens.json ~/workspace/benchgrape/
running multiuser mode
benchgrape benchmark multi-user --url http://localhost --port 8000 --username admin --password admin --org 1 --websockets 10 --activity mechanical_keyboard --tokens ./benchmark_tokens.json
Start the configured Benchmark
- visit http://localhost:8089/
- select amount of users/(which is connections for websocket stability), f.e. 100
- select hatch rate, this is the amount of users per second which will connect. weaker systems should not go over 10.
- start and watch.
- logs in ./logs/stats.log and ./logs/debug.log
Master Slave Setups
using locust directly for master-slave setup, currently:
locust --help
-
running one process of locust is bound to 1 CPU max and handles roughly 500 users per CPU core. for serious stuff you need to check how much CPU your python request process uses, if it hits the 90s, proceed with master/slave setup.
-
start one master like this:
benchgrape benchmark single-user --master --url http://localhost --port 8000 --username admin --password admin --org 1 --websockets 10 --activity mechanical_keyboard
-
start at least one slave like this:
locust --slave --master-host=MASTER_HOST_OR_IP
Interpreting the Result
Type Name # Requests # Fails Median (ms) Average (ms) Min (ms) Max (ms) Average size (bytes) Current RPS
WebSocket Recv 100 0 0 0 0 0 51 0
GET /api/accounts/session/ 100 0 290 336 251.3880729675293 953.8741111755371 356 0
WebSocket Recv ping 211 0 -9977 -9984 -10001 0 19 10
WebSocket Sent ping 211 0 0 0 0 0 33 10
Total 622 0 0 -3333 -10001 953.8741111755371 83 20
there should be no # Fails and no WEBSOCKET_DROP events in the list. only
-
WebSocket Recv
-
GET /api/accounts/session/
-
WebSocket Sent Ping
-
WebSocket Recv Ping
-
the hostname is passed in the locust command and taken from there.
-
heads up: if 2fa is on, the login wont work. you need to pass the token directly.
Development
cd benchgrape
python3 -m pip install --upgrade pip
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
python setup.py develop # -> uses the live code for development
benchgrape --help # see if the command line tool is linked and works
make test
Revert an installed package to continue development, switch between
python setup.py install
python setup.py develop
Releasing to PyPi
Before releasing to PyPi, you must either configure your login credentials or you will be prompted every time upon upload
~/.pypirc:
[pypi]
username = YOUR_USERNAME
password = YOUR_PASSWORD
Then use the included helper function via the Makefile
:
make dist
make dist-upload
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file benchgrape-0.0.13.dev20200328172124.tar.gz
.
File metadata
- Download URL: benchgrape-0.0.13.dev20200328172124.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1671a015d0ca4405cef0ddea8eb18218bc72b2272faeff066498b3652911e6e1 |
|
MD5 | 0bcda07390b784e2717a013553928abb |
|
BLAKE2b-256 | 533de7f8d9c6bb975c7ff36ffc114664077289461a0b772295f8480089ad49cc |
File details
Details for the file benchgrape-0.0.13.dev20200328172124-py3-none-any.whl
.
File metadata
- Download URL: benchgrape-0.0.13.dev20200328172124-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a070f0914027f1354b017eea9ecb0adf31857239fab713fc12581bac9a841ae2 |
|
MD5 | 95d0c2738f139e1f73f2743b501111bc |
|
BLAKE2b-256 | f3a86ee72765c62fa354136c2283a368d993c1bdef576f6491a2fd64639650f6 |