Gurmessa Lemma
Gurmessa Lemma

Reputation: 103

How much websocket connection can one daphne handle at the same time and how can I increase the max connection

I have 10 daphne instances running When I try to connect 400 clients, only a few connection lost. When I try to connect 1000 clients, more than 400 connection lost.

from channels.consumer import SyncConsumer,AsyncConsumer
from websocket.utils import *
from asgiref.sync import async_to_sync
import threading
import time
#from channels_presence.models import Room
#from channels_presence.models import Presence

class Consumer(AsyncConsumer):

    async def websocket_connect(self, event):
        await self.send({
            "type": "websocket.accept",
        })
 


    async def websocket_receive(self, event):
        await self.send({
             "type": "websocket.send",
             'text': "testtt"
        })



    async def websocket_disconnect(self, close_code):
        #Room.objects.remove("some_room", self.channel_name)
        pass

    
Django==2.2.8
channels==2.3.1
channels-redis==2.4.1
psycopg2==2.8.5
daphne==2.5.0
django-channels-presence

settings.py

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    }
}

Upvotes: 2

Views: 567

Answers (1)

Devsidhu
Devsidhu

Reputation: 11

use redis for reliable connection in memory use is not great for production

`CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
                "hosts": [("redis://:" + config('REDIS_SERVER_PASSWORD') + "@" + config('REDIS_SERVER_HOST') + ":" + config('REDIS_SERVER_PORT'))],
                
        },
    },
}

Upvotes: 1

Related Questions