fanar fanar - 5 months ago 18
Python Question

Twisted(asynch server) vs Django(or any other framework)

I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives it an advantage for real-time apps like the chat app?

Sorry I am obviously little confused about the need for an asynchronous framework.

Answer

Asynchronous servers support much larger numbers of simultaneous client connections. More conventional servers come up against thread and process limits when servicing large number of concurrent clients, particularly those with long-lived connections. Async servers can also provide better performance as they avoid the overheads of e.g. thread context switching.

As well as the Twisted framework, there are also asynchronous server building blocks in Python's standard library: previously asyncore and asynchat, but now also asyncio.