Website::: https://pm2.io/doc/en/runtime/quick-start/Preface
Source: HTTPS://GITHUB.COM/UNITECH/PM2
The PM2 here are not atmospheric pollutants.
In fact, the PM2 is a process manager with a load-balanced node application, and the node implements a process management library with many, forever is also one of the most powerful but relatively old process managers.
Why to use PM2
The basic reason for this problem is that because node itself is a single-threaded application, it is characterized by the fact that all methods are serially executed at once, and node is not capable of creating a new thread on its own like Java to implement an asynchronous operation, if the i/is executed The blocking in O reduces the execution efficiency of the entire application and causes high CPU usage.
So in this mode, a thread can only handle one task, and to improve throughput it must be multithreaded. While there are many advantages of single-threaded, such as avoiding thread synchronization or deadlock, state synchronization, and so on, but in the application and computing power requirements of today, the biggest drawback is that the multi-core CPU can not take advantage of the advantages to improve operational efficiency.
We know that node can take advantage of asynchronous I/O to avoid thread blocking and improve utilization:
At the same time, in order to compensate for the single-threaded inability to take advantage of multicore CPUs, the concept of "sub-process", node. JS is actually a single thread of Javascript execution threads, real I/O operations, and the underlying API calls are executed through multithreading. Of course here I just point out this background, then why do we use PM2?
I've summed up two more concise answers: 1. PM2 can deploy your application to all CPUs on the server ($ pm2 start app.js-i max), effectively solving the problems raised in the previous background. 2, the same process manager, why not forever? I think the biggest difference is the lack of monitoring, the limited process and cluster management. In the monitoring and log aspects can be considered forever finish PM2, why, a picture you know the answer.
This is the PM2 website to give the demo, we can clearly see the whole cluster mode, state, CPU utilization and even memory size, and forever give what? Null
What if I want to monitor all process status in real time?
This is the power of PM2, multi-process management, monitoring, load balancing ...
PM2 Main Features
- Built-in load balancing (using node cluster cluster module, sub-process, you can refer to Pauling "in layman node. js" book Nineth)
- Thread Guard, keep alive
- 0-second downtime overload, no downtime required for maintenance upgrades.
- Now Linux (Stable) & MacOSX (Stable) & Windows (Stable). Multi-platform Support
- Stop an unstable process (avoid infinite loops)
- Console detection
- Provide HTTP API
- Remote control and real-time interface API (Nodejs module, allows interaction with PM2 process Manager)
Usage
$ npm Install pm2-g # command line installation PM2 $ pm2 start App.js-i 4 #后台运行pm2, start 4 app.js # can also put ' ma X ' parameter passed to start # Number of correct processes depends on CPU core number $ PM2 start app.js--name My-api # named process $ PM2 List # Show All process status $ PM2 Monit # Monitor all Processes $ PM2 Logs # Show all process logs $ pm2 Stop all # Stop all processes $ PM2 Restart all # restart all processes $ pm2 reload All # 0 seconds Downtime Reload process (for networked process) $ PM2 Stop 0 # Stop the specified process $ pm 2 Restart 0 # Restart the specified process $ PM2 startup # Generate Init script keep process alive $ PM2 Web # run robust computer API en Dpoint (http://localhost:9615) $ pm2 Delete 0 # kills the specified process $ pm2 Delete all # different ways to kill all processes running the process: $ PM2 Start app . js-i Max # Start maximum number of processes based on number of active CPUs $ PM2 start App.js-i 3 # Start 3 processes $ pm2 start app.js-x #用fork模式启动 app.js instead of using C luster$ PM2 Start App.js-x---a 23 # start app.js with fork mode and pass parameters (-a) $ PM2 start app.js--name ServerOne # Start a process and name it For serverone$ pm2 stop SERverone # Stop ServerOne process $ pm2 Start App.json # START process, set options in App.json $ pm2 start app.js-i Max---a 23 #在--App.js passed parameters $ pm2 start app.js-i max-e err.log-o Out.log # Start and generate a profile you can also execute apps written in other languages (fork mode): $ pm2 start my-bash-script.sh-x--interpreter bash$ pm2 start my-python-script.py-x--interpreter python
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
Attached keymetrics real-time monitoring
Address: Https://app.keymetrics.io/#/register
PM2 official also combined with PM2 management to provide a set of visual online monitoring platform, how many cows? :
Create your own first project after registration the project will receive a password after it is successfully completed:
The system allocates public key and secret key. Then, enter the following command on the server side where the PM2 is installed
pm2 interact your-secret-key your-public-key
The next thing to do is to visualize it.
Why process Daemon chooses PM2