Live data from Hacker News

Tornado: FriendFeed's non-blocking Python web server is now open source

bret.appspot.com

41–50 of 77 posts

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#41

What exactly does 'non-blocking' mean in the context of a webserver?

Non-blocking sockets. Calls to socket.read() can return no data. It's non-blocking because the program is not stuck waiting for data to be returned.

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#42
I've been looking for a good framework to begin serious web development on for someone coming from a decade-long career in desktop development (see the discussion at http://news.ycombinator.com/item?id=808191), and decided this release co-incides nicely with my newly-started quest and gave it a shot.

I realize Tornado isn't any different from the other Python frameworks with regards to coding style, etc. but the the fact that this framework comes complete with a web server means I don't have to worry about that part of the equation making developing Python-based webapps almost identical to developing a C++ library with one of the many HTML-based UI frontends :)

Having a great time playing around with it... almost done with a basic forum system built on Tornado + Storm (https://storm.canonical.com/).. I think I'm getting the hang of this whole web-development thing! :D

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#43
post #4

I could use this in apps today if it used twisted instead of reinventing it.

How many deployed web apps really use Twisted? There are like 3 web packages in Twisted, most of which are really buggy, and as far as I could tell, barely used (even they acknowledge this, see http://twistedmatrix.com/trac/wiki/WebDevelopmentWithTwisted ). When we were developing this, we found that Twisted introduced as many problems as it solved in terms of incomplete features and bugs. The other protocols seem to…

"How many deployed web apps really use Twisted?"

This is sort of the point. twisted isn't a web framework. It's a networking framework. I work on a lot of really awesome networking projects that either don't have web interfaces (various xmpp services) or have ones that need work (buildbot).

Instead of filling an obviously missing hole in an existing framework, a new one was created that is missing all of the stuff that the other project has.

The twisted http client stuff is quite good. I used it along with a friend to build a tool that is a realtime (in the web sense) gateway between friendfeed and xmpp clients a couple days after the realtime API was released (before friendfeed launched their own). It works very well and I still use it today.

Unfortunately, if I wanted to build a tool that did similar stuff with a Tornado front-end, I'd have to write a new HTTP client that's compatible with Tornado's event loop (unless I'm mistaken).

Everything comes at a cost. Tornado demonstrably solved Friendfeed's problems quite well, but, as I stated above, I can't use it to solve my problems because even if I rewrote my apps, I'd lose all of the rest of twisted upon which I'm relying. e.g. I can't just bolt it onto buildbot (which would be so ideal as our web interface is suffering from lack of a framwork, but the backend is really good).

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#44
post #23

I implemented the same idea in Ruby event machine: http://gist.github.com/184760 Obviously missing features (auth, nicks, scrolling) but that can all be added in a few mins.

how about turning this to a full framework? or is there one already?

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#45
It seems like blocking calls to data sources (the database, memcache, etc) would screw with a lot of the benefits of running the framework asynchronously. If your Tornado processes freeze while making synchronous backend requests, you're gonna need a lot of them, which probably kills a lot of the value.

Now all we need are async data clients that tie into the Tornado event loop, and a clean way to yield control back and forth (perhaps with coroutines - http://www.python.org/dev/peps/pep-0342/). Unfortunately, I don't think there are any async Python mysql clients (PHP has one now - http://www.scribd.com/doc/7588165/mysqlnd-Asynchronous-Queri...)

A web app written like that would run like it's on fire. The event loop would just roll through everything asynchronously. You could even automatically batch together data calls across http requests to make things easier on the data tier.

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#46
post #6

Is this similar to EventMachine in Ruby?

EM is a general-purpose library for nonblocking IO. Tornado is an HTTP server. In as much as they're both about nonblocking IO, they are similar.

Tornado has its own EventMachine-like equivalent as part of the stack they released. So you could use it to do TCP non-blocking IO if I grokked the code correctly.

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#47
The templating system they developed looks pretty sweet http://github.com/facebook/tornado/blob/master/tornado/templ....

Just played around with it a bit and it's basically what I want:

1) Simple and clear syntax (e.g. they use 'end' not endfor, endblock, etc)

2) Assign template variables to anything (including functions)

3) Don't over-restrict the author (e.g. they allow list comprehensions in if tags)

4) Block and extends statements.

Error handling seems to be a little clearer than other template languages though still not great:

http://gist.github.com/184934

Clearly it's not going to be for everyone but after slogging around with Mako for the last year ( tags anyone?) this is like a breath of fresh air.

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#48
post #22

Earlier quoted context omitted.

If you ran a single CherryPy instance, I don't see how that is possible. The Python global interpreter lock prevents a single process from making use of multiple cores.

No, it doesn't. I/O bound tasks can heavily use multiple cores just fine using threads.

If you're CPU bound in pure-python computations then the GIL (Global Interpreter Lock) will cause you to only make use of one core. This is intentional: threads are hard, processes are simple.

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#49
post #23

I implemented the same idea in Ruby event machine: http://gist.github.com/184760 Obviously missing features (auth, nicks, scrolling) but that can all be added in a few mins.

how about turning this to a full framework? or is there one already?

I'll brainstorm the idea. I have some ideas of how to turn this evented programming into a very natural flow using ruby 1.9.1's fibers.

Re: Tornado: FriendFeed's non-blocking Python web server is now open source

#50

It seems like blocking calls to data sources (the database, memcache, etc) would screw with a lot of the benefits of running the framework asynchronously. If your Tornado processes freeze while making synchronous backend requests, you're gonna need a lot of them, which probably kills a lot of the value. Now all we need are async data clients that tie into the Tornado event loop, and a clean way to yield control back…

The browser-webserver delay resulting from long polling is much larger the frontend-backend delay. I think there is at least an order of magnitude difference there, hence an order of magnitude reduction is the amount of idle state kept on the server.
Post reply on HN