This Node.js Cluster project is designed to demonstrate the use of the cluster module to create a multiprocessor Node.js
application for better utilization of CPU cores. The project includes a simple Express application in app.js
and a
clustering logic in cluster.js
.
Before running the application, ensure you have the following installed:
- app.js: Contains the main Express application logic.
- cluster.js: Manages the creation of multiple worker processes using the cluster module.
- package.json: Project configuration file with dependencies and start script.
-
Clone the repository:
git clone https://github.com/saeedNW/node.js-cluster.git
-
Navigate to the project directory:
cd node.js-cluster
-
Install dependencies:
npm install
-
Start the application:
npm start
This will launch the application and utilize multiple CPU cores via the cluster module.
To test the application's performance, you can use the loadtest
module. Follow these steps:
-
Install
loadtest
globally:npm install -g loadtest
-
Run the load test:
loadtest -c 10 -t 10 -n 100 http://localhost:3000/cluster
This command will simulate 10 clients (-c) making requests for 10 seconds (-t) with a total of 100 requests (-n) to the specified endpoint. Adjust the parameters as needed for your testing requirements.