Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 384
fanar Avatar asked Sep 11 '09 17:09

fanar


People also ask

What framework is better than Django?

Flask renders full control and is highly suitable for small projects that necessitate experimentation. Django is complicated and requires vast knowledge but it stands out as one of the best frameworks for building sophisticated applications.

Does Django use twisted?

You could use twisted to write the http server Django runs on. If you use Django you are limited to http model, with twisted it could be communicating in any protocol you like including push protocols.

What is comparable to Django?

Laravel Features. Similar to Django, Laravel also has wide-ranging features to help developers create products with ease. Some of the features of Laravel are: Free and open source: Laravel is open source and available free to use.

Is Django good for server?

Django is an extremely popular and fully featured server-side web framework, written in Python. This module shows you why Django is one of the most popular web server frameworks, how to set up a development environment, and how to start using it to create your own web applications.


4 Answers

First off Django is a framework for writing web apps so it provides ORM, html templating, it requires running an http server etc. Twisted helps to write much lower level code than that. You could use twisted to write the http server Django runs on. If you use Django you are limited to http model, with twisted it could be communicating in any protocol you like including push protocols. So for your chat example you get a server that scales better since it can push comments to people who have logged in VS with django every client having to poll repeatedly.

edited to reflect comments by: sos-skyl

like image 68
stonemetal Avatar answered Sep 23 '22 14:09

stonemetal


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.

like image 31
Vinay Sajip Avatar answered Sep 21 '22 14:09

Vinay Sajip


The biggest advantage for me is that Twisted gives me an application that has state, and can communicate with many different clients using many protocols.

For me, my Twisted server communicates with a number of sensors installed in houses and businesses that monitor power usage. It stores the data and keeps recent data and state in handy-dandy python classes in memory. Requests via xmlrpc from django get this state and can present recent data to the user. My Gridspy stuff is still in development so the actual site at your.gridspy.co.nz is a bit pre-alpha.

The best part is that you need surprisingly little code to make an effective server. An amazing amount of the work is done for you.

like image 41
Tom Leys Avatar answered Sep 24 '22 14:09

Tom Leys


In twisted you can implement protocols of your own. Django certainly can't do this.

like image 28
Skylar Saveland Avatar answered Sep 22 '22 14:09

Skylar Saveland