Node.js群集-决定负载平衡的因素是什么? [英] Node.js Clustering - What determines load balancing?

查看:91
本文介绍了Node.js群集-决定负载平衡的因素是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经仔细阅读了这篇文章,并且还花了几个小时研究Node.js中的集群(派生过程)主题。

I have read over this article pretty thoroughly and as well have spent a few hours researching the subject of clustering (forking processes) in Node.js.

我从本文中似乎无法理解,它决定了哪个工作进程得到请求X,如果它们都在同一个端口上侦听?

What I can't seem to understand from the article, is what determines which worker process gets request X, if they are all listening on the same port?

主进程是否可以通过某种方式引导请求,还是只是随机的?

Is there a way for the master process to channel the requests, or is it just random?

推荐答案

有很好的解释此处。长话短说,根据您的节点版本,有两种不同的行为:

There a good explanation here. Long story short, there are 2 different behaviors depending on your node version:

node 0.8-0.10(在Windows上为0.12+):每个进程都在端口上侦听。操作系统决定建立新连接时唤醒哪一个。在某些操作系统下的某些应用程序中,这种方法不能很好地工作,并且使大多数进程处于连接状态;

node 0.8-0.10 (and 0.12+ on Windows): Each process listens on the port. The OS decides which one to wake up when a new connection comes in. In some applications under some OSs this doesn't work very well and leaves a few processes with a strong majority of the connections; in most it works just fine.

node 0.12+(在Windows上除外):主进程在端口上侦听。当它们进入时,它会以循环方式将它们交给工人。

node 0.12+ (except on Windows): The master process listens on the port. As they come in, it hands them off to workers in a round-robin fashion.

在这两种情况下,您的应用程序都应将其视为随机的(尽管您可以可能假设合理的负载平衡特性)。但是,如果您出于某种原因需要更好的控制,请在该文章中使用一个句子(请注意,该句子是由node.js核心贡献者编写的,因此这里有一些授权):

In either of these cases, your application should treat it as random (although you can probably assume reasonable load-balancing characteristics). However, if you for some reason need finer control, one sentence in that article (note that it was written by a node.js core contributor, so there's some authority here):

将选择算法转换为开发人员可配置或可插入的东西是正在考虑的更改。

Turning the selection algorithm into something that is configurable or pluggable by the developer is a change that is under consideration.

表示您可能会得到想要的东西。在Github上似乎存在与该选项有关的问题。

says that you might get what you're looking for. There appears to be an issue on Github pertaining to this option.

这篇关于Node.js群集-决定负载平衡的因素是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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