10

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.

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?

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Don't know about 0.12 but I think it is RR in 0.11.2. Here is the relevant commit
@user568109 Interesting. It looks like "new in v0.12", the article means that's the first major version its in, which only includes even numbers? Updated to something closer to the language of the article (only referencing major versions 0.8, 0.10, and 0.12).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.