Answer the question
In order to leave comments, you need to log in
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:
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question