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

Improve load balancing of App Proxy #3196

Open
achimnol opened this issue Dec 4, 2024 · 0 comments
Open

Improve load balancing of App Proxy #3196

achimnol opened this issue Dec 4, 2024 · 0 comments
Labels
comp:appproxy Related to App Proxy component urgency:4 As soon as feasible, implementation is essential.
Milestone

Comments

@achimnol
Copy link
Member

achimnol commented Dec 4, 2024

Currently we are using a uniform random variable to choose a route from the weighted route list.
The current implementation is a our own Python logic, but this could be optimized by replacing it with random.choices() which is provided as a native C implementation in CPython.

Also, let's add an option to switch the load balancing algorithm to introduce a proper weighted round robin with shuffling as follows:

weights = {
  a: 2.5,
  b: 1.2,
  c: 1.0,
}
multiplier = 10
shuffle_period = 5
route_decisions = [
  route * int(weights[r] * multiplier) for route, weight in routes.items()
]
random.shuffle(route_decisions)

current_choice = 0
pass_count = 0

def select_route():
  global current_choice, pass_count
  selected_route = route_decisions[current_choice]
  current_choice = (current_choice + 1) % len(route_decisions)
  # periodically re-shuffle
  if current_choice == 0:
    pass_count = (pass_count + 1) % shuffle_period
    if pass_count == 0:
      random.shuffle(route_decisions)
  return selected_route

The advantages of WRR are:

  • Ensures all routes are used during one iteration of route_decisions.
  • Prevents probabilistic imbalance, like that a route is excessively selected or vice versa.

As there are several adjustable parameters like multiplier and shuffle_period, I'd suggest to add configurations for load balancing in App Proxy.

@achimnol achimnol added the comp:appproxy Related to App Proxy component label Dec 4, 2024
@achimnol achimnol added this to the 24.09 milestone Dec 4, 2024
@achimnol achimnol added the urgency:4 As soon as feasible, implementation is essential. label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:appproxy Related to App Proxy component urgency:4 As soon as feasible, implementation is essential.
Projects
None yet
Development

No branches or pull requests

1 participant