Skip to content

Commit

Permalink
optimize swrr perf
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Jan 12, 2024
1 parent 25f071d commit aa56680
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions kong/resty/dns_client/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ local function swrr_next(answers)
local best = nil -- best answer in answers[]

for _, answer in ipairs(answers) do
local weight = answer.weight
answer.cw = answer.cw + weight
if not best or answer.cw > best.cw then
local w = answer.weight
local cw = answer.cw + w
answer.cw = cw
if not best or cw > best.cw then
best = answer
end
total = total + weight
total = total + w
end

best.cw = best.cw - total

return best
end

Expand All @@ -113,7 +113,6 @@ local function filter_lowest_priority_answers(answers)
end

answer.l = l

return l
end

Expand Down

0 comments on commit aa56680

Please sign in to comment.