7 ms·
Web Application Development with Tornado
- japherwocky 17y agoMuch love for tornado, though I ditched their templating for genshi. It also works pretty good as a Cron sort of engine for polling/scraping.
- enneff 17y ago> Because your tornado app runs as a stand-alone HTTP server that is directly coupled to your application classes, you need to run multiple processes to serve multiple requests. Really? My understanding is that an async http server like Tornado should service many requests with the same process. (This is the case with Twisted and nginx, at least.) It should be a matter of writing your application in the same async, callback-driven style. Or am I misunderstanding something?
- deleted 17y ago[deleted]
- frognibble 17y agoYour understanding is correct. Multiple requests can be active in a single instance of the Tornado server if the request handlers are written in an async style. The chat example included with the Tornado source demonstrates this feature.
- crad 17y agoIf your app is fully async, yes. Any blocking and you'll need another backend to service a simultaneous request.
- enneff 17y agoSo why are you even using Tornado if you fork a separate process for each simultaneous request? Doesn't that negate the benefits of an asynchronous http server?
- frognibble 17y agoBrett Taylor discusses this issue in his tech talk on Tornado (http://bret.appspot.com/entry/tornado-tech-talk http://bret.appspot.com/entry/tornado-tech-talk). He uses a hybrid approach: Use synchronous programming when requests block for a short time (fetching data from local db or memcache) and async programming when something blocks for a long time (calling out to third party services, long polling requests). He does not go all async because programming with callbacks or deferreds is more complicated than straight line synchronous programming. Brett also mentions that the instances of the server are created once and reused. He does not fork an instance of the server per request.
- enneff 17y agoTwisted has a nice asynchronous db api (http://twistedmatrix.com/documents/current/core/howto/rdbms.html http://twistedmatrix.com/documents/current/core/howto/rdbms....) that mitigates these concerns at the database level. More generally, I'd think the cleanest approach is to write async wrappers for your synchronous code, rather than forking an async server to service multiple requests. Otherwise you miss out on a lot of benefits of an async architecture, IMO.
- deleted 17y ago[deleted]
- z8000 17y ago"There are changes in the master branch of Tornado on github to make Tornado multi-threaded, spawning a thread per CPU core, but this will not change the scaling concern and will complicate the equation a bit more" Wrong. It forks. http://github.com/facebook/tornado/commit/6fb90ae694190fcedc48d9fb98b02325826d783e http://github.com/facebook/tornado/commit/6fb90ae694190fcedc...
- crad 17y agoMy bad.. I should have double checked my rusty memory of the commit.
- martythemaniak 17y agoA pretty good overview of Tornado. I've been using it as a backend for a real-time web game and from what I've seen so far, its pretty good. I especially like how small and light-weight it is (which kinda lets them get away with non-existent documentation)