-
Notifications
You must be signed in to change notification settings - Fork 63
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
It is not working for me #4
Comments
I am having the same issue, even with the original sticky-session. It seems that net connections passed from master to children is not released properly, choking the backlog with unreleased net connections (fd). |
Do you think anywhere I can patch the readStart() at runtime? nodejs/node-v0.x-archive#7905 (comment) I want to make my app work ASAP before the official fix. |
@vicary the workaround I outlined in nodejs/node-v0.x-archive#7905 does work okay:
|
Thanks for that, works like a charm. >95% of connections are running smooth now. 😄 |
webscale. :P |
This was just fixed in the v0.12 branch. I have no idea when it will be released, but once it happens I'll update the document to reflect what has to change. (Should be using the |
I am looking into implementing this, @samcday where does that snippet go? I am assuming it goes into master to stop it from reading anything before being passed to the worker. |
I've chopped down my master.js for your reference. Not sure if the cluster.js part, which I took reference from node.js core, is necessary, you may experiment yourself. EDIT A more simple workaround is to add |
Thanks @vicary, I can't use sticky-session.js since I already have code that has clustering in a separate file. Is the handle closing code 100% necessary in your sample? https://gist.github.com/vicary/b8a7664227ec0245a0dc#file-master-js-L74-L81 Also when do you send the |
In short, I'm not sure. Like what I wrote in the comments, I've crunched through the node.js core, I can assure you that's how node handles cluster on itself. But Here is an example of worker.js |
Yeah after I implemented it, it works on my test environment although with the handle closing code the
This is when I reload the page. Not sure how this will behave under load where lots of connections are coming in. |
I changed the |
The Doesn't really matter tho, the difference is in the scale of nanoseconds. |
Hi, I am beginner for Node.js clustering. I followed example code step by step but doesn't work. Very appreciate if you could help me. Environment: this is my code.
The problem is: |
I am using your solution, but when I tried to run in browser, it is just hanging, and there is no response at all. My versions are:
Node: 0.10.x
Express: 4.2.0
redis: 0.10.1
socket.io: 1.0.6
socket.io-redis: 0.1.3
It is exactly same as yours
I think this is confusion:
process.on('message', function(message, connection) {
if (message !== 'sticky-session:connection') {
return;
}
server.emit('connection', connection);
});
How to make the real code to process the request, if you are using app.listen(0, 'localhost')
My code is as follows:
var cluster = require('cluster'),
net = require('net');
var num_processes = process.env.WORKERS || require('os').cpus().length;
if (cluster.isMaster) {
console.log('start cluster with %s workers', num_processes);
var workers = [];
var spawn = function(i) {
workers[i] = cluster.fork();
};
for (var i = 0; i < num_processes; i++) {
spawn(i);
}
var worker_index = function(ip, len) {
var s = '';
for (var i = 0, _len = ip.length; i < _len; i++) {
if (ip[i] !== '.') {
s += ip[i];
}
}
return Number(s) % len;
};
var server = net.createServer(function(connection) {
var worker = workers[worker_index(connection.remoteAddress, num_processes)];
worker.send('sticky-session:connection', connection);
}).listen(3000);
} else {
}
process.on('uncaughtException', function (err) {
console.error((new Date).toUTCString() + ' uncaughtException:', err.message)
console.error(err.stack)
process.exit(1)
})
The text was updated successfully, but these errors were encountered: