4 ms·
> 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 m
by 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]