Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many concurrent connections can django-channels handle?

I am using Django channels for chat application. This application might scale to 100k concurrent users in some amount of time. I am wondering how many concurrent connections can Django Channels handle. Basically, what I am comparing it with is XMPP server, that whether XMPP is a better choice for scalability or I should continue with Django channels?

Also, I am using a redis layer as the channel layer. I was wondering if redis layer can be a bottle neck at some point of time?

Thanks

like image 973
hardik24 Avatar asked May 01 '19 07:05

hardik24


People also ask

What is the difference between Django channels and HTTP?

Django still handles traditional HTTP, whilst Channels give you the choice to handle other connections in either a synchronous or asynchronous style. To get started understanding Channels, read our Introduction , which will walk through how things work.

What is the difference between channels and ASGI in Django?

Channels builds upon the native ASGI support available in Django since v3.0, and provides an implementation itself for Django v2.2. Django still handles traditional HTTP, whilst Channels give you the choice to handle other connections in either a synchronous or asynchronous style.

How do you handle persistent connections in Django?

Enable persistent connections If the application needs to process a large number of requests, enable maintaining persistent connections to the database. Django closes the connection by default at the end of each request and persistent connections avoid overloading the database for each request.

How to handle a large number of requests in Django?

If the application needs to process a large number of requests, enable maintaining persistent connections to the database. Django closes the connection by default at the end of each request and persistent connections avoid overloading the database for each request.


1 Answers

ASGI (Asynchronous Server Gateway Interface) is intended to provide a standard interface between async-capable Python web servers, frameworks, and applications.

In Django Channels, even though Django itself in a synchronous mode it can handle connections and sockets asynchronously.

Websockets go into a server called Daphne (Daphne is a HTTP, HTTP2 and WebSocket protocol server for ASGI and ASGI-HTTP, developed to power Django Channels) can handle hundreds or potentially thousands of simultaneous connections open at once.

Any event on a websocket (connect, message received) is sent onto the channel layer, which is a type of first-in-first-out queue

Django worker processes synchronously take a message from the queue, process it, and then loop back to take another.

So, the number of open connections affects how many Daphne instances you run. And throughput of events affects the number of workers you run.

like image 153
psorab Avatar answered Sep 22 '22 20:09

psorab