Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJs-Performance

  • Maximizing Cluster Perfromance : 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…

  • 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

image

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

Screenshot 2023-02-14 171203

  • 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 CPU

Worker Thread

  • One process total
  • Each worker will have its own instance of V8 and Event Loop
  • Shares memory with other threads

About

Maximizing the performance of NodeJs using clustering, performing load balancing using PM2, and understanding how worker threads vs cluster works.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages