tornado not multithreaded?

2,787 views
Skip to first unread message

Andreas

unread,
Dec 15, 2011, 6:49:27 PM12/15/11
to Tornado Web Server
hi,

i dont know if im doing something wrong or if it is too late right now and im not connecting right any more.

what i have is a tornado app that recieves a json post where it gets a downloadlink of an image or a video which gets processed by a function. what i noticed is that it seems to do the work in serial instead of parallel. which means that if a video takes 10min to encode nothing all other requests wait until this is done.

in prod production i start 4 tornado instances behind nginx but it behaves the same way as on my local machine.

the code is pretty simple:

def post(self):
data = simplejson.loads(self.request.body)
self.process_blob(data)
self.set_status(200)


maybe im doing something wrong.

thx

Peter Bengtsson

unread,
Dec 15, 2011, 7:23:03 PM12/15/11
to python-...@googlegroups.com
"multithreaded" isn't the word you're probably looking for. Maybe you mean "asynchronous" as opposed to "synchronous". Strangely, Tornado is both. Django is only synchronous and Node, for example, is only asynchronous.

However, Tornado makes it possible to pass on the attention whilst doing nothing, which is what happens when it has to sit and wait idly. For example, to wait for an server to respond.

What you need is a proper parallel job handler. Aka. a message queue. These are easy to set up with Celery which is unrelated to Tornado. You can look at https://github.com/peterbe/toocool for source code examples that use Celery. However, that code doesn't use a result store so you'll have to do a bit more work. That code only uses Celery to fire-and-forget.

Ben Darnell

unread,
Dec 16, 2011, 1:31:31 AM12/16/11
to python-...@googlegroups.com
Tornado does not use multiple threads; its main source of concurrency
is by making long-running operations asynchronous. You can create
additional threads if you want and pass messages between them,
although the python GIL means that threading is often not worth its
cost in complexity. For cpu-intensive tasks such as encoding video,
you almost certainly want to do the work in a separate process. There
are a number of ways to do this, including the multiprocessing and
subprocess modules in the standard library, or communicating with an
external system via message queues or HTTP.

-Ben

Gaurav Sehrawat

unread,
Oct 9, 2014, 2:01:52 AM10/9/14
to python-...@googlegroups.com, b...@bendarnell.com
I know this  is very late but those who searching on Google . 

Phyo Arkar

unread,
Oct 14, 2014, 3:20:26 PM10/14/14
to python-...@googlegroups.com, b...@bendarnell.com
Why need for Multi-Thread when Non-Blocking Evented can scale a lot better?
No Memory increased for each connection added is big win for Evented
systems. Tornado can scale > 10k connections easily ,when
multi-threaded just can't.
> --
> You received this message because you are subscribed to the Google Groups
> "Tornado Web Server" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python-tornad...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
Reply all
Reply to author
Forward
0 new messages