Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Emitted after the worker IPC channel has disconnected.
- This can occur when a worker exits gracefully, is killed, or is disconnected manually (such as with
- There may be a delay between the and events.
- These events can be used to detect if the process is stuck in a cleanup or if there are long-living connections.
- The exit code, if it exited normally.
- The name of the signal, that caused the process to be killed.
- When any of the workers die the cluster module will emit the event.
- This can be used to restart the worker by calling again.
- See
- When a new worker is forked the cluster module will emit a event.
- This can be used to log worker activity, and create a custom timeout.
- After calling from a worker, when the event is emitted on the server a event will also be emitted on in the master.
- The event handler is executed with two arguments, the contains the worker object and the object contains the following connection properties: and
- This is very useful if the worker is listening on more than one address.
- The is one of:
- Emitted when the cluster master receives a message from any worker.
- Before Node.js v6.0, this event emitted only the message and the handle, but not the worker object, contrary to what the documentation stated.
- If support for older versions is required but a worker object is not required, it is possible to work around the discrepancy by checking the number of arguments:
- After forking a new worker, the worker should respond with an online message.
- When the master receives an online message it will emit this event.
- The difference between and is that fork is emitted when the master forks a worker, and is emitted when the worker is running.
- Emitted every time is called.
- The object is the object at the time was called and is advisory only, since multiple calls to can be made in a single tick.
- If accuracy is important, use
- Called when all workers are disconnected and handles are closed.
- Calls on each worker in
- When they are disconnected all internal handles will be closed, allowing the master process to die gracefully if no other event is waiting.
- The method takes an optional callback argument which will be called when finished.
- This can only be called from the master process.
- Key/value pairs to add to worker process environment.
- Spawn a new worker process.
- This can only be called from the master process.
- True if the process is a master.
- This is determined by the
- If is undefined, then is
- True if the process is not a master (it is the negation of
- The scheduling policy, either for round-robin or to leave it to the operating system.
- This is a global setting and effectively frozen once either the first worker is spawned, or is called, whichever comes first.
- is the default on all operating systems except Windows.
- Windows will change to once libuv is able to effectively distribute IOCP handles without incurring a large performance hit.
- can also be set through the environment variable.
- Valid values are and
- List of string arguments passed to the Node.js executable.
- File path to worker file.
- String arguments passed to worker.
- Current working directory of the worker process.
- (inherits from parent process).
- Whether or not to send output to parent's stdio.
- Configures the stdio of forked processes.
- Because the cluster module relies on IPC to function, this configuration must contain an entry.
- When this option is provided, it overrides
- Sets the user identity of the process.
- Sets the group identity of the process.
- Sets inspector port of worker.
- This can be a number, or a function that takes no arguments and returns a number.
- By default each worker gets its own port, incremented from the master's
- Hide the forked processes console window that would normally be created on Windows systems.
- After calling or this settings object will contain the settings, including the default values.
- This object is not intended to be changed or set manually.
- is used to change the default 'fork' behavior
- Once called, the settings will be present in
- Note that:
- Any settings changes only affect future calls to and have no effect on workers that are already running.
- The only attribute of a worker that cannot be set via is the passed to
- The defaults above apply to the first call only, the defaults for later calls is the current value at the time of is called.
- This can only be called from the master process.
- A reference to the current worker object. Not available in the master process.
- A hash that stores the active worker objects, keyed by field. Makes it easy to loop through all the workers. It is only available in the master process.
- A worker is removed from after the worker has disconnected and exited.
- The order between these two events cannot be determined in advance.
- However, it is guaranteed that the removal from the list happens before last or event is emitted.
- Go through all workers
- Using the worker's unique id is the easiest way to locate the worker.
- The module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.
- The module exports two specific components:
- A class with methods such as and that can be used to write to any Node.js stream.
- A global instance configured to write to and
- The global can be used without calling
- Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams.
- See the note on process I/O for more information.
- Example using the global
- Prints
- Example using the class:
- The class can be used to create a simple logger with configurable output streams and can be accessed using either or (or their destructured counterparts):
- Ignore errors when writing to the underlying streams.
- Set color support for this instance.
- Setting to enables coloring while inspecting values, setting to will make color support depend on the value of the property and the value returned by on the respective stream.
- Creates a new with one or two writable stream instances.
- is a writable stream to print log or info output.
- is used for warning or error output.
- If is not provided, is used for
- custom simple logger
- use it like console
- The global is a special whose output is sent to
- and
- It is equivalent to calling:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement