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

Parallization mechanism \ oppurtunity #6

Closed
zouhir opened this issue Nov 6, 2018 · 15 comments
Closed

Parallization mechanism \ oppurtunity #6

zouhir opened this issue Nov 6, 2018 · 15 comments

Comments

@zouhir
Copy link

zouhir commented Nov 6, 2018

I have noticed in the benchmarks in readme that the test ran on single thread.

Rust's actix, Go's fast http and C++ can do multi-thread. Would this implementation for Node allow clustering? or is it something on the roadmap?

Thank you!

@ghost
Copy link

ghost commented Nov 7, 2018

Yes ofc you can do that. How would it look like if a server only could use 1 thread in 2018? The graphs are single threaded to show that spent CPU time is equal for all software. You can, or will be able to, use Linux REUSE_PORT and similar.

@lukeed
Copy link

lukeed commented Nov 7, 2018

Are you planning to expose it thru native cluster module? Typical http clustering setup is here: https://nodejs.org/api/cluster.html#cluster_cluster

@ghost
Copy link

ghost commented Nov 7, 2018

Nope. Nothing Node.js-specific is going in here, this is its own server which just happens to work in Node.js. Probably it will work just fine though, there will definitely be support to move sockets over threads.

@ghost
Copy link

ghost commented Nov 7, 2018

I will keep that in mind anyways, there needs to be an example using the cluster feature.

@lukeed
Copy link

lukeed commented Nov 7, 2018

Sounds good. It doesn't work as of now, but you're probably aware already 😀

Looking forward to this!

@ghost
Copy link

ghost commented Dec 26, 2018

This looks like a problem - I guess cluster worked before because before uws was using the Node.js Http server which obviously works with the cluster module. You're just trading one hacky solution for another one really. Before it was very hacky to work with Node.js Http server and now it's hacky to work with cluster module.

Best would probably be to have a complete replacement or just skip this for Node.js

@ghost
Copy link

ghost commented Dec 29, 2018

One possible solution is to use net.Server to listen and accept, and then import the FD to the uWS.App and have it do everything else.

That's kind of the same as old uws, but instead of using the HTTP server of Node.js it only makes use of the very minimal net.Server thing.

It will make it slower though, at least for short lived connections

@ghost
Copy link

ghost commented Dec 29, 2018

Nope, not going to work

@ghost
Copy link

ghost commented Dec 31, 2018

Technically, all you need to do really is to call Unix fork syscall in the listen callback. That would enable some kind of clustering. More work can be done to even the distribution and balan e connections but this fork call should be enough to have basic clustering. What Node.js does is some kind of non-Unix-Windows-compatible black magic hack that I simply cannot support. Standard Unix fork should do it (along with similar Unix features). Windows is what it is..

@ghost
Copy link

ghost commented Dec 31, 2018

I'm pretty much sure V8 is properly compatible with Unix fork but Node.js itself might very well break I don't know

@ghost
Copy link

ghost commented Dec 31, 2018

Well quick tests show that it is at least possible to have SOME kind of clustering with Node.js, all you need is SO_RESUSEPORT and it works decently actually. 120k up to 380k. It doesn't seem to be very round-robin ish though, but all instances gets loaded fully at least for this load test

@zorro-fr24
Copy link

zorro-fr24 commented Jan 1, 2019

It doesn't seem to be very round-robin ish though, but all instances gets loaded fully at least for this load test

If you are still using Cluster in any capacity to achieve this, then by default node lets the OS decide how to route connections - you can change the behaviour with:

Cluster.schedulingPolicy = Cluster.SCHED_RR;

before forking.

@ghost
Copy link

ghost commented Jan 1, 2019

https://nodejs.org/api/cluster.html#cluster_cluster_schedulingpolicy

Interesting. Round robin is possible to achieve with SO_REUSEPORT with just a few changes - currently it is undefined behavior. Very promising, then clustering will work at least on Linux which is the main platform anyways

@ghost
Copy link

ghost commented Jan 1, 2019

I'm closing this, will be up to uSockets to solve. Will work nicely on Linux, other platforms might be supported at some point.

@ghost ghost closed this as completed Jan 1, 2019
@dalisoft
Copy link

@alexhultman any news? i can't make it work, on linux too. on osx/macos too.
any example and/or guide here available?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants