I recently learned about the cluster
module in node, and wanted to give it a spin. I have a super basic express app that look like this.
const express = require('express');
const app = express();
const cluster = require('cluster');
const os = require('os');
const numCores = os.cpus().length;
app.get('/', (req, res) => {
res.status(200).json({ success: true })
});
if (cluster.isMaster) {
for (let i = 0; i < numCores; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
console.log("Let's fork another worker!");
cluster.fork();
});
} else {
app.listen(1337, () => console.log('server is running on port 1337'));
}
I am also using the Artillery load testing tool to load test this basic node app.
The problem is that whether I use the cluster
module or not, by the time my load test is done running, I have the same amount of failed requests.
This is the output of my test
Scenarios launched: 30000 Scenarios completed: 23145 Requests completed: 23145 Mean response/sec: 426.14 Response time (msec): min: 0 max: 449 median: 1 p95: 4 p99: 35 Scenario counts: simple request: 30000 (100%) Codes: 200: 23145 Errors: ETIMEDOUT: 6855
Why do I have 6855 ETIMEDOUT
errors even when I am using the cluster
module?
This is the exact same amount of errors I have when not using the cluster
module.