I want to use django channels on an existing project to support websockets, but i'm having doubts about scalability i know daphne server can only handle so much opened connections
1-how many simultaneous connection can one daphne instance handle?
2-can it scale using a load balancer to be able to handle big traffic (let's say 100k simultaneous websocket connections)?
TL;DR: Scaling to 5k connections is fairly easy to do, I'm unsure beyond that. Stress testing your specific use case is going to be the best way to know with certainty if it will work for you or not.
We're currently using a channels setup that maintains around 5-6k websocket connections from iot devices that are sending ~10 messages per second each, most of those messages also result in at least 2-3 Postgres DB calls. We currently use 256 servers each running one daphne process on AWS ECS that is load balanced behind an AWS ALB. This is the first time any of us on the project have used websockets/channels/daphne so I'm certain we're not doing this in the optimal way (according to metrics the servers are largely sitting idle the whole time so I suspect we're not yielding/awaiting somewhere like we should be or something like that). The tasks are also incredibly small as all 256 of them run on a collective 16 vCPU and about 64GB of ram. We've also discovered that it's usually the shared resources (i.e. DB/Redis/etc.) that have the concurrency issues over the webservers themselves. It's pretty trivial to just throw more servers at it to handle additional websocket connections.
One thing that we've learned is that big distributed systems like this don't always react in the way you expect and it's often the tiniest things that will bite you. Therefore, we've built a stress-testing environment based on Locust that lets us try out code changes with fake clients before deploying to production. I strongly recommend you trying this out with your specific use case to either gain the confidence in the technology or at least know what is most likely to break first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With