Python tornado with multi-process

人盡茶涼 提交于 2019-12-06 11:26:07

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!