I am using django-channels
to add HTTP2
& WebSocket
support for my application. I could not find a lot of documentation as to how to scale channels. Below is my nginx
configuration that load balances multiple instances of daphne
running on the same machine but different ports. Is this the correct way to do it?
upstream socket {
least_conn;
server 127.0.0.1:9000;
server 127.0.0.1:9001;
server 127.0.0.1:9002;
server 127.0.0.1:9003;
}
server {
listen 80;
server_name 127.0.0.1;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/niscp/home-screen;
}
location /nicons/ {
root /home/niscp/home-screen;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/niscp/home-screen/home-screen.sock;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://socket;
}
}
Along with that, I am running individual instances of workers
to listen to individual channels in the following manner:
python manage.py runworker --only-channels=websocket.connect
python manage.py runworker --only-channels=websocket.receive
python manage.py runworker --only-channels=websocket.disconnect
I have got uwsgi
to handle all http requests the way django
normally handles them. All daphne
and workers
do is handle WebSocket
requests.
Is this a viable method to scale django-channels
, or is there something I could do better?