I found how to execute tornado with multi-process.
server = HTTPServer(app)
server.bind(8888)
server.start(0) #Forks multiple sub-processes
IOLoop.current().start()
In this situation is there any way to share resource over processes?
and It seems using the same port over processes.
Does tornado balance the load itself for each process?
If so, how does it do?
In general, when using multi-process mode the processes only communicate via external services: databases, cache servers, message queues, etc. There are some additional options available for processes that are running on the same machine (see the multiprocessing
module`), but in general once you are no longer using a single process it's better to look to techniques that will continue to scale when you move beyond a single machine.
In this scenario, it is the kernel and not Tornado that does the load balancing across the processes. In theory, this is a self-correcting mechanism because the new connection will only be given to a process that is idle at the time the connection arrives. However, in practice this tends to result in significant imbalances (the most loaded process has 2-3x as many connections as the least loaded), so a dedicated load balancing proxy will result in a more even distribution.
来源:https://stackoverflow.com/questions/33371682/python-tornado-with-multi-process