mirror of
https://github.com/django/daphne.git
synced 2025-06-29 17:33:05 +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
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -10,5 +10,6 @@ __pycache__/
|
||||||
.coverage.*
|
.coverage.*
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
IDE and Tooling files
|
# IDE and Tooling files
|
||||||
.idea/*
|
.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:
|
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::
|
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
|
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
|
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:
|
How to use with runserver:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -62,7 +75,7 @@ In another terminal window, run the benchmark with::
|
||||||
|
|
||||||
|
|
||||||
Additional load testing options:
|
Additional load testing options:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
If you wish to setup a separate machine to loadtest your environment, you can do the following steps.
|
If you wish to setup a separate machine to loadtest your environment, you can do the following steps.
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
from channels.sessions import enforce_ordering
|
from channels.sessions import enforce_ordering
|
||||||
|
|
||||||
|
|
||||||
#@enforce_ordering(slight=True)
|
|
||||||
def ws_connect(message):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
#@enforce_ordering(slight=True)
|
|
||||||
def ws_message(message):
|
def ws_message(message):
|
||||||
"Echoes messages back to the client"
|
"Echoes messages back to the client"
|
||||||
message.reply_channel.send({
|
message.reply_channel.send({'text': message['text']})
|
||||||
"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
|
@task
|
||||||
def run_daphne(redis_ip):
|
def run_daphne(redis_ip):
|
||||||
with cd("/srv/channels/testproject/"):
|
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
|
@task
|
||||||
|
|
|
@ -3,7 +3,10 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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
|
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
|
from chtest import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [url(r'^$', views.index)]
|
||||||
url(r'^$', views.index),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from chtest import consumers
|
from chtest import consumers
|
||||||
|
|
||||||
channel_routing = {
|
channel_routing = {"websocket.receive": consumers.ws_message}
|
||||||
"websocket.receive": consumers.ws_message,
|
|
||||||
"websocket.connect": consumers.ws_connect,
|
|
||||||
}
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user