tornado as a daemon

165 views
Skip to first unread message

mbutubuntu

unread,
Dec 7, 2010, 11:42:07 AM12/7/10
to python-...@googlegroups.com
Hello folks, reading httpserver.py I've found @line 133 self.start(1),
modifying the argument (i.e. self.start(10)) I've seen that python runs
10+1 processes (this argument seems the same parameter to set up
workers/threads on Apache), is using this trick (about) the same of
running different tornado processes on different ports? (obviously I'm
running 10 processes on the same port) it could be the same of a
"load-balancing" ?

Best Regards

Fabio Buda
Web Developer/Designer @ netdesign
+39 338 9423302
fabi...@netd.it
http://www.netd.it/

Phil Plante

unread,
Dec 7, 2010, 1:25:48 PM12/7/10
to Tornado Web Server
That value controls how many child forks to spawn. The parent process
remains around and binds to whichever port you specified, handing off
processing of the requests to its children.

Ideally you should create N tornado processes, N being number of CPU
cores you have, and serve them via a nginx frontend server. This is
ideal because you can offload static file requests to nginx. Also it
adds protection should one of the processes die, the remaining can
still serve http requests. The pre-forking method cannot guarantee
this level of safety alone.
> fabiob...@netd.ithttp://www.netd.it/

soupy

unread,
Dec 7, 2010, 4:08:14 PM12/7/10
to Tornado Web Server
I am curious about this as well actually, is there a benefit to
running 4 tornado instances on different ports behind nginx vs simply
calling start(4) and spawning 4 child processes on the same port
behind nginx? I realize that this would essentially move the load
balancing to the tornado parent process instead of nginx but has
anyone done testing to determine which method produces better output?
Are there any additional factors to consider in this decision?

Arek Bochinski

unread,
Dec 7, 2010, 4:09:04 PM12/7/10
to python-...@googlegroups.com
As Phil mentioned, it's ideal to start multiple tornado processes rather than spawning
more children via Tornado.

I personally found Supervisor to be excellent for managing daemon style processes.
I couldn't recommend it enough.

Cliff Wells

unread,
Dec 7, 2010, 4:50:44 PM12/7/10
to python-...@googlegroups.com
On Tue, 2010-12-07 at 13:08 -0800, soupy wrote:
> I am curious about this as well actually, is there a benefit to
> running 4 tornado instances on different ports behind nginx vs simply
> calling start(4) and spawning 4 child processes on the same port
> behind nginx? I realize that this would essentially move the load
> balancing to the tornado parent process instead of nginx but has
> anyone done testing to determine which method produces better output?
> Are there any additional factors to consider in this decision?

If you need to restart a Tornado process (whether due to code changes,
hung process, or whatever), then having them all as discrete processes
makes this simpler and reduces the possibility of downtime (Nginx will
simply move on to the next backend if one is down). By contrast, if an
internal Tornado process needs to be restarted, you must restart all of
them at the same time.

For instance, I have a simple shell script that tells supervisor to
restart my instances in reverse order (in order to avoid racing with
Nginx's failover procedure), so I effectively get zero downtime even
with a full restart of my application.

Regards,
Cliff

--
Cliff Wells <cl...@develix.com>

Ben Darnell

unread,
Dec 7, 2010, 5:53:53 PM12/7/10
to python-...@googlegroups.com
In addition, child processes can fail in ways that are difficult to
detect from the outside (interpreter crashes, deadlocks, infinite
loops), so you could be running at reduced capacity without even
realizing that you need to restart the whole process group.

-Ben

Didip Kerabat

unread,
Dec 7, 2010, 6:18:04 PM12/7/10
to python-...@googlegroups.com
Also, running multiple tornado processes (with their own pid files) is monit friendly.

I'm not sure what would be the reliable way on monitoring children forks.

- Didip -

mbutubuntu

unread,
Dec 8, 2010, 8:02:02 AM12/8/10
to python-...@googlegroups.com
ok, so the better solution is many tornado instances on different ports
using nginx as a front-end/load-balancer, does someone tested pound as a
load balancer? (http://www.apsis.ch/pound/).

Best Regards,

Fabio Buda

mbutubuntu

unread,
Dec 7, 2010, 3:00:56 PM12/7/10
to python-...@googlegroups.com
I don't need any static file to be served by tornado so do you think I
should use nginx alike?

thanks

Cliff Wells

unread,
Dec 8, 2010, 2:31:55 PM12/8/10
to python-...@googlegroups.com
On Wed, 2010-12-08 at 14:02 +0100, mbutubuntu wrote:
> ok, so the better solution is many tornado instances on different ports
> using nginx as a front-end/load-balancer, does someone tested pound as a
> load balancer? (http://www.apsis.ch/pound/).

Yes, I switched from Pound to Nginx about 5 years ago. Pound suffers
from the same problems as Apache: it is threaded and when the amount of
concurrency gets high it consumes massive amounts of RAM and then dies.

Pound is okay for smaller sites, but it's not really easier to setup
than Nginx and it has a smaller community, so I have never seen any
advantage to it.

David Birdsong

unread,
Dec 8, 2010, 2:49:08 PM12/8/10
to python-...@googlegroups.com
On Tue, Dec 7, 2010 at 3:00 PM, mbutubuntu <mbutu...@yahoo.it> wrote:
> I don't need any static file to be served by tornado so do you think I
> should use nginx alike?
>
if you dont need any static file serving, than you could also use
haproxy. haproxy has health checks which allows you to do neat things
with health handlers in your tornado app to make restarts seamless.
Reply all
Reply to author
Forward
0 new messages