Skip to content

Commit

Permalink
ipairs again
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Aug 11, 2023
1 parent 24b6fcf commit 9f55f61
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions kong/runloop/balancer/round_robin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ function roundrobin_algorithm:afterHostUpdate()
local targets = self.balancer.targets or {}

-- calculate the gcd to find the proportional weight of each address
for i = 1, #targets do
local addresses = targets[i].addresses

for j = 1, #addresses do
local address_weight = addresses[j].weight
for _, target in ipairs(targets) do
for _, address in ipairs(target.addresses) do
local address_weight = address.weight
divisor = gcd(divisor, address_weight)
total_weight = total_weight + address_weight
end
Expand All @@ -60,13 +58,9 @@ function roundrobin_algorithm:afterHostUpdate()
local new_wheel = {}
local idx = 1

for i = 1, #targets do
local addresses = targets[i].addresses

for j = 1, #addresses do
local address = addresses[j]
for _, targets in ipairs(targets) do
for _, address in ipairs(targets.addresses) do
local address_points = address.weight / divisor

for _ = 1, address_points do
new_wheel[idx] = address
idx = idx + 1
Expand Down

0 comments on commit 9f55f61

Please sign in to comment.