Merge pull request #4272 from ElvinEfendi/balancer-ewma-score-var
introduce ngx.var.balancer_ewma_score
This commit is contained in:
commit
05e764be2c
2 changed files with 6 additions and 3 deletions
|
@ -73,19 +73,21 @@ local function pick_and_score(self, peers, k)
|
||||||
lowest_score_index, lowest_score = i, new_score
|
lowest_score_index, lowest_score = i, new_score
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return peers[lowest_score_index]
|
return peers[lowest_score_index], lowest_score
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.balance(self)
|
function _M.balance(self)
|
||||||
local peers = self.peers
|
local peers = self.peers
|
||||||
local endpoint = peers[1]
|
local endpoint, score = peers[1], -1
|
||||||
|
|
||||||
if #peers > 1 then
|
if #peers > 1 then
|
||||||
local k = (#peers < PICK_SET_SIZE) and #peers or PICK_SET_SIZE
|
local k = (#peers < PICK_SET_SIZE) and #peers or PICK_SET_SIZE
|
||||||
local peer_copy = util.deepcopy(peers)
|
local peer_copy = util.deepcopy(peers)
|
||||||
endpoint = pick_and_score(self, peer_copy, k)
|
endpoint, score = pick_and_score(self, peer_copy, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ngx.var.balancer_ewma_score = score
|
||||||
|
|
||||||
-- TODO(elvinefendi) move this processing to _M.sync
|
-- TODO(elvinefendi) move this processing to _M.sync
|
||||||
return endpoint.address .. ":" .. endpoint.port
|
return endpoint.address .. ":" .. endpoint.port
|
||||||
end
|
end
|
||||||
|
|
|
@ -1090,6 +1090,7 @@ stream {
|
||||||
|
|
||||||
port_in_redirect {{ if $location.UsePortInRedirects }}on{{ else }}off{{ end }};
|
port_in_redirect {{ if $location.UsePortInRedirects }}on{{ else }}off{{ end }};
|
||||||
|
|
||||||
|
set $balancer_ewma_score -1;
|
||||||
set $proxy_upstream_name "{{ buildUpstreamName $location }}";
|
set $proxy_upstream_name "{{ buildUpstreamName $location }}";
|
||||||
set $proxy_host $proxy_upstream_name;
|
set $proxy_host $proxy_upstream_name;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue