On Sat, Jan 19, 2013 at 7:54 PM, thewilli <[email protected]> wrote: > Hi! > > The node documentation of the cluster module says about incoming server > connections: > >> When multiple processes are all accept()ing on the same underlying >> resource, the operating system load-balances across them very efficiently. >> There is no routing logic in Node.js, or in your program, and no shared >> state between the workers. > > > I want to understand what node does when a new incoming connection is > established and two or more worker are "listening". > > As far as I understand what happens after listen(port) is called on a > workers server instance is, that the master is queried ("queryServer > internal message") about the given parameters like port and type, and that > the server returns an "fd handler" (in cluster.js, > messageHandler.queryServer). This handle is either retrieved or newly > created. So what is that handle about? It is created in the > _createServerHandle method in the net module, which creates a new instance > of process.binding('tcp_wrap').TCP defined in tcp_wrap.cc in case of a > TCP-based server. > > But where does that "acception" that is mentioned in the documentation take > place? Is there any (easy) way to create a custom way of distribution of new > connections to all listening workers? > > Thanks in advance!
It works like this: 1. The master creates the listen socket (wrapped by a handle object) and sends it to the workers. 2. The workers tell the operating system: "Start watching this socket for new connections." 3. When a new connection comes in, the operating system notifies one of the workers. 4. The notified worker accepts (opens) the connection and starts reading/writing. The idea is that the operating system knows best what process to notify (the one that is least loaded) but that has turned out to be of debatable effectiveness. Some workloads trigger a Linux scheduler quirk where most connections end up in just 2 or 3 workers. We'll be revising the current approach some day but the details remain TBD and there is also the issue of man power. -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
