Tornado Web server multi process startup 2 methods

  • 2020-04-02 13:55:56
  • OfStack

Introduction to Tornado

Tornado is an open source version of FriendFeed's Web server and its popular tools. Tornado has a clear difference from today's mainstream Web server frameworks (including most Python frameworks) : it's a non-blocking server, and it's pretty fast. With its non-blocking approach and use of epoll, Tornado can handle thousands of connections per second, making Tornado an ideal framework for real-time Web services.

Two, multi - process startup method

Normal startup method:


server = HTTPServer(app)
server.listen(8888)
IOLoop.instance().start()

Multi-process, plan 1:


server = HTTPServer(app)
server.bind(8888)
server.start(0)  # Forks multiple sub-processes
IOLoop.instance().start()

Multi-process, plan 2:


sockets = tornado.netutil.bind_sockets(8888)
tornado.process.fork_processes(0)
server = HTTPServer(app)
server.add_sockets(sockets)
IOLoop.instance().start()


Related articles: