哪种扩展 nodejs 应用程序的方式更好?
Which way of scaling nodejs app is better?
我也需要跨不同的服务器进行扩展。
- 仅 pm2 是否可行,因为它仅从主进程分叉子进程,它们也共享相同的端口。
- 正在使用像 Nginx 这样的反向代理,是水平扩展的前进方向吗?
你可以选择,PM2 with Nginx。
这是扩展 node.js 应用程序的首选方法。
下面是更好的解释:
Nginx on the outside, to be the front door. It should handle SSL and be a reverse proxy into pm2. Bonus points for mapping static assets at nginx, and sheilding node from those requests.
Then pm2. It too is a reverse proxy, but very specific to node processes and really more of a process manager than a webserver. Using it is still a great idea. You can spin up N node processes allowing you to take advantage of multiple CPUs, and pm2 will keep them going in case of a crash. You can make graceful restarts as well, updating one instance of your application at a time, with zero downtime.
Pm2 also comes with some handy utilities like built in (freemium) metrics, and a great little web management tool you could expose to show basic stats, and stdout of your processes.
Having both layers, on the same server or split out if needed, gives you a lot of control and performance. The overhead is not at all bad (since each layer is doing what it does best) and is not at all difficult to set up.
我也需要跨不同的服务器进行扩展。
- 仅 pm2 是否可行,因为它仅从主进程分叉子进程,它们也共享相同的端口。
- 正在使用像 Nginx 这样的反向代理,是水平扩展的前进方向吗?
你可以选择,PM2 with Nginx。
这是扩展 node.js 应用程序的首选方法。
下面是更好的解释:
Nginx on the outside, to be the front door. It should handle SSL and be a reverse proxy into pm2. Bonus points for mapping static assets at nginx, and sheilding node from those requests.
Then pm2. It too is a reverse proxy, but very specific to node processes and really more of a process manager than a webserver. Using it is still a great idea. You can spin up N node processes allowing you to take advantage of multiple CPUs, and pm2 will keep them going in case of a crash. You can make graceful restarts as well, updating one instance of your application at a time, with zero downtime.
Pm2 also comes with some handy utilities like built in (freemium) metrics, and a great little web management tool you could expose to show basic stats, and stdout of your processes.
Having both layers, on the same server or split out if needed, gives you a lot of control and performance. The overhead is not at all bad (since each layer is doing what it does best) and is not at all difficult to set up.