Open wenxiaodong opened 8 years ago
https://groups.google.com/forum/#!topic/python-tornado/JNtWjFcVb7s
app = tornado.web.Application()
http_server = tornado.httpserver.HTTPServer(app)
http_server.bind(port)
http_server.start(4)
chat_routes = sockjs.tornado.SockJSRouter(connection.handler, '/im')
app.add_handlers(".*",
[(r"/im/search", handlers.search_handler)] +
[(r"/favicon.ico", handlers.favicon_handler)] +
[(r"/test", handlers.TestHandler)] +
chat_routes.urls)
Works, but take note of:
This won't work: SockJS protocol requires sticky sessions - client should come back to same instance of the SockJS server. With pre-forking requests will be distributed in round-robin fashion.
Advised approach:
- Spawn multiple sockjs-tornado processes, each listening on separate port
- Use haproxy to load-balance requests. Sample config: https://github.com/sockjs/sockjs-node/blob/master/examples/haproxy.cfg
Serge.
RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start_processes()
Can't use multiple processes?