0

I have a nodejs express API. I set up the cluster module and nginx. Load testing gives me subpar results. Why?

So I have a regular nodejs express API with 8 clusters set up. I try load testing to see if there will be a difference and it gives 400 RPS. Does anybody have an idea why? I have a regular API bootstrapped with express-generator and this is my cluster.js file:

const cluster = require("cluster");
const numCPUs = 8;

if (cluster.isMaster) {
  console.log(`Master ${process.pid} is running`);

  for (let i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on("exit", (worker, code, signal) => {
    console.log(`Worker ${worker.process.pid} died`);
    cluster.fork();
  });
} else {
  const app = require("./app");
  const port = 3000; 
  app.listen(port, () => {
    console.log(`Worker ${process.pid} started and listening on port ${port}`);
  });
}

Could it be my CPU/memory? They hit 90% and 100% when load testing.

giri
  • 1

0 Answers0