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

Uneven incoming connection distribution to worker processes with SO_REUSEPORT #142

Closed
ghost opened this issue Nov 25, 2016 · 3 comments
Closed
Assignees

Comments

@ghost
Copy link

ghost commented Nov 25, 2016

The usage for option SO_REUSEPORT was recently updated in
9eb1bc9

However, there is an additional issue with using the specific option in the current-code flow which affect high volume traffic sites being serviced by Hitch.

The initial patch in Linux kernel 3.9 for the said option SO_REUSEPORT does explain the intended use to be a case where we can have multiple (unrelated) processes bind to the same IP:PORT pair if and only if the first process chooses to create the first binding with this specific option enabled and the connection would be distributed among the interest processes based on a hash of source/destination ip:port pairs.

The behavior observed in Debian (Jessie/Whezzy) is that it leads to uneven distribution (pretty skewed) of incoming connection to different worker processes, with the initial/first process get 'most' of the connection (till the RX queue associated with the first core gets full)

@daghf daghf self-assigned this Dec 5, 2016
@ghost
Copy link
Author

ghost commented Dec 6, 2016

Submitted pull request #144 to move front-end listener socket initialisation to individual worker processes. At a beta deployment in production this change seems to have resolved the issue related to uneven distribution of incoming connection across Hitch worker processes.

Took the hint for this change from https://lwn.net/Articles/542629/

"Multiple servers (processes or threads) can bind to the same port if they each set the option as follows:
int sfd = socket(domain, socktype, 0);
int optval = 1;
setsockopt(sfd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
bind(sfd, (struct sockaddr *) &addr, addrlen);"

In order to appropriately use SO_REUSEPORT each worker/thread should have a different socket-handle, this does move away from the current Hitch implementation where we had a socket initialised and bonded only once in master process.

@ghost
Copy link
Author

ghost commented Jan 18, 2017

Any chance of this particular change also being pushed upstream.

@p-id
Copy link

p-id commented Jan 30, 2018

Thanks for taking this up.

I can confirm that this does indeed work and help a bit in current stable Debian derivative production environment since past year or so...

@p-id p-id mentioned this issue Sep 4, 2018
openstack-mirroring pushed a commit to openstack/swift that referenced this issue Sep 3, 2020
We've seen lumpy distributions of requests to workers, which seems to
parallel what some other projects have seen [0][1].

The solution (as best we can tell) is to take advantage of the
SO_REUSEPORT that eventlet's been setting for us since basically
forever [2].

[0] https://lwn.net/Articles/542629/
[1] varnish/hitch#142
[2] eventlet/eventlet@f9a3074a3

Change-Id: I83cdaa2cbd394cbd49609c65bf9c5ed026c55417
openstack-mirroring pushed a commit to openstack/openstack that referenced this issue Sep 3, 2020
* Update swift from branch 'master'
  - Merge "Bind a new socket per-worker"
  - Bind a new socket per-worker
    
    We've seen lumpy distributions of requests to workers, which seems to
    parallel what some other projects have seen [0][1].
    
    The solution (as best we can tell) is to take advantage of the
    SO_REUSEPORT that eventlet's been setting for us since basically
    forever [2].
    
    [0] https://lwn.net/Articles/542629/
    [1] varnish/hitch#142
    [2] eventlet/eventlet@f9a3074a3
    
    Change-Id: I83cdaa2cbd394cbd49609c65bf9c5ed026c55417
@daghf daghf closed this as completed in fb5eeb4 Oct 16, 2020
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

2 participants