PM2:每个内核有多个应用程序 vs 一个内核有多个实例

问题描述 投票:0回答:0

我试图完全理解将 Node 应用程序部署到生产环境的几种方法之间的区别。

假设我有一台 4 核的电脑 并假设如下,

// example 1
module.exports = {
    apps: [
        {
            name: 'worker-0',
            script: './server.js',
            instances: 'max',
            exec_mode: 'cluster'
        }
    ]
};

据我所知,此配置启动了一个具有 8 个实例的 worker(因为我已经要求了

'max'
个实例)。但是,如果我将
exec_mode
更改为
fork
会怎么样?那会发生什么?

现在假设我有以下配置:

// example 2
module.exports = {
    apps: [
        {
            script: './server.js',
            exec_mode: 'fork',
            name: `worker-0`
        },
        {
            script: './server.js',
            exec_mode: 'fork',
            name: `worker-1`
        }
    ]
};

在这里,我不完全理解术语。我在这里说的是什么,我想要 two 工人,每个工人运行一个服务器实例,总共 two 实例?

同样,推而广之,请考虑以下内容:

// example 3
module.exports = {
    apps: [
        {
            script: './server.js',
            exec_mode: 'cluster',
            instances: 'max',
            name: `worker-0`
        },
        {
            script: './server.js',
            exec_mode: 'cluster',
            instances: 'max',
            name: `worker-1`
        }
    ]
};

这似乎类似于第一个例子,我想要两个工人和八个实例,因为每个工人都设置为

instances: 'max'
,因此,他们每个人都有4个实例。

生产环境的最佳方法是什么?可以安全地假设第一个例子,有 one 工人和

'max'
实例,在
cluster
模式下运行是最佳的吗?

node.js pm2
© www.soinside.com 2019 - 2024. All rights reserved.