Update for review
This commit is contained in:
parent
e118ebc08a
commit
06b200fa4b
2 changed files with 11 additions and 3 deletions
|
@ -176,7 +176,6 @@ function _M.balance(self)
|
|||
|
||||
if #peers > 1 then
|
||||
local k = (#peers < PICK_SET_SIZE) and #peers or PICK_SET_SIZE
|
||||
local peer_copy = util.deepcopy(peers)
|
||||
|
||||
local tried_endpoints
|
||||
if not ngx.ctx.balancer_ewma_tried_endpoints then
|
||||
|
@ -187,7 +186,7 @@ function _M.balance(self)
|
|||
end
|
||||
|
||||
local filtered_peers
|
||||
for _, peer in ipairs(peer_copy) do
|
||||
for _, peer in ipairs(peers) do
|
||||
if not tried_endpoints[get_upstream_name(peer)] then
|
||||
if not filtered_peers then
|
||||
filtered_peers = {}
|
||||
|
@ -198,7 +197,7 @@ function _M.balance(self)
|
|||
|
||||
if not filtered_peers then
|
||||
ngx.log(ngx.WARN, "all endpoints have been retried")
|
||||
filtered_peers = peer_copy
|
||||
filtered_peers = util.deepcopy(peers)
|
||||
end
|
||||
|
||||
if #filtered_peers > 1 then
|
||||
|
|
|
@ -106,6 +106,7 @@ describe("Balancer ewma", function()
|
|||
-- even though 10.10.10.1:8080 has a lower ewma score
|
||||
-- algorithm picks 10.10.10.3:8080 because its decayed score is even lower
|
||||
assert.equal("10.10.10.3:8080", peer)
|
||||
assert.equal(true, ngx.ctx.balancer_ewma_tried_endpoints["10.10.10.3:8080"])
|
||||
assert.are.equals(0.16240233988393523723, ngx.var.balancer_ewma_score)
|
||||
end)
|
||||
|
||||
|
@ -114,8 +115,12 @@ describe("Balancer ewma", function()
|
|||
table.remove(two_endpoints_backend.endpoints, 2)
|
||||
local two_endpoints_instance = balancer_ewma:new(two_endpoints_backend)
|
||||
|
||||
ngx.ctx.balancer_ewma_tried_endpoints = {
|
||||
["10.10.10.3:8080"] = true,
|
||||
}
|
||||
local peer = two_endpoints_instance:balance()
|
||||
assert.equal("10.10.10.1:8080", peer)
|
||||
assert.equal(true, ngx.ctx.balancer_ewma_tried_endpoints["10.10.10.1:8080"])
|
||||
end)
|
||||
|
||||
it("all the endpoints are tried, pick the one with lowest score", function()
|
||||
|
@ -123,6 +128,10 @@ describe("Balancer ewma", function()
|
|||
table.remove(two_endpoints_backend.endpoints, 2)
|
||||
local two_endpoints_instance = balancer_ewma:new(two_endpoints_backend)
|
||||
|
||||
ngx.ctx.balancer_ewma_tried_endpoints = {
|
||||
["10.10.10.1:8080"] = true,
|
||||
["10.10.10.3:8080"] = true,
|
||||
}
|
||||
local peer = two_endpoints_instance:balance()
|
||||
assert.equal("10.10.10.3:8080", peer)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue