@doujiang24 , the gcd implement is not fair enough, the following is more better:
function _M:next()
local servers=self.servers
local selectedIdx
for i = 1, #servers do
servers[i]['cweight'] = servers[i]['weight'] + severs[i]['cweight']
if not selectedIdx or servers[selectedIdx]['cweight'] < severs[i]['cweight'] then
selectedIdx = i
end
end
servers[selectedIdx]['cweight'] = servers[selectedIdx]['cweight'] - self.totalWeight
return servers[selectedIdx]['name']
end
@doujiang24 , the gcd implement is not fair enough, the following is more better: