3

Tornado is non-blocking webserver.

However, all of the operations are run in a single thread. How does it stay non-blocking if it is handled by single thread?

If there is a long operation, will it block new coming request?

Is downloading a large file from Tornado a long blocking process?

Please kindly correct me if my understanding is not accurate.

Many Thanks

Snakes and Coffee
  • 8,747
  • 4
  • 40
  • 60
MobileDev
  • 178
  • 3
  • 14

1 Answers1

2

If there is a long operation, will it block new coming request?

Yes. No. It depends.

Anything which happens inside Tornado itself blocks. So if you do "time.sleep(10)" or do a computationally intensive operation, it will block.

What Tornado (and Twisted, and node.js) can do well is request data from another service (like Amazon, or Facebook, or a subprocess, or a database with an async library) then serve other requests while it's waiting for a reply. See http://www.tornadoweb.org/documentation/overview.html#non-blocking-asynchronous-requests

To do this, you need the server in front to be async too (so Nginx, not Apache).

wisty
  • 6,981
  • 1
  • 30
  • 29
  • Many Thanks, it means it is not naively non-blocking even the operation is not sharing the same source of object/content. Am I right? – MobileDev Aug 21 '12 at 08:13
  • I'm not 100% sure what you are saying, but it will block if you naively put an "async" wrapper over synchronous code. The main advantage of Tornado's async is you don't have to block while waiting for IO. You do block if Tornado has has a lot of processing to do. – wisty Aug 21 '12 at 09:41