PM2 cluster mode with CPU 0% consuming a lot of memory with no traffic

87 Views Asked by At

I have a LoopBack application that runs in cluster mode using PM2. One instance serves as the primary with active schedulers, while the other instances act as replicas to handle background jobs that are initiated when we receive webhook requests. However, I have noticed that after half an hour of starting the process with PM2 and with no traffic, the CPU utilization is at 0%. The memory usage for instances ranges between 450MB and 1.6GB. We are using Redis and Bull to process jobs. Also, when there is traffic, max_memory_restart reaches the threshold, and it restarts.

Can someone guide me on how to resolve this?

Nodejs version - 14.19
PM2 version - 5.2.2
Instace - 8CPU and 32 GB RAM

ecosystem.config

module.exports = {
  apps: [
    {
      name: 'primary',
      script: 'dist/index.js',
      instances: 1,
      exec_mode: 'cluster',
      autorestart: true,
      watch: false,
      time: true,
      pmx: false,
      max_memory_restart: '3G',
      env: {
        NODE_ENV: 'development',
      },
      env_production: {
        NODE_ENV: 'production',
      },
    },
    {
      name: 'replica', 
      script: 'dist/index.js',
      instances: '-1',
      exec_mode: 'cluster',
      autorestart: true,
      watch: false,
      time: true,
      pmx: false,
      max_memory_restart: '3G',
      env: {
        NODE_ENV: 'development',
      },
      env_production: {
        NODE_ENV: 'production',
      },
    },
  ],
};

enter image description here

0

There are 0 best solutions below