mirror of
https://github.com/django/daphne.git
synced 2025-04-21 01:02:06 +03:00
Correct benchmark test for recent channels version. (#487)
* Ignore Emacs backups. * Do not override default websocket.connect handler. Channels specification 1.0 requires that websocket.connect handler returns meaningful message with {'accept': True} at least. * Add rabbitmq channel layer settings. * Add benchmark requirements in separate file. * Add RabbitMQ infrastructure part. * Adapt benchmark README for new docker layout. * Adapt fabric deploy for new settings module.
This commit is contained in:
parent
fd30bff5de
commit
335cd1625e
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -10,5 +10,6 @@ __pycache__/
|
|||
.coverage.*
|
||||
TODO
|
||||
|
||||
IDE and Tooling files
|
||||
.idea/*
|
||||
# IDE and Tooling files
|
||||
.idea/*
|
||||
*~
|
||||
|
|
27
testproject/Dockerfile.rabbitmq
Normal file
27
testproject/Dockerfile.rabbitmq
Normal file
|
@ -0,0 +1,27 @@
|
|||
FROM ubuntu:16.04
|
||||
|
||||
MAINTAINER Artem Malyshev <proofit404@gmail.com>
|
||||
|
||||
# python-dev \
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
git \
|
||||
python-setuptools \
|
||||
python-pip && \
|
||||
pip install -U pip
|
||||
|
||||
# Install asgi_rabbitmq driver and most recent Daphne
|
||||
RUN pip install \
|
||||
git+https://github.com/proofit404/asgi_rabbitmq.git#egg=asgi_rabbitmq \
|
||||
git+https://github.com/django/daphne.git@#egg=daphne
|
||||
|
||||
# Clone Channels and install it
|
||||
RUN git clone https://github.com/django/channels.git /srv/channels/ && \
|
||||
cd /srv/channels && \
|
||||
git reset --hard origin/master && \
|
||||
python setup.py install
|
||||
|
||||
WORKDIR /srv/channels/testproject/
|
||||
ENV RABBITMQ_URL=amqp://guest:guest@rabbitmq:5672/%2F
|
||||
|
||||
EXPOSE 80
|
|
@ -18,13 +18,13 @@ e.g. to create it right in the test directory (assuming python 2 is your system'
|
|||
How to use with Docker:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Build the docker image from Dockerfile, tag it `channels-test`::
|
||||
Build the docker image from Dockerfile, tag it `channels-redis-test`::
|
||||
|
||||
docker build -t channels-test .
|
||||
docker build -t channels-redis-test -f Dockerfile.redis .
|
||||
|
||||
Run the server::
|
||||
|
||||
docker-compose up -d
|
||||
docker-compose -f docker-compose.redis.yml up
|
||||
|
||||
The benchmark project will now be running on: http:{your-docker-ip}:80
|
||||
|
||||
|
@ -40,6 +40,19 @@ Let's just try a quick test with the default values from the parameter list::
|
|||
|
||||
python benchmark.py ws://localhost:80
|
||||
|
||||
How to use with Docker and RabbitMQ:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Build the docker image from Dockerfile, tag it `channels-rabbitmq-test`::
|
||||
|
||||
docker build -t channels-rabbitmq-test -f Dockerfile.rabbitmq .
|
||||
|
||||
Run the server::
|
||||
|
||||
docker-compose -f docker-compose.rabbitmq.yml up
|
||||
|
||||
The rest is the same.
|
||||
|
||||
How to use with runserver:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -62,14 +75,14 @@ In another terminal window, run the benchmark with::
|
|||
|
||||
|
||||
Additional load testing options:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If you wish to setup a separate machine to loadtest your environment, you can do the following steps.
|
||||
|
||||
Install fabric on your machine. This is highly dependent on what your environment looks like, but the recommend option is to::
|
||||
|
||||
pip install fabric
|
||||
|
||||
|
||||
(Hint: if you're on Windows 10, just use the Linux subsystem and use ``apt-get install fabric``. It'll save you a lot of trouble.)
|
||||
|
||||
Git clone this project down to your machine::
|
||||
|
@ -81,7 +94,7 @@ Relative to where you cloned the directory, move up a couple levels::
|
|||
cd channels/testproject/
|
||||
|
||||
Spin up a server on your favorite cloud host (AWS, Linode, Digital Ocean, etc.) and get its host and credentials. Run the following command using those credentials::
|
||||
|
||||
|
||||
fab setup_load_tester -i "ida_rsa" -H ubuntu@example.com
|
||||
|
||||
That machine will provision itself. It may (depending on your vendor) prompt you a few times for a ``Y/n`` question. This is just asking you about increasing stroage space.
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
from channels.sessions import enforce_ordering
|
||||
|
||||
|
||||
#@enforce_ordering(slight=True)
|
||||
def ws_connect(message):
|
||||
pass
|
||||
|
||||
|
||||
#@enforce_ordering(slight=True)
|
||||
def ws_message(message):
|
||||
"Echoes messages back to the client"
|
||||
message.reply_channel.send({
|
||||
"text": message['text'],
|
||||
})
|
||||
message.reply_channel.send({'text': message['text']})
|
||||
|
|
28
testproject/docker-compose.rabbitmq.yml
Normal file
28
testproject/docker-compose.rabbitmq.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
version: '2'
|
||||
services:
|
||||
rabbitmq:
|
||||
image: rabbitmq:management
|
||||
ports:
|
||||
- "15672:15672"
|
||||
rabbitmq_daphne:
|
||||
image: channels-rabbitmq-test
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.rabbitmq
|
||||
command: daphne -b 0.0.0.0 -p 80 testproject.asgi.rabbitmq:channel_layer
|
||||
volumes:
|
||||
- .:/srv/channels/testproject/
|
||||
ports:
|
||||
- "80:80"
|
||||
depends_on:
|
||||
- rabbitmq
|
||||
rabbitmq_worker:
|
||||
image: channels-rabbitmq-test
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.rabbitmq
|
||||
command: python manage.py runworker --settings=testproject.settings.channels_rabbitmq
|
||||
volumes:
|
||||
- .:/srv/channels/testproject/
|
||||
depends_on:
|
||||
- rabbitmq
|
26
testproject/docker-compose.redis.yml
Normal file
26
testproject/docker-compose.redis.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
version: '2'
|
||||
services:
|
||||
redis:
|
||||
image: redis:alpine
|
||||
redis_daphne:
|
||||
image: channels-redis-test
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.redis
|
||||
command: daphne -b 0.0.0.0 -p 80 testproject.asgi.redis:channel_layer
|
||||
volumes:
|
||||
- .:/srv/channels/testproject/
|
||||
ports:
|
||||
- "80:80"
|
||||
depends_on:
|
||||
- redis
|
||||
redis_worker:
|
||||
image: channels-redis-test
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.redis
|
||||
command: python manage.py runworker --settings=testproject.settings.channels_redis
|
||||
volumes:
|
||||
- .:/srv/channels/testproject/
|
||||
depends_on:
|
||||
- redis
|
|
@ -1,18 +0,0 @@
|
|||
version: '2'
|
||||
services:
|
||||
redis:
|
||||
image: redis:alpine
|
||||
daphne:
|
||||
image: channels-test
|
||||
build: .
|
||||
command: daphne -b 0.0.0.0 -p 80 testproject.asgi:channel_layer
|
||||
ports:
|
||||
- "80:80"
|
||||
depends_on:
|
||||
- redis
|
||||
worker:
|
||||
image: channels-test
|
||||
build: .
|
||||
command: python manage.py runworker --settings=testproject.settings.channels_redis
|
||||
depends_on:
|
||||
- redis
|
2
testproject/fabfile.py
vendored
2
testproject/fabfile.py
vendored
|
@ -23,7 +23,7 @@ def setup_channels():
|
|||
@task
|
||||
def run_daphne(redis_ip):
|
||||
with cd("/srv/channels/testproject/"):
|
||||
sudo("REDIS_URL=redis://%s:6379 daphne -b 0.0.0.0 -p 80 testproject.asgi:channel_layer" % redis_ip)
|
||||
sudo("REDIS_URL=redis://%s:6379 daphne -b 0.0.0.0 -p 80 testproject.asgi.redis:channel_layer" % redis_ip)
|
||||
|
||||
|
||||
@task
|
||||
|
|
|
@ -3,7 +3,10 @@ import os
|
|||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
|
||||
os.environ.setdefault(
|
||||
"DJANGO_SETTINGS_MODULE",
|
||||
"testproject.settings.channels_redis",
|
||||
)
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
|
|
7
testproject/requirements.benchmark.txt
Normal file
7
testproject/requirements.benchmark.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
autobahn==0.17.1
|
||||
constantly==15.1.0
|
||||
incremental==16.10.1
|
||||
six==1.10.0
|
||||
Twisted==16.6.0
|
||||
txaio==2.6.0
|
||||
zope.interface==4.3.3
|
0
testproject/testproject/asgi/__init__.py
Normal file
0
testproject/testproject/asgi/__init__.py
Normal file
8
testproject/testproject/asgi/rabbitmq.py
Normal file
8
testproject/testproject/asgi/rabbitmq.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import os
|
||||
from channels.asgi import get_channel_layer
|
||||
|
||||
os.environ.setdefault(
|
||||
"DJANGO_SETTINGS_MODULE",
|
||||
"testproject.settings.channels_rabbitmq",
|
||||
)
|
||||
channel_layer = get_channel_layer()
|
14
testproject/testproject/settings/channels_rabbitmq.py
Normal file
14
testproject/testproject/settings/channels_rabbitmq.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Settings for channels specifically
|
||||
from testproject.settings.base import *
|
||||
|
||||
INSTALLED_APPS += ('channels',)
|
||||
|
||||
CHANNEL_LAYERS = {
|
||||
'default': {
|
||||
'BACKEND': 'asgi_rabbitmq.RabbitmqChannelLayer',
|
||||
'ROUTING': 'testproject.urls.channel_routing',
|
||||
'CONFIG': {
|
||||
'url': os.environ['RABBITMQ_URL'],
|
||||
},
|
||||
},
|
||||
}
|
|
@ -1,17 +1,11 @@
|
|||
from django.conf.urls import url
|
||||
from django.conf.urls import url
|
||||
from chtest import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index),
|
||||
]
|
||||
|
||||
urlpatterns = [url(r'^$', views.index)]
|
||||
|
||||
try:
|
||||
from chtest import consumers
|
||||
|
||||
channel_routing = {
|
||||
"websocket.receive": consumers.ws_message,
|
||||
"websocket.connect": consumers.ws_connect,
|
||||
}
|
||||
|
||||
channel_routing = {"websocket.receive": consumers.ws_message}
|
||||
except:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user