Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

issue node v0.12.3 win7 : problem processing multiple requests in parallel with cluster module (1 connection out of 2) #25350

Closed
kristofen opened this issue May 19, 2015 · 5 comments

Comments

@kristofen
Copy link

Hello,
I've been trying nodejs 0.12..3 on my windows 7 pc (4 cores).
My test is focused on multicore connection processing (see the code below) using cluster module.

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

if (cluster.isMaster) {
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', function (worker, code, signal) {
    console.log('worker ' + worker.process.pid + ' died');
  });
} else {
  myApp();
}

function myApp() {
  // Workers can share any TCP connection
  // In this case its a HTTP server
  http.createServer(function (req, res) {
    console.log('[httpServer] new request');
    res.writeHead(200);
    // connection will be hanging forever 
    while (true) {
      for (var i = 0; i < 10000000; i++) {}
      res.write("chunk!!!");
    }
    res.end("this is the end\n");
  }).listen(3000, function (err) {
    if (err) console.error(err);
    console.log('listening on port 3000');
  });
}

My test is : launch 8 connections in parallel (with curl). Note: I launch 8 connections because I'm on a 4 core PC.
The result: only connections number 1, 3, 5 and 7 will be processed in parallel (ie: receiving chunk!chunk!chunk!...)

sans titre

@cjihrig
Copy link

cjihrig commented May 19, 2015

What are you expecting to happen? You have four child processes. Each one receives a connection and then you put it into an infinite loop so that it can't accept any new connections.

@kristofen
Copy link
Author

Thx for your reply

I was expecting that the first 4 connections will be processed and any additional connection will be on hold.
But the test shows that:

  • the first conn. is being processed
  • the second is on hold (weird because at that point other child processes are waiting for connections)
  • the third is being processed
  • the fourth is on hold (same remark as for the 2nd cn)
  • the fifth is being processed
  • the sixth is on hold (same remark as for the 2nd cn)
  • the seventh is being processed
  • the eighth is on hold (normal because all child processes are busy)

Isn't that weird?

I was expecting

  • the first conn. is processed
  • the second is processed
  • the third is processed
  • the fourth is processed
  • the fifth is on hold (until one previous ends)
  • the sixth is on hold (until one previous ends)
  • the seventh is on hold (until one previous ends)
  • the eighth is on hold (until one previous ends)

Am I missing something ?

@cjihrig
Copy link

cjihrig commented May 19, 2015

I believe that on Windows, the operating system controls which requests are sent to which threads. I wonder if you'd have different results on a different OS using the round robin scheduler.

EDIT: By "threads" I really meant "processes" :-)

@cjihrig cjihrig closed this as completed May 19, 2015
@kristofen
Copy link
Author

thanks I'll test that on debian

@kristofen
Copy link
Author

You're totally right @cjihrig !! on debian the first 4 connections are processed while any other connections are on hold.

Windows 👎

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants