admin管理员组

文章数量:1122832

I was trying to start my nextjs 14.2 app using pm2. at first, i tried to use: pm2 start npm --name "Next" -i max -- start command. everything is ok and it use about 70MB of ram.

than i tried to start the exactly same app, using configuration file: ecosystem.config.js

module.exports = {
    apps: [
        {
            name: 'maApp',
            exec_mode: 'cluster',
            instances: 'max',
            script: './node_modules/next/dist/bin/next',
            args: 'start',
            exp_backoff_restart_delay: 100,
            watch: false,
            max_memory_restart: '150M',
            autorestart: true,
        }
    ]
}

then i found out, that 2nd way takes much more ram and cpu - ~150MB at zero requests, under load it could take ~1.2GB of ram.

if u go to the pm2 monit, you should be available to see, that with 1st method, the script path is /root/.nvm/versions/node/v21.6.2/bin/npm; 2nd - ./nextjs_test_fast/node_modules/next/dist/bin/next.

So:

  1. where this big difference coming from?
  2. which way to run app is more suitable?
  3. is there any way to reduce the memory consumption from 2nd method?
  4. is there any way to start cron job to reload apps, not restarting it (without scripts)?

PS

also, using 1st method, the app do not updating cache files and to fix this, i'm using pm2 reload command and everything starts working normal.

Nextjs - 14.2 pm2 - 5.4.0 node - 21.6.2 npm - 10.2.4 nvm - 0.39.7

本文标签: linuxNextjs and PM2 on ubuntu serverStack Overflow