Re: [tornado] Why do multiprocess in tornado be useless?

60 views
Skip to first unread message

Ben Darnell

unread,
Nov 1, 2012, 1:21:15 PM11/1/12
to Tornado Mailing List
This doesn't mean that multiprocessing isn't working - sometimes the kernel prefers to wake up a process that's been busy recently instead of trying to spread the load evenly.  Try adding a call to time.sleep() in the handler, and then making several requests at once - you should see that they go to different processes.


On Thu, Nov 1, 2012 at 6:05 AM, Yarkee <iya...@gmail.com> wrote:
The code is very simple.I start with 5 processes of http_server.
Everytime I visit the url, what the handler do is to print the pid of current process.
However, everytime I visit the url, the result of "print os.getpid()" is as the same. It means that, the same process is always be used to handler all of my requests.
So how can I use multiprocess in tornado.(What do I mean is not a nginx frontend.)
Looking forward your answer. Thanks.

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        print os.getpid()
        self.write("Hello, world")

def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([
        (r"/", MainHandler),
    ])
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.bind(options.port)
    http_server.start(5)
    tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
    main()

Reply all
Reply to author
Forward
0 new messages