具有多进程的 Python 龙卷风 [英] Python tornado with multi-process

查看:39
本文介绍了具有多进程的 Python 龙卷风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了如何使用多进程执行 tornado.

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.

tornado 是否会平衡每个进程的负载?

Does tornado balance the load itself for each process?

如果是这样,它是怎么做的?

If so, how does it do?

推荐答案

一般来说,当使用多进程模式时,进程只通过外部服务进行通信:数据库、缓存服务器、消息队列等.还有一些额外的选项可用对于在同一台机器上运行的进程(请参阅 multiprocessing 模块`),但一般来说,一旦您不再使用单个进程,最好寻找在您移动时会继续扩展的技术超越一台机器.

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.

在这种情况下,是内核而不是 Tornado 在进程间进行负载平衡.理论上,这是一种自我纠正机制,因为新连接只会提供给在连接到达时处于空闲状态的进程.然而,在实践中,这往往会导致严重的不平衡(负载最多的进程的连接数是负载最少的进程的 2-3 倍),因此专用负载平衡代理将导致更均匀的分布.

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.

这篇关于具有多进程的 Python 龙卷风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆