Reputation: 103
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
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