M
M
Michael2017-01-03 00:21:24
Node.js
Michael, 2017-01-03 00:21:24

How to understand the logic of this code and the cluster module?

I started to get acquainted with the cluster module, came across an article on Habré . In it, the author shares his code , which, according to him, will balance the loads. I don't understand line 62 in this code:

cluster.on('listening', stopNextWorker);

function stopNextWorker() {
  var i = workersToStop.pop(); //workersToStop - массив воркеров, ожидающих рестарта
  var worker = cluster.workers[i];
  if (worker) stopWorker(worker); //в stopWorker просто выполняется worker.disconnect();
}

Why do we need to kill the worker on the 'listening' event?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question