Navigation Menu

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

Enable SO_REUSEPORT in ipv6-only environments as well #14748

Merged
merged 2 commits into from Mar 20, 2018

Conversation

sreecha
Copy link
Contributor

@sreecha sreecha commented Mar 19, 2018

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 call listen 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 queues listen 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.

@grpc-testing
Copy link

****************************************************************

libgrpc.so

     VM SIZE                                              FILE SIZE
 ++++++++++++++ GROWING                                ++++++++++++++
  +0.3%     +16 src/core/lib/iomgr/tcp_server_posix.cc     +16  +0.3%
       +28%     +23 init                                       +23   +28%

 -+-+-+-+-+-+-+ MIXED                                  +-+-+-+-+-+-+-
  -0.0%     -16 [None]                                     +56  +0.0%

  [ = ]       0 TOTAL                                      +72  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link

[trickle] No significant performance differences

@grpc-testing
Copy link

[microbenchmarks] No significant performance differences

@grpc-testing
Copy link

****************************************************************

libgrpc.so

     VM SIZE                                              FILE SIZE
 ++++++++++++++ GROWING                                ++++++++++++++
  +0.3%     +16 src/core/lib/iomgr/tcp_server_posix.cc     +16  +0.3%
       +28%     +23 init                                       +23   +28%

 -+-+-+-+-+-+-+ MIXED                                  +-+-+-+-+-+-+-
  -0.0%     -16 [None]                                     +56  +0.0%

  [ = ]       0 TOTAL                                      +72  +0.0%


****************************************************************

libgrpc++.so

     VM SIZE        FILE SIZE
 ++++++++++++++  ++++++++++++++

  [ = ]       0        0  [ = ]



@grpc-testing
Copy link

[trickle] No significant performance differences

@grpc-testing
Copy link

[microbenchmarks] No significant performance differences

@sreecha
Copy link
Contributor Author

sreecha commented Mar 20, 2018

Talked to @adelez and the failures at ""Bazel Debug build for C/C++" are known failures.
All other tests passed. Merging.

@sreecha sreecha merged commit 3136dd3 into grpc:master Mar 20, 2018
@sreecha sreecha deleted the fix_reuseport branch March 20, 2018 17:50
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants