How to run multiple instances of Tornado Server on multiple ports

I need to run the blog demo in the following ports:

127.0.0.1:8000 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003

When I start my application using:

./demki/blog/blog.py

it runs on port 8888 as defined:

define ("port", default = 8888, help = "run on the given port", type = int)

How do I run multiple instances on multiple ports?

+2


source to share


5 answers


I found what I was looking for:



./demos/blog/blog.py --port=8889

      

+4


source


Make sure you know the -port option is parsed by the Tornado Infrastructure Options Module.

Lines that look like this:

define("port", default=8888, help="Port to listen on", type=int)

      



and then calling the options module, which automatically parses the command line switches.

I'm just giving it to you because you might want to later specify different variables in your programs that you create around the framework that you can change for the instance instance.

+3


source


Use supervisord to run multiple instances. Since every application takes an argument --port=

, you can set something like this:

Here's the setting I'm using for Around The World

[group:aroundtheworld]
programs=aroundtheworld-10001,aroundtheworld-10002,aroundtheworld-10003

[program:aroundtheworld-10001]
command=/var/lib/tornado/aroundtheworld/app.py --port=10001
directory=/var/lib/tornado/aroundtheworld/
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado/aroundtheworld-10001.log
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn

[program:aroundtheworld-10002]
command=/var/lib/tornado/aroundtheworld/app.py --port=10002
directory=/var/lib/tornado/aroundtheworld/
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado/aroundtheworld-10002.log
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn

[program:aroundtheworld-10003]
command=/var/lib/tornado/aroundtheworld/app.py --port=10003
directory=/var/lib/tornado/aroundtheworld/
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado/aroundtheworld-10003.log
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn

      

If you need help on how to configure Nginx or something similar to load balancing them, please post a new question.

+2


source


you can register multiple ports when creating a handler

application = tornado.web.Application([
   (r".*", MainHandler),
], **app_settings)

application.listen(8080)
application.listen(8081)

      

+1


source


copy /demos/blog/blog.py to blog_otherports.py

      

change messages in blog_otherports.py

and python blog_otherports.py

you need to start two processes

-4


source







All Articles