Skip to content

Nuxt js cluster mode (without PM2) #8241

Discussion options

You must be logged in to vote
const { loadNuxt } = require('nuxt-start')
const cluster = require('cluster');

// this number of workers 
const instanses = 2

if (cluster.isMaster) {
  for (let i = 0; i < instances; i ++) {
    console.log('a')
    cluster.fork();
  }

  cluster.on("exit", (worker, code) => {
    // worker finished because of an error
    if (code !== 0 && !worker.exitedAfterDisconnect) {
      console.log("Worker crashed. Starting a new one");
      cluster.fork();
    }
  });
  
  
  //signal of workers restart (when this signal is called it performes a recursive function disconnectiong workers and adding new ones on the same place and so it is performed a zero downtime update)
  process.on("SIGUSR2"…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@vtonchev
Comment options

Answer selected by vtonchev
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants