Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between node.js and Tornado [closed]

Besides the fact that node.js is written in JS and Tornado in Python, what are some of the differences between the two? They're both non-blocking asynchronous web servers, right? Why choose one over the other besides the language?

like image 794
coffee-grinder Avatar asked Apr 06 '11 05:04

coffee-grinder


3 Answers

The main advantage of node.js is that all its libraries are async so you don't have to worry much about blocking. There are async libraries for mysql, postgres, redis, etc. All is async by default.

Python have a library for anything - but most of these libraries are not asynchronous. In order to take advantage of tornado (and not to block the process) special libraries for are necessary (e.g. you can't just 'pip install redis' and use it, you'll need something like brukva), and there are much less tornado libraries than node.js libraries. There is no async mysql tornado driver available at the moment, for example (or at least I'm not aware of it).

But you can still use many python libraries with tornado (ones that doesn't do i/o), and tornado community is raising and filling the gaps.

It is easier to write an app using node.js than using tornado in my experience. I personally switched to tornado from node.js because it fits into existing infrastructure of my python project better (integration between django site serving html pages and tornado server providing realtime features was quite painless).

like image 131
Mikhail Korobov Avatar answered Oct 13 '22 17:10

Mikhail Korobov


As Rich Bradshaw points out Node.js is written in JS, which means you can keep the front end and the back end in the same language and possibly share some codebase. To me that is a huge potential benefit of Node.js. Node also comes with more asynchronous libraries out of the box it seems.

V8 should make JS faster than Python at least that's what benchmarks seem to suggest, but it may not matter much, because both Node.js and Tornado (and most other web frameworks for that matter) use wrappers for native libraries. A lot of the Python standard library is written in C or can be replaced by a faster alternative, which mitigates potential differences even more.

Web services are usually I/O bound, so that means we're spending the time waiting for the data store and not processing the data. That makes the synthetic speed difference between JS and Python irrelevant in many applications.

like image 26
Morten Jensen Avatar answered Oct 13 '22 16:10

Morten Jensen


node.js uses V8 which compiles into assembly code, tornado doesn't do that yet.

Other than that (which doesn't actually seem to make much difference to the speed), it's the ecosystem. Do you prefer the event model of JS, or the way Python works? Are you happier using Python or JS libraries?

like image 10
Rich Bradshaw Avatar answered Oct 13 '22 15:10

Rich Bradshaw