Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
how to implement multiprocessing in serverless-offline with node js, express, cluster,

I'm trying to use cluster in serverless offline. but after running serverless offline it gives me following error

offline: Failure: offline: handler 'handler' in /home/Documents/cluster is not a function
Error: offline: handler 'handler' in /home/Documents/cluster is not a function
    at InProcessRunner.run (/home/Documents/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:160:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async LambdaFunction.runHandler (/home/Documents/node_modules/serverless-offline/dist/lambda/LambdaFunction.js:368:20)
    at async hapiHandler (/home/Documents/node_modules/serverless-offline/dist/events/http/HttpServer.js:702:18)
    at async exports.Manager.execute (/home/Documents/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
    at async Object.internals.handler (/home/Documents/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at async exports.execute (/home/Documents/node_modules/@hapi/hapi/lib/handler.js:31:20)
    at async Request._lifecycle (/home/Documents/node_modules/@hapi/hapi/lib/request.js:371:32)
    at async Request._execute (/home/Documents/node_modules/@hapi/hapi/lib/request.js:281:9)

and after that it start to kill process. I don't have any idea how to implement cluster in serverless offline.

if I'm call serverless handler in master process it works file for single thread but not for child process.

const cluster = require("cluster");
const totalCPUs = require("os").cpus().length;
const serverless = require("serverless-http");
const app = require("./api");

console.log("cluster.isMaster", cluster.isMaster);
if (cluster.isMaster) {
  console.log(`Number of CPUs is ${totalCPUs}`);
  console.log(`Master ${process.pid} is running`);

  // Fork workers.
  for (let i = 0; i < totalCPUs; i++) {
    cluster.fork();
  }
  module.exports.handler = serverless(app);// if I declare here it works fine 
  cluster.on("exit", (worker, code, signal) => {
    // console.log(`process killed:`, worker.kill());
    console.log(`${worker.process.pid} is killed`);
    // console.log("code, signal ", code, signal);
    // cluster.fork();
    console.log(`new proccess pid: ${process.pid}`);
  });
} else {
  console.log("process pid ", process.pid);
  // console.log("serverless(app)",app);
  // runServer.runServer();
  module.exports.handler = serverless(app);// if I declare here never get called and 
                                          //kill all process
}

please guide, I'm frustrate to implement this because I'm doing this from long time but not getting any solution.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda