https://github.com/syed007hassan/nodejs-performance
Maximizing the performance of NodeJs using clustering, performing load balancing using PM2, and understanding how worker threads vs cluster works.
https://github.com/syed007hassan/nodejs-performance
availability clustering load-balancer pma zero-downtime
Last synced: 5 months ago
JSON representation
Maximizing the performance of NodeJs using clustering, performing load balancing using PM2, and understanding how worker threads vs cluster works.
- Host: GitHub
- URL: https://github.com/syed007hassan/nodejs-performance
- Owner: Syed007Hassan
- Created: 2023-02-14T09:18:40.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-14T17:36:13.000Z (over 2 years ago)
- Last Synced: 2025-02-17T21:46:33.121Z (8 months ago)
- Topics: availability, clustering, load-balancer, pma, zero-downtime
- Language: JavaScript
- Homepage:
- Size: 69.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeJs-Performance
* [Maximizing Cluster Perfromance ](https://github.com/Syed007Hassan/NodeJs-Performance/tree/69dabf9ae8c2f96e53baee4f383aff521882e357):
Using the amount of logical cores available on a system, increasing the performance of web servers so that the response time can be lesser when multiple requests are being made. A module that is responsible for providing cluster related API is called a cluster. It's NodeJS inbuilt module. Cluster uses single master(parent) process and many worker(child) process. See below diagram to know more…
![]()
* [Load Balancing using PM2 (Process Manager)](https://pm2.keymetrics.io/docs/usage/quick-start/): It is a runtime process management and monitoring tool with a built-in load balancer for NodeJS applications which makes managing them easier on production.
- This could be installed globally on the system, using the following command:```
npm i pm2 -g
```- How to use:
The best thing about PM2 is easiness. Some of the basic commands for using PM2 are following one:- To Start:
The following command will start an application.
```
pm2 start server.js
```
8 instances shows the max number of logical cores available in a system.
- To Stop an Application/Process:
```
pm2 stop pid or App-name
```- To Restart an Application/Process:
Restart will kill and start an application
```
pm2 restart pid or App-name
```- To Reload an Application/Process:
As opposed to restart, which kills and restarts the process, reload achieves a 0-second-downtime reload.
```
pm2 reload pid or App-name
```- To Delete an Application/Process:
```
pm2 delete pid or App-name
```- To effect “All” Applications/Processes:
'All' attribute will affect every process and application.
```
pm2 reload all
```- To Monitor:
```
pm2 monit
```
- To View Logs:
```
pm2 logs
```
#### Worker Threads VS Cluster
Cluster
- Each process has it’s own memory with it’s own Node (v8) instance
- One process is launched on each CPUWorker Thread
- One process total
- Each worker will have its own instance of V8 and Event Loop
- Shares memory with other threads
![]()
![]()