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

Initial load balancing support and test changes #10

Merged
merged 1 commit into from
Jan 8, 2023

Conversation

wjhoward
Copy link
Owner

No description provided.

@wjhoward wjhoward requested a review from khvzak December 31, 2022 20:57
@wjhoward wjhoward self-assigned this Dec 31, 2022
@wjhoward wjhoward merged commit 5feacc7 into main Jan 8, 2023
@wjhoward wjhoward deleted the initial-load-balancing branch January 8, 2023 13:20
Comment on lines 40 to 44
fn match_backend<'a>(backends: &'a [Backend], host_header: &str) -> Option<&'a Backend> {
backends
.iter()
.find(|&backend| backend.name.is_some() && host_header == backend.name.clone().unwrap())
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can compare backend.name.as_deref() == Some(host_header) without cloning.

let backend = match_backend(backends, host_header)?;

// Check if load balancing is enabled
if backend.backend_type.is_some() && backend.backend_type.clone()? == "loadbalanced" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to clone, see comment for match_backend

Comment on lines 46 to 50
fn round_robin_select(backend_name: String, backends: &Vec<String>) -> Option<String> {
// Uses the rr_counter to keep an index of the next backend to select.
// This counter is incremented or reset to zero when exceeding the number of backends
let backend_count = backends.len();
let mut rr_map = RR_COUNTER.lock().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need global counter at all, also this approach can be incorrect under some edge cases.

Would be better to add atomic counter into Backend struct to track number of requests.

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

Successfully merging this pull request may close these issues.

2 participants