Commit Graph

10 Commits

Author SHA1 Message Date
Manuel Rüger
992d4c20db plugin/loadbalance: reduce roundRobin allocations for homogeneous address sets (#8375)
* perf(loadbalance): fast-path zero-allocation roundRobin for homogeneous record sets

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

* plugin/loadbalance: copy before shuffling in the fast path

The fast path shuffled the caller's slice in place, which is not safe.
roundRobin must not modify its input: a backend may hand back a slice it
owns rather than one built for the response. plugin/file does exactly that
- Lookup returns elem.Type(qtype), which is the zone tree's own []dns.RR -
so an in-place shuffle reorders the zone itself, visible to every other
query and racing with the ones running concurrently.

Copy the records into a fresh slice and shuffle that instead. This is still
a single allocation rather than the four slices the partitioning path builds,
so most of the gain is kept:

    name          old time/op    new time/op    delta
    RoundRobin      353 ns         244 ns       -31%

    name          old alloc/op   new alloc/op   delta
    RoundRobin      118 B           54 B        -54%

    name          old allocs/op  new allocs/op  delta
    RoundRobin        5              4          -20%

Also reorder the type check so a response led by a CNAME is rejected on the
first record instead of scanning the whole answer section first.

TestRoundRobinDoesNotMutateInput pins the contract; it fails against the
in-place version.

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

---------

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2026-08-19 20:27:35 -07:00
Ville Vesilehto
6720959b8b lint(revive): fix unused-parameter violations (#7980) 2026-03-29 17:02:20 -07:00
Ville Vesilehto
0d05791404 lint: enable nakedret (#7569)
Replace naked returns with explicit return values to satisfy nakedret
linter and improve readability.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-09-21 08:17:35 -07:00
Gabor Dozsa
7da2cedaf0 Add weighted-round-robin policy to loadbalance plugin (#5662)
* Add weighted-round-robin policy to loadbalance plugin

Signed-off-by: Gabor Dozsa <gabor.dozsa@ibm.com>
2023-01-27 11:36:56 -05:00
Ondřej Benkovský
c2dbb7141a add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
John Belamaric
9d41fa663c Do not muck with ordering of XFRs (#2329)
The loadbalancer plugin reorders records. It was doing this for zone
transfers - if you had a CNAME in the zone then your transfer would
be broken because it would get put before the SOA record.
2018-11-21 08:38:19 +01:00
Miek Gieben
0930eb8beb all: fix plugin import ordering (#1717)
Got a bit messed up with stb lib "context" usage.
2018-04-22 08:34:35 +01:00
Miek Gieben
8722336fff global: move to context (#1699)
* global: move to context

Move from golang.org/x/net/context to std lib's context.

Change done with:

for i in $(grep -l '/context' **/*.go); do sed -e 's|golang.org/x/net/context|context|' -i $i; echo $i; done
for i in **/*.go; do goimports -w $i; done

* drop from dns.pb.go as well
2018-04-20 11:01:06 +01:00
Miek Gieben
284061eee7 pkg: add dnstest (#1098)
Add a full test server impl in this new package + tests. Move
dnsrecorder into this package as well and finish up the commented out
tests that were left in the old dnsrecorder package.

Update all callers and tests.
2017-09-21 15:15:47 +01:00
Miek Gieben
d8714e64e4 Remove the word middleware (#1067)
* Rename middleware to plugin

first pass; mostly used 'sed', few spots where I manually changed
text.

This still builds a coredns binary.

* fmt error

* Rename AddMiddleware to AddPlugin

* Readd AddMiddleware to remain backwards compat
2017-09-14 09:36:06 +01:00