summaryrefslogtreecommitdiff
path: root/lib/cluster.js
AgeCommit message (Collapse)Author
2014-07-28cluster: enable error/message events using .workercjihrig
Between 0.11.1 and 0.11.2, the message and error events stopped being usable via the cluster.worker object. This commit makes them usable again. Closes #7998. Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-15cluster: include settings object in 'setup' eventRyan Graham
Emits on every call to cluster.setupMaster(), even if no new settings are given. This is because calling cluster.setupMaster() without arguments (or with an empty options object) results in the settings being restored to their defaults. Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-15cluster: allow multiple calls to setupMaster()Ryan Graham
Only attributes of 'cluster.settings' will be modified after the first call, leaving all other cluster initialization alone. Each call that includes a 'settings' argument triggers a 'setup' event to be emitted. Instead of each call resetting all values to their defaults, use the current settings (if any) as the default. This retains setupMaster's support how cluster.fork() uses setupMaster() to ensure cluster.settings has been populated. Update example in docs to use current node coding style and include an example of progressive configuration. Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-02child_process: accept uid/gid everywhereFedor Indutny
Accept uid/gid option in every execute/spawn call (including cluster.fork). Add documentation where needed. fix #7881 Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-06-11cluster: restore v0.10.x setupMaster() behaviourRyan Graham
In v0.10.x, process.argv and process.execArgv would only be evaluated and copied into cluster.settings on the first call to cluster.setupMaster() (either directly or via cluster.fork()), allowing them to be modified as needed before initializing the settings. In 41b75ca the behaviour was changed so that these values are initialized at the time of the first require('cluster'). Fixes #7670. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2013-12-31cluster: do not synchronously emit 'setup' eventSam Roberts
This is a problem present in both v0.10, and v0.11, where the 'setup' event is synchronously emitted by `cluster.setupMaster()`, a mostly harmless anti-pattern.
2013-12-31cluster: only forcibly exit worker on unclean exitSam Roberts
Fix inadvertent v0.11 changes to the definition of suicide, particularly the relationship between suicide state, the disconnect event, and when exit should occur. In v0.10, workers don't forcibly exit on disconnect, it doesn't give them time to do a graceful finish of open client connections, they exit under normal node rules - when there is nothing left to do. But on unexpected disconnect they do exit so the workers aren't left around after the master. Note that a test as-written was invalid, it failed against the v0.10 cluster API, demonstrating that it was an undocumented API change.
2013-12-31cluster: disconnect callback should always occurSam Roberts
Fixes issue in 0.11 where callback doesn't occur if worker count is currently zero. In 0.10 callback occurs after worker count is zero, and occurs in next tick if worker count is currently zero.
2013-12-31cluster: replace erroneous comma with semicolonSam Roberts
2013-10-14cluster: fix premature 'disconnect' eventBen Noordhuis
Don't emit the 'disconnect' event until all workers have gone away. Before this commit, the event was emitted when all open handles were closed, which usually - but not always - amounts to the same thing. Fixes #6346.
2013-08-15cluster: variable is not globalBrian White
2013-08-01src: Replace macros with util functionsisaacs
2013-07-28cluster: fix shared handle bind error propagationBen Noordhuis
A failed bind() was already being correctly reported in round-robin mode. This commit fixes bind() error reporting in shared handle mode. Fixes #5774.
2013-07-28cluster: remove duplicate this.errno assignmentBen Noordhuis
2013-07-25cluster: support setting data on shared serverFedor Indutny
If `obj` given to `cluster._getServer` has `_setServerData` or `_getServerData` methods, the data will be synchronized across workers and stored in master.
2013-07-24lib: macro-ify type checksBen Noordhuis
Increases the grep factor. Makes it easier to harmonize type checks across the code base.
2013-07-20src, lib: update after internal api changeBen Noordhuis
Libuv now returns errors directly. Make everything in src/ and lib/ follow suit. The changes to lib/ are not strictly necessary but they remove the need for the abominations that are process._errno and node::SetErrno().
2013-05-13cluster: use round-robin load balancingBen Noordhuis
Empirical evidence suggests that OS-level load balancing (that is, having multiple processes listen on a socket and have the operating system wake up one when a connection comes in) produces skewed load distributions on Linux, Solaris and possibly other operating systems. The observed behavior is that a fraction of the listening processes receive the majority of the connections. From the perspective of the operating system, that somewhat makes sense: a task switch is expensive, to be avoided whenever possible. That's why the operating system likes to give preferential treatment to a few processes, because it reduces the number of switches. However, that rather subverts the purpose of the cluster module, which is to distribute the load as evenly as possible. That's why this commit adds (and defaults to) round-robin support, meaning that the master process accepts connections and distributes them to the workers in a round-robin fashion, effectively bypassing the operating system. Round-robin is currently disabled on Windows due to how IOCP is wired up. It works and you can select it manually but it probably results in a heavy performance hit. Fixes #4435.
2013-05-08debugger, cluster: each worker has new debug portMiroslav Bajtoš
Implement support for debugging cluster workers. Each worker process is assigned a new debug port in an increasing sequence. I.e. when master process uses port 5858, then worker 1 uses port 5859, worker 2 uses port 5860, and so on. Introduce new command-line parameter '--debug-port=' which sets debug_port but does not start debugger. This option works for all node processes, it is not specific to cluster workers. Fixes joyent/node#5318.
2013-04-20cluster: clean up lib/cluster.jsBen Noordhuis
Clean up and DRY the cluster source code. Fix a few bugs while we're here: * Short-lived handles in long-lived worker processes were never reclaimed, resulting in resource leaks. * Handles in the master process are now closed when the last worker that holds a reference to them quits. Previously, they were only closed at cluster shutdown. * The cluster object no longer exposes functions/properties that are only valid in the 'other' process, e.g. cluster.fork() is no longer exported in worker processes. So much goodness and still manages to reduce the line count from 590 to 320.
2013-04-11lintisaacs
2013-04-11cluster: fix O(n*m) scan of cmd stringBen Noordhuis
Don't scan the whole string for a "NODE_CLUSTER_" substring, just check that the string starts with the expected prefix. The linear scan was causing a noticeable (but unsurprising) slowdown on messages with a large .cmd string property.
2013-03-03cluster: Rename destroy() to kill(signal=SIGTERM)isaacs
Fix #4133, bringing the cluster worker API more in line with the child process API.
2013-01-28cluster: support datagram socketsBert Belder
2013-01-18cluster: make --prof work for workersBen Noordhuis
Profiling in clustered environments doesn't work out of the box. By default, V8 writes the profile data of all processes to a single v8.log. Running that log file through a tick processor produces bogus numbers because many events won't match up with the recorded memory mappings and you end up with graphs where 80+% of ticks is unaccounted for. Fixing the tick processor to deal with multi-process output is not very useful because the processes may be running wildly disparate workloads. That's why we fix up the command line arguments to include a "--logfile=v8-%p.log" argument (where %p is expanded to the PID) unless it already contains a --logfile argument. Fixes #4617.
2012-10-09cluster: make 'listening' handler see actual portAaditya Bhatia
Make the 'listening' event handler in the master process see the actual port that the worker bound to when the worker specified port 0, i.e. a random port.
2012-08-06net: fix listen() regression, revert patchesBen Noordhuis
This commit reverts the following commits (in reverse chronological order): 74d076c errnoException must be done immediately ddb02b9 net: support Server.listen(Pipe) 085a098 cluster: do not use internal server API d138875 net: lazy listen on handler Commit d138875 introduced a backwards incompatible change that broke the simple/test-net-socket-timeout and simple/test-net-lazy-listen tests - it defers listening on the target port until the `net.Server` instance has at least one 'connection' event listener. The other patches had to be reverted in order to revert d138875. Fixes #3832.
2012-08-05cluster: do not use internal server APIAndreas Madsen
2012-07-06Avoid redeclaring variableJonas Westerlund
Capitalize the constructor to avoid redeclaration. Fixes strict mode error.
2012-06-15domain: the EventEmitter constructor is now always called in nodecoreAndreas Madsen
2012-06-14cluster: rename worker.unqiueID to worker.idAndreas Madsen
2012-06-13Fix #3388 Support listening on file descriptorsisaacs
This implements server.listen({ fd: <filedescriptor> }). The fd should refer to an underlying resource that is already bound and listening, and causes the new server to also accept connections on it. Not supported on Windows. Raises ENOTSUP.
2012-05-21cluster: remove NODE_UNIQUE_ID from env on startupAndreas Madsen
In case a worker would spawn a new subprocess with process.env, NODE_UNIQUE_ID would have been a part of the env. Making the new subprocess believe it is a worker, this would result in some confusion if the subprocess where to listen to a port, since the server handle request would then be relayed to the worker. This patch removes the NODE_UNIQUE_ID flag from process.env on startup so any subprocess spawned by a worker is a normal process with no cluster stuff.
2012-05-05More cluster event consistencyisaacs
Regarding discussion in #3198. Passing the worker as an argument to an event emitted on the worker is redundant, and an unnecessary break in consistency vs the events on the ChildProcess objects. It was removed from 'exit', but 'listening' and others were overlooked. This corrects that oversight.
2012-05-04cluster: worker exit event to match child_processJ. Lee Coltrane
test: fixes due to new cluster api. - changed worker `death` to `exit`. - corrected argument type expected by worker `exit` handler. test: more tests of cluster.worker death cluster: fixed arguments on worker 'exit' event worker 'exit' event now emits arguments consistent with the corresponding event in child_process module.
2012-04-06docs: grammar and spelling on lib/cluster.jsZachary Scott
2012-03-30cluster: Rename 'death' back to 'exit'isaacs
2012-03-19cluster: English language fixingisaacs
2012-03-19cluster: kill workers when master diesAndreas Madsen
This patch will kill the worker once it has lost its connection with the parent. However if the worker are doing a suicide, other measures will be used.
2012-03-19cluster: add graceful disconnect supportAndreas Madsen
This patch add a worker.disconnect() method there will stop the worker from accepting new connections and then stop the IPC. This allow the worker to die graceful. When the IPC has been disconnected a 'disconnect' event will emit. The patch also add a cluster.disconnect() method, this will call worker.disconnect() on all connected workers. When the workers are disconneted it will then close all server handlers. This allow the cluster itself to self terminate in a graceful way.
2012-03-15Expose original argv as process.execArgv for cluster and child_process.fork()Micheil Smith
2012-02-20util: add `util._extend` for extending objectsMaciej Małecki
There were 2 duplicates with such functionality in `cluster` and `child_process` modules which were replaced by this function.
2012-02-18Lint all the JavaScripts.isaacs
2012-02-06cluster: use process.disconnect methodAndreas Madsen
After adding a .disconect method and connected flag in child_process we should no longer use the process._channel object.
2012-02-06cluster: simplify process event handlingAndreas Madsen
This simplify the internalMessage and exit event handling And simply relay message and error event to the worker object Note that the error event was not relayed before
2012-01-20Add cluster.setupMasterAndreas Madsen
Fixes #2470
2012-01-11child_process: fix typo in internal message event nameAndreas Madsen
2012-01-05typosAndreas Madsen
fixes #2465
2012-01-04cluster improvements: Worker class and isolate internal messagesAndreas Madsen
Fixes #2388
2011-12-19Remove debug console.log and optimize object copyAndreas Madsen
Fixes #2380