Difference between cluster and child_process modules?

devquora
devquora

Posted On: Feb 22, 2018

 

    1 Answer Written

  •  devquora
    Answered by Satyam

    Difference between Cluster and child process modules in NodeJS

    Cluster: Cluster is a module of Node.js that contains sets of functions and properties that helps the developers for forking processes through which they can take advantage of the multi-core system. This is the first level of scalability and its care must be taken in the node application, especially if the work is going on in the HTTP server application, it is important before moving up to the higher scalability level. Any number of child/worker processes can be forked with the help of the cluster module. Also with its help, communication can be made by sending messages via IPC communication. A point to remember is that there is no shared memory among these processes.

    With the cluster module, the creation and sharing of child processes and several parts become easy. In a single thread, the individual instance of node.js runs specifically and to take advantage of various ecosystems, a cluster of node.js is launched, to distribute the load. With the help of a cluster module, child processes can be created very easily sharing the server ports. It also creates in IPC channel to facilitate the communication of the Master and worker process.

    Child Process: A child process can be easily spun using Node’s child_process module and these child processes can easily communicate with each other with the help of a messaging system. A developer can access Operating System functionalities by the child_process module, this happens by running any system command inside a child process. The child process input streams can be controlled and the developer can also listen to the output stream.

    Arguments that are to be passed to the underlying OS command can also be controlled, and whatever is to be done can be done with that command’s output. This module provides the user with various utility functions where all of its logics are stacked on top of each other. Its most significant feature is spawn () which is used to spawn a new process of type git log. It is also complemented with a cluster module offering a variety of tools to ease the processes like start, stop, pipe input, pipe output and many more.

Related Questions

Please Login or Register to leave a response.

Related Questions

Node JS Interview Questions with Express

What is Node js ?

Node Js is one of the most popular and powerful server technologies today. It allows you built the entire website only..

Node JS Interview Questions with Express

Explain CLI in Node.js?

CLI stands for Command Line Interface. It is a utility or program on your computer where users type commands to perform..

Node JS Interview Questions with Express

In which Language Node Js is written ?

Node js is written in C, C++,JavaScript.It uses Google’s open source V8 Javascript Engine to convert Javascript code..