Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advise]the improvement on roundrobin. #12

Open
guanglinlv opened this issue Mar 10, 2017 · 1 comment
Open

[Advise]the improvement on roundrobin. #12

guanglinlv opened this issue Mar 10, 2017 · 1 comment

Comments

@guanglinlv
Copy link

@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
@guanglinlv guanglinlv changed the title [Advice]the improvement on roundrobin. [Advise]the improvement on roundrobin. Mar 10, 2017
@kalindudc
Copy link

Possible related consequence of the current implementation: #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants