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

dnsdist: Random load-balancing of incoming queries on reuseport sockets #13399

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rgacogne
Copy link
Member

Short description

When SO_ATTACH_REUSEPORT_EBPF is available (Linux >= 4.6) along with BPF_FUNC_get_prandom_u32() (Linux >= 4.1), this implements a fully random load-balancing policy between incoming sockets in the same reuseport group (listening address and port, reuseport set). This is needed because Linux implements reuseport load-balancing based on (source IP, source port, destination IP, destination port, protocol), which means that if all queries comes from the same IP and port, and to the same IP and port, they will be distributed to a single worker only, using a single CPU core.

This is a draft pull request to get feedback (@wojas). The current eBPF code is very simple, and is not optimized for NUMA nodes or even just to keep the queries on the local CPU cores, which would be possible. @omoerbeek, @Habbie, if you are interested in using that code in the authoritative server and/or the recursor I'll refactor the eBPF loading code to make it possible.
Note that it is actually possible to replace the eBPF policy from an external program at runtime, but then we need to find a way to let the program know how many sockets we have, and perhaps our CPU affinity. eBPF maps could probably be used to do that.

Related to #8033 and #13327.

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled this code
  • tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)

When `SO_ATTACH_REUSEPORT_EBPF` is available (Linux >= 4.6) along with
`BPF_FUNC_get_prandom_u32()` (Linux >= 4.1), this implements a fully
random load-balancing policy between incoming sockets in the same
`reuseport` group (listening address and port, `reuseport` set).
This is needed because Linux implements `reuseport` load-balancing
based on (source IP, source port, destination IP, destination port,
protocol), which means that if all queries comes from the same IP and
port, and to the same IP and port, they will be distributed to a
single worker only, using a single CPU core.
@coveralls
Copy link

coveralls commented Oct 19, 2023

Pull Request Test Coverage Report for Build 6572957075

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2636 unchanged lines in 60 files lost coverage.
  • Overall coverage decreased (-0.4%) to 57.081%

Files with Coverage Reduction New Missed Lines %
pdns/pollmplexer.cc 1 81.99%
ext/yahttp/yahttp/utility.hpp 2 41.09%
pdns/burtle.hh 2 96.32%
pdns/channel.hh 2 51.75%
pdns/dbdnsseckeeper.cc 2 85.7%
pdns/epollmplexer.cc 2 78.31%
pdns/libssl.hh 2 0.0%
pdns/proxy-protocol.cc 2 73.63%
pdns/remote_logger.hh 2 0.0%
pdns/dnswriter.cc 3 72.7%
Totals Coverage Status
Change from base Build 6546352796: -0.4%
Covered Lines: 71663
Relevant Lines: 107909

💛 - Coveralls

{
#if defined(HAVE_BPF_FUNC_get_prandom_u32) && defined(SO_ATTACH_REUSEPORT_EBPF)
const struct bpf_insn randomReusePortPolicy[] = {
#include "random-reuseport-policy.ebpf"

Check notice

Code scanning / CodeQL

Include header files only Note

The #include pre-processor directive should only be used to include header files.
Copy link
Member Author

Choose a reason for hiding this comment

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

Says who?

Copy link
Member

@Habbie Habbie Oct 19, 2023

Choose a reason for hiding this comment

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

Says who?

AV Rule 32, Joint Strike Fighter Air Vehicle C++ Coding Standards. Lockheed Martin Corporation, 2005.

@omoerbeek
Copy link
Member

IMO, this would be a valuable function to have in the recursor.

@rgacogne rgacogne modified the milestones: dnsdist-1.9, dnsdist-1.10 Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants