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

[Feature] Weighted round robin load balancing #441

Open
azhard4int opened this issue May 30, 2024 · 1 comment
Open

[Feature] Weighted round robin load balancing #441

azhard4int opened this issue May 30, 2024 · 1 comment

Comments

@azhard4int
Copy link

We are using CHProxy in Usermaven and looking for a weighted round robin load balancing strategy. We want to route high paying customers traffic to the beefy servers.

Describe the solution you'd like
A clear and concise description of what you want to happen.

We would like to implement this feature, a variable with weighted for the servers configuration. We'll implement the weighted round robin load balancing implementation:

Something like this:

func weightedRoundRobin(servers []*Server) *Server {
    var totalWeight int
    var bestServer *Server

    for i := range servers {
        servers[i].mu.Lock()
        if !servers[i].IsHealthy {
            servers[i].mu.Unlock()
            continue
        }
        servers[i].CurrentWeight += servers[i].Weight
        totalWeight += servers[i].Weight

        if bestServer == nil || servers[i].CurrentWeight > bestServer.CurrentWeight {
            bestServer = servers[i]
        }
        servers[i].mu.Unlock()
    }

    if bestServer != nil {
        bestServer.mu.Lock()
        bestServer.CurrentWeight -= totalWeight
        bestServer.mu.Unlock()
    }

    return bestServer
}
@mga-chka
Copy link
Collaborator

mga-chka commented Jun 3, 2024

FYI, we had issues in the past with the load balancing logic.

But, feel free to provide a PR. As long as the weightedRoundRobin is only unsable with a specific flag/option in the conf, it souldn't be an issue. If you need to change the current load balancing business code, the review of the PR might take a while and could be refused (since this part is subtle, and we don't want to break it again).

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

No branches or pull requests

2 participants