Node.js Clustering - What determines load balancing?

I read this article quite carefully, and also spent several hours exploring the topic of clustering (branching processes) in Node.js.

What I cannot understand from the article determines which workflow receives an X request if they all listen on the same port?

Is there a way the master process can send requests, or is it just random?

+6
source share
1 answer

There is a good explanation here . In short, there are 2 different behaviors in your version of node:

node 0.8-0.10 (and 0.12+ on Windows): each process listens on a port. The OS decides which one to wake up when a new connection arrives. In some applications under some operating systems, this does not work very well and leaves several processes with a strong majority of connections; in most it works just fine.

node 0.12+ (except Windows): The main process is listening on the port. When they enter, he passes them on in a working circular fashion.

In any of these cases, your application should consider it as random (although you can probably assume reasonable load balancing characteristics). However, if for some reason you need finer control, one suggestion in this article (note that it was written by the main contributor to node.js, so there are some permissions here):

Turning a selection algorithm into something that is configured or connected by the developer is the change that is being considered.

says you can get what you are looking for. There seems to be a problem on Github related to this option.

+3
source

Source: https://habr.com/ru/post/958751/


All Articles