0

I'm running a clustered node app, with 8 worker processes. I'm giving output when serving requests, and the output includes the ID of the process which handled the request:

app.get('/some-url', function(req, res) {
    console.log('Request being handled by process #' + process.pid);
    res.status(200).text('yayyy');
});

When I furiously refresh /some-url, I see in the output that the same process is handling the request every time.

I used node load-test to query my app. Again, even with 8 workers available, only one of them handles every single request. This is obviously undesirable as I wish to load-test the clustered app to see the overall performance of all processes working together.

Here's how I'm initializing the app:

var cluster = require('cluster');
if (cluster.isMaster) {

    for (var i = 0; i < 8; i++) cluster.fork();

} else {

    var app = require('express')();

    // ... do all setup on `app`...

    var server = require('http').createServer(app);
    server.listen(8000);

}

How do I get all my workers working?

Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
  • Your request does not use any ressources. What happens if you do some calculation inside that takes more time than the time needed to handle a request ? As it stands, the worker is never busy between accepting a request and answering it. – Lorenz Meyer Mar 22 '17 at 19:17
  • Is it expected that the second worker will never be used until the 1st worker is busy? Either way I would expect `load-test` to do enough calling that workers become busy. Especially because requests can take upwards of 50ms to calculate (I've omitted the actual calculations for brevity in my example). – Gershom Maes Mar 22 '17 at 19:24
  • @LorenzMeyer I've actually done some additional testing; I artificially bumped up the calculation time to several seconds and simply refreshed quickly in the browser; your thought was correct! This test caused multiple processes to be used. It seems `load-test` does not fire its next request until the previous one has completed. If you submit an answer I'll give you the check! – Gershom Maes Mar 22 '17 at 19:36

1 Answers1

1

Your request does not use any ressources. I suspect that the same worker is always called, because it just finishes to handle the request before the next one comes in.

What happens if you do some calculation inside that takes more time than the time needed to handle a request ? As it stands, the worker is never busy between accepting a request and answering it.

Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
  • This was the issue. Useful note for anyone else using `node load-test`: the library will never activate any worker apart from the 1st unless you use the "concurrency" config option. – Gershom Maes Mar 22 '17 at 19:52