-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add support for node cluster #16
base: master
Are you sure you want to change the base?
Conversation
@jfrconley Awesome contribution here! Would love to see this merged =] @mafintosh |
Is this a Linux only solution? AFAIK On Linux it does look nice though
|
@gakada You are correct in that on Windows, you get effectively a single worker as ports cannot be shared. SO_REUSEADDR (at least on Windows) essentially steals the port from whoever last had it. It is only included for compatibility reasons (you shouldn't be deploying a node server on Windows anyways). This is similar to what node does by default; All platforms other than Windows use round-robin with SO_REUSEPORT and Windows distributes connections to workers through the master. You could implement something similar on top of this, but the gains would be middling and likely not worth the effort. edit: You'll also get higher numbers if you limit your number of threads to your number of cores (or double if you have hyper threading) edit 2: add context |
Well I tried running const cluster = require("cluster");
const http = require("turbo-http");
if (cluster.isMaster) {
for (let i = 0; i < 2; ++i) {
cluster.fork();
}
} else {
const pid = Buffer.from(`${process.pid}`);
http.createServer((_, res) => res.end(pid)).listen(8080);
} and it works on Linux (2 workers utilized), but doesn't work on Windows (only 1 worker). Maybe we can have a test demonstrating that cluster load balancing is working (> 1 workers)? |
@gakada Sorry, updated my response while you were posting yours |
If I replace |
@gakada Right, I address this in my response. Node uses a single master process on windows that handles all connection termination, but then uses an IPC to distribute them to workers. Again, you could do this on top of turbo-http, but I'm not convinced the benefits would outweigh the costs |
Btw, it is the same "not working" behavior on OS X. So I guess what I was pointing out is that if you test vanilla |
You're totally right, I done goofed. Upon further research it seems that the load distribution features of SO_REUSEPORT are exclusive to Linux and that server.listen in Node actually passes off most work to the master process (setting up file descriptors to listen on and such). More work will have to be done on properly integrating such logic here. |
Adds support for node cluster module using the SO_REUSEPORT option for the uv socket. This can be disabled with the server option reusePort, which defaults to on. SO_REUSEADDR is used instead on windows.