Node.js Clustering - What determines load balancing?

允我心安 提交于 2019-12-05 06:30:58

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

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+ (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.

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.

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

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