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

unix: support SO_REUSEPORT with load balancing for TCP #4407

Merged
merged 12 commits into from
May 21, 2024

Conversation

panjf2000
Copy link
Contributor

@panjf2000 panjf2000 commented May 17, 2024

For #386, #570, #1229

Relevant issue: nodejs/node#12228


The time was not ripe for introducing the SO_REUSEPORT TCP in #386 because SO_REUSEPORTs on platforms other than Linux didn't have the capabilities of load balancing, but as time went by, other systems started to extend the SO_REUSEPORT to distribute workload across all listening sockets: DragonFlyBSD 3.6.0 (2013), FreeBSD 12.0 (2018), Solaris 11.4 (2018), AIX 7.2.5 (2020). #400 was made as a workaround for those who only wanted to enable SO_REUSEPORT on Linux by creating the socket beforehand, and of course, what it does is beyond the SO_REUSEPORT. Therefore, I think it's time to reconsider officially supporting this feature.

References

@saghul @bnoordhuis

For libuv#386, libuv#570, libuv#1229

Relevant issue: nodejs/node#12228

---------

Signed-off-by: Andy Pan <i@andypan.me>
---------

Signed-off-by: Andy Pan <i@andypan.me>
…ameter

---------

Signed-off-by: Andy Pan <i@andypan.me>
src/unix/tcp.c Outdated Show resolved Hide resolved
src/unix/tcp.c Outdated Show resolved Hide resolved
test/test-tcp-reuseport.c Show resolved Hide resolved
---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000 panjf2000 requested a review from saghul May 17, 2024 06:52
Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, good work! Ping @libuv/collaborators for some more reviews.

---------

Signed-off-by: Andy Pan <i@andypan.me>
---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000
Copy link
Contributor Author

panjf2000 commented May 17, 2024

This CI failure on Windows runner seems like a fortuitous thing and it's irrelevant to this PR, right? Could you trigger that failed runner manually? @saghul

Thanks!

Copy link
Member

@santigimeno santigimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you add a very basic test that checks that uv_tcp_bind() returns UV_EOPNOTSUPP on the not supported platforms but succeeds on the others? Thanks

@saghul
Copy link
Member

saghul commented May 17, 2024

Could you trigger that failed runner manually?

Done!

---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000
Copy link
Contributor Author

LGTM. Can you add a very basic test that checks that uv_tcp_bind() returns UV_EOPNOTSUPP on the not supported platforms but succeeds on the others? Thanks

Done!

---------

Signed-off-by: Andy Pan <i@andypan.me>
---------

Signed-off-by: Andy Pan <i@andypan.me>
Copy link
Member

@santigimeno santigimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nits but still LGTM

test/test-tcp-reuseport.c Outdated Show resolved Hide resolved
test/test-tcp-reuseport.c Outdated Show resolved Hide resolved
---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000
Copy link
Contributor Author

Is this PR ready to land? Or is there something unresolved?
@saghul @santigimeno

Copy link
Member

@santigimeno santigimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This missing documentation changes. Can you please add those in https://github.com/libuv/libuv/blob/v1.x/docs/src/tcp.rst? Thanks

@panjf2000
Copy link
Contributor Author

This missing documentation changes. Can you please add those in v1.x/docs/src/tcp.rst? Thanks

Working on it!

---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000
Copy link
Contributor Author

panjf2000 commented May 20, 2024

This missing documentation changes. Can you please add those in v1.x/docs/src/tcp.rst? Thanks

Working on it!

I've made some changes to the docs, PTAL. @santigimeno

---------

Signed-off-by: Andy Pan <i@andypan.me>
@panjf2000 panjf2000 requested a review from saghul May 21, 2024 08:01
@panjf2000
Copy link
Contributor Author

Somehow there are two irrelevant CI failures arising. I assume we need to trigger the GitHub CI manually?

@saghul
Copy link
Member

saghul commented May 21, 2024

Somehow there are two irrelevant CI failures arising. I assume we need to trigger the GitHub CI manually?

Triggered them.

@panjf2000
Copy link
Contributor Author

Somehow there are two irrelevant CI failures arising. I assume we need to trigger the GitHub CI manually?

Triggered them.

Missed the Windows CI?

@saghul
Copy link
Member

saghul commented May 21, 2024

Somehow there are two irrelevant CI failures arising. I assume we need to trigger the GitHub CI manually?

Triggered them.

Missed the Windows CI?

Ups, done!

@panjf2000
Copy link
Contributor Author

Excellent! All CIs have passed, shall we get this PR landed? @saghul @santigimeno

@saghul saghul merged commit d2d92b7 into libuv:v1.x May 21, 2024
38 checks passed
@saghul
Copy link
Member

saghul commented May 21, 2024

Nice work Andy!

@panjf2000 panjf2000 deleted the tcp-reuseport branch May 21, 2024 11:38
panjf2000 added a commit to panjf2000/libuv that referenced this pull request May 22, 2024
Start connecting to the peers after all threads
to poll for accepting connections.

For libuv#4407

---------

Signed-off-by: Andy Pan <i@andypan.me>
saghul pushed a commit that referenced this pull request May 30, 2024
Start connecting to the peers after all threads
to poll for accepting connections.

Ref: #4407
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

Successfully merging this pull request may close these issues.

None yet

3 participants