This is more of a combination of a web <i>server</i> and a web <i>framework</i>, which is what I find fascinating about it. Twisted has had a web server forever, but despite a significant amount of experience in Twisted Land, I'd never write a full app using it! Add to that the (apparently) standalone low-level modules and we've got some seriously awesome tech that FriendFeed/Facebook have supplied for free.<p>Thanks a lot, fellas. Asynchronous networking programming in Python is somewhat of a bear so it's really nice to see a tool get released that improves it!
An instance of the chat demo is running here: <a href="http://chan.friendfeed.com:8888/" rel="nofollow">http://chan.friendfeed.com:8888/</a><p>Website: <a href="http://www.tornadoweb.org/" rel="nofollow">http://www.tornadoweb.org/</a><p>Source: <a href="http://github.com/facebook/tornado/tree/master" rel="nofollow">http://github.com/facebook/tornado/tree/master</a>
Awesome to see more Python webservers coming to light, and fast ones at that. One observation though; anyone else notice that the bar chart is a bit misleading? It compares running Tornado in 4 processes behind nginx to running Django behind Apache and Cherrypy as a single Python process. As a fellow coworker put it, "With 4 extra processes running of course it will be 4 times as fast." I'm not opposed to this kind of comparison when the intent is to show how configurations can increase req/sec, but if the intent is to compare one Pythonic webserver to another, this comparison seems a bit unfair. That said, assuming the "Tornado (1 single-threaded frontend)" measure is simply Tornado running as a single Python process, it still is plenty faster than Cherrypy.
The templating system they developed looks pretty sweet <a href="http://github.com/facebook/tornado/blob/master/tornado/template.py" rel="nofollow">http://github.com/facebook/tornado/blob/master/tornado/templ...</a>.<p>Just played around with it a bit and it's basically what I want:<p>1) Simple and clear syntax (e.g. they use 'end' not endfor, endblock, etc)<p>2) Assign template variables to anything (including functions)<p>3) Don't over-restrict the author (e.g. they allow list comprehensions in if tags)<p>4) Block and extends statements.<p>Error handling seems to be a little clearer than other template languages though still not great:<p><a href="http://gist.github.com/184934" rel="nofollow">http://gist.github.com/184934</a><p>Clearly it's not going to be for everyone but after slogging around with Mako for the last year (<%namespace:def /> tags anyone?) this is like a breath of fresh air.
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.<p>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 - <a href="http://www.python.org/dev/peps/pep-0342/" rel="nofollow">http://www.python.org/dev/peps/pep-0342/</a>). Unfortunately, I don't think there are any async Python mysql clients (PHP has one now - <a href="http://www.scribd.com/doc/7588165/mysqlnd-Asynchronous-Queries-and-more" rel="nofollow">http://www.scribd.com/doc/7588165/mysqlnd-Asynchronous-Queri...</a>)<p>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.
Who wants a (unofficial for now) Fedora rpm ? [0]
I just hacked this together in half an hour. Time to sleep now.<p>[0] <a href="http://mapleoin.fedorapeople.org/pkgs/tornado/tornado-0.1-1.fc11.noarch.rpm" rel="nofollow">http://mapleoin.fedorapeople.org/pkgs/tornado/tornado-0.1-1....</a>
Definitely rough around the edges, but looks like a great foundation.<p>A few notes:
- template.py: "Error-reporting is currently... uh, interesting."
- url mapping looks primitive
- no form helpers
- database.py looks decent, but is mysql only
- Very nice to see the security considerations in signed cookies, auth, csrf protection.<p>Overall, it looks like they've done the trickier parts of building a web framework and left it to the user/community to add the parts web developers use most frequently (form & url helpers, code organization, and orm).<p>I love Facebook's enlightened approach to open source. If only one of their open source projects takes off, it will benefit them tremendously.
I implemented the same idea in Ruby event machine: <a href="http://gist.github.com/184760" rel="nofollow">http://gist.github.com/184760</a><p>Obviously missing features (auth, nicks, scrolling) but that can all be added in a few mins.
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 <a href="http://news.ycombinator.com/item?id=808191" rel="nofollow">http://news.ycombinator.com/item?id=808191</a>), and decided this release co-incides nicely with my newly-started quest and gave it a shot.<p>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 :)<p>Having a great time playing around with it... almost done with a basic forum system built on Tornado + Storm (<a href="https://storm.canonical.com/" rel="nofollow">https://storm.canonical.com/</a>).. I think I'm getting the hang of this whole web-development thing! :D
This looks great. I'm likely to look at it a little more in the future. I've been using Second Life's asyncrounous coroutine library called eventlet. I've implemented most of my code with a good lightweight framework that fits; restish. On top of that, I use spawning to manage my server processes. I myself have seen these kinds of numbers with my own app tests.
This is great for python, a proven web framework that was stressed on friend feed. Thanks ff team! I have been torn on my next python server project between web2py, cherrypy and django and I think I just decided.
What would be the advantage of using this over, say, lighttpd with one of the many existing python frameworks?<p>Does this web server offer any specific gains? Or is it just a question of personal taste?