refactor some lua code
This commit is contained in:
parent
ced6c5bd96
commit
cb4755835e
11 changed files with 83 additions and 47 deletions
|
|
@ -1,6 +1,7 @@
|
|||
local balancer_resty = require("balancer.resty")
|
||||
local resty_chash = require("resty.chash")
|
||||
local util = require("util")
|
||||
local split = require("util.split")
|
||||
|
||||
local _M = balancer_resty:new({ factory = resty_chash, name = "chash" })
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ end
|
|||
function _M.balance(self)
|
||||
local key = util.lua_ngx_var(self.hash_by)
|
||||
local endpoint_string = self.instance:find(key)
|
||||
return util.split_pair(endpoint_string, ":")
|
||||
return split.split_pair(endpoint_string, ":")
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
local resty_lock = require("resty.lock")
|
||||
local util = require("util")
|
||||
local split = require("util.split")
|
||||
|
||||
local DECAY_TIME = 10 -- this value is in seconds
|
||||
local LOCK_KEY = ":ewma_key"
|
||||
|
|
@ -131,10 +132,10 @@ function _M.balance(self)
|
|||
end
|
||||
|
||||
function _M.after_balance(_)
|
||||
local response_time = tonumber(util.get_first_value(ngx.var.upstream_response_time)) or 0
|
||||
local connect_time = tonumber(util.get_first_value(ngx.var.upstream_connect_time)) or 0
|
||||
local response_time = tonumber(split.get_first_value(ngx.var.upstream_response_time)) or 0
|
||||
local connect_time = tonumber(split.get_first_value(ngx.var.upstream_connect_time)) or 0
|
||||
local rtt = connect_time + response_time
|
||||
local upstream = util.get_first_value(ngx.var.upstream_addr)
|
||||
local upstream = split.get_first_value(ngx.var.upstream_addr)
|
||||
|
||||
if util.is_blank(upstream) then
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
local balancer_resty = require("balancer.resty")
|
||||
local resty_roundrobin = require("resty.roundrobin")
|
||||
local util = require("util")
|
||||
local split = require("util.split")
|
||||
|
||||
local _M = balancer_resty:new({ factory = resty_roundrobin, name = "round_robin" })
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ end
|
|||
|
||||
function _M.balance(self)
|
||||
local endpoint_string = self.instance:find()
|
||||
return util.split_pair(endpoint_string, ":")
|
||||
return split.split_pair(endpoint_string, ":")
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
local balancer_resty = require("balancer.resty")
|
||||
local resty_chash = require("resty.chash")
|
||||
local util = require("util")
|
||||
local split = require("util.split")
|
||||
local ck = require("resty.cookie")
|
||||
|
||||
local _M = balancer_resty:new({ factory = resty_chash, name = "sticky" })
|
||||
|
|
@ -74,7 +75,7 @@ end
|
|||
|
||||
function _M.balance(self)
|
||||
local endpoint_string = sticky_endpoint_string(self)
|
||||
return util.split_pair(endpoint_string, ":")
|
||||
return split.split_pair(endpoint_string, ":")
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue