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
Enable SO_REUSEPORT in ipv6-only environments as well #14748
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kpayson64
approved these changes
Mar 19, 2018
|
yang-g
approved these changes
Mar 19, 2018
|
|
|
|
|
Talked to @adelez and the failures at ""Bazel Debug build for C/C++" are known failures. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SO_REUSEPORT was previously getting disabled in ipv6-only environment due to a bug in our tcp_server_posix.cc code
This was causing significant perf regression in ipv6-only environments..
Relevant background and details
What is SO_REUSEPORT ?
SO_REUSEPORT lets multiple listening sockets bind to same port. If we only had one listening socket and multiple threads were doing
listen()
call on that socket, the OS provided no guarantees on fairly distributing the incoming connections to different threads. SO_REUSEPORT option feature was added so that multiple sockets can all listen on the same port (and different threads can calllisten
on different sockets) (more details here)Why and how is it used in gRPC code
In gRPC server, if SO_REUSEPORT option is available, we create multiple sockets - one per each server completion queue - and add them to the corresponding completion queue's pollset. This way, the threads calling
grpc_completion_queue_next()
on those server completion queueslisten
on multiple sockets (but all of them are bound to the same port)Without this option, we only create one listening socket and added the same socket to all pollsets (corresponding to server completion queues). This means all threads end up listening on the same socket and hence are vulnerable to the load distribution problem described above.
Clearly, using SO_REUSEPORT gives significant performance improvements (and this is why, it is generally enabled in our code - unless we are running on some older kernel version that didn't have this feature)
Bug in our code
In our code, we check whether SO_REUSEPORT option is enabled or not by first creating a socket and then setting that option and checking if the option is correctly set or not.
The API we were using to create socket only created IPV4 sockets. Therefore, this check was failing in Ipv6 environments and we were effectively disabling SO_REUSEPORT option..and causing performance regression.