Y
Y
yociyavi2016-07-01 11:44:11
JavaScript
yociyavi, 2016-07-01 11:44:11

Why doesn't clusterer reduce load time?

I decided to check the operation of cluster. Wrote a cycle which fulfills 9-10 seconds. And launched 4 tabs at about the same time.
In total we have:
1) 10.05 sec
2) 19.99 sec
3) 31.38 sec
4) 41.93 sec
I.e. the cluster does not seem to work.
Although there are processes:
3c80ad4d39a8478d9f9a5f827c82c5bf.png
Here is the server code:

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
    for (var i = 0; i < numCPUs; i++) {
        cluster.fork();
    }
} else {
    http.createServer((req, res) => {
        for (var i = 0; i < 5000000000; ++i) {
        }
        res.writeHead(200);
        res.end('hello world\n');
    }).listen(3000);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Shemsedinov, 2016-07-01
@yociyavi

The cluster also should not reduce loading time. Its task is to increase the overall performance of rps (request per second). The way it works is that a connection is established with the master and then the socket is passed via IPC to the worker for processing. If each connection does something more time-consuming than returning a string, then this will allow us to utilize additional tasks for the task. kernel, but in your case, the IPC overhead compensates for the parallel processing. In addition, IPC itself is not fast, and cluster is a piece of shit code, of the built-in libraries of the node, only http is written worse. I have removed cluster from my projects and am getting ready to remove http.

_
_ _, 2016-07-01
@AMar4enko

Check cluster.schedulingPolicy - the behavior you expect is round-robin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question