Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in cluster module while running an http server #8540

Closed
GavinDmello opened this issue Sep 14, 2016 · 2 comments
Closed

Issue in cluster module while running an http server #8540

GavinDmello opened this issue Sep 14, 2016 · 2 comments
Labels
cluster Issues and PRs related to the cluster subsystem.

Comments

@GavinDmello
Copy link

  • Version: 4.4.7
  • Platform: Darwin Kernel Version 15.5.0 root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
  • Subsystem: Cluster module

I'm not sure if a bug or not. I'm running an http server within the cluster module and all my requests seem to go the same process. I'm logging the pid and every time I get a request I get the same pid. I'm also setting the policy as cluster.SCHED_RR for a round robin. Some help would be great!

var cluster = require('cluster');
cluster.schedulingPolicy = cluster.SCHED_RR
if (cluster.isMaster) {
    var cpuCount = require('os').cpus().length;
    for (var i = 0; i < cpuCount; i += 1) {
        cluster.fork();
    }
} else {
    console.log('Four child processes created', process.pid)
    var express = require('express');
    var app = express();

    app.get('/', function(req, res) {
        console.log(process.pid)
        res.send('Hello World!');
    });
    app.listen(3001);
    console.log('Application running!');

}
@mscdex mscdex added the cluster Issues and PRs related to the cluster subsystem. label Sep 14, 2016
@timoxley
Copy link
Contributor

timoxley commented Sep 14, 2016

Try hitting it with curl http://localhost:3001/ a few times or try using different browsers and you should see it hits different processes. I believe this may be because the browser uses http keepalive, so the connection is reused.

@GavinDmello
Copy link
Author

@timoxley Thanks. Sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cluster Issues and PRs related to the cluster subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants