-
Notifications
You must be signed in to change notification settings - Fork 3.8k
subsystem: net tcp #3198
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
subsystem: net tcp #3198
Conversation
support reuserport flag for tcp socket, improve performance and load balancing reuserport flag in linux will make process accept and handle the connection better
vtjnash
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be enabled by default, as it is a functional change
My understanding is that linux also requires this to be after the bind call, while freebsd requires it to be before the bind call.
support reuserport flag for tcp socket, improve performance and load balancing reuserport flag in linux will make process accept and handle the connection better
support reuserport flag for tcp socket, improve performance and load balancing reuserport flag in linux will make process accept and handle the connection better
Thanks for review 。I have add environment variable SO_REUSEPORT to control this flag。In addition SO_REUSEPORT (since Linux 3.9) |
|
Ah, you are right, I had that backwards (FreeBSD must be afterwards) |
OS usually check the port in bind call。so i think we should call setsockopt before bind。And i find this document(https://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2&format=html) that also describe this。 |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
I think it's a good resolution to resolve the issue of nodejs/node#37343 |
santigimeno
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think using an environment variable is the libuv way to do this. I think a better option would be defining a specific uv_tcp_flags flag: UV_TCP_REUSEPORT that can be passed to uv_tcp_bind().
Thanks for review. I have change the code. Looking forward to your review again |
I have add this flags into my Node.js branch(branch add-reuseport of https://github.com/theanarkh/node). You can test the performance in Linux 3.9 and above. |
|
Codewise, except some style nits I think it's good, but I've been thinking about it and I'm not sure we should add this option as the SO_REUSEPORT seems to be implemented differently across platforms. (see: https://stackoverflow.com/a/14388707). From what I understand this PR is focused in the Linux implementation which only seems to be implemented also on
My choice would be 1 but let's see what other @libuv/collaborators think. |
Thanks for your advice, What I think is that Node.js Server runs under Linux in most cases, so supporting this flag allows Node.js to benefit from Linux. For systems that do not support this flag, I also added compatible code for Node.js(demo code: https://github.com/theanarkh/node/pull/1/files). Do you mean not to support this flag in Libuv, or do not modify the code in uv_tcp_bind? Nginx supports this flag already. |
What I mean is that the consumer of libuv (nodejs in this case) could call |
before uv_tcp_bind the socket have not been made(make in uv__tcp_bind). consumer make the socket? |
|
Yeah, I forgot to add, use |
I think it should be that the bottom layer supports certain features, and then the upper layer decides whether to enable it, rather than when the upper layer needs to use the feature, it needs to write similar repetitive code, which will increase the burden on the upper layer. |
|
I understand, but the issue here is that it's not a feature that can be implemented cross-platform. BTW, as a reference here's an issue from some years ago about this very same topic: #1229 (comment). The solution it refers to is also using |
Thanks again, i get it, i try to support this in C++ and js of Node.js。 |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
I'm going to close this. Please feel free to re-open in case you thing there's more to discuss. Thanks |
|
I have read the source code of libuv, and found that the function of Lines 562 to 566 in 0f696da
|
|
@yunnysunny I'm not sure I understand your question. Can you elaborate? |
@santigimeno said we should use |
|
SO_REUSEPORT is different between tcp and udp. For udp it means mutilcast which is supported in multiple platform. So i think this is why the Libuv supports it. |
👌 |
support reuserport flag for tcp socket, improve performance and load balancing
reuserport flag in linux will make process accept and handle the connection better