-
Notifications
You must be signed in to change notification settings - Fork 148
Add WeightedRandomPicker #1412
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
base: main
Are you sure you want to change the base?
Add WeightedRandomPicker #1412
Conversation
Implements weighted random sampling picker with 4 normalization options: - None (default): Pure weighted random sampling - Square Root: Moderate score difference reduction - Capping: Limits max score ratio to prevent hot-spotting - Logarithmic: Maximum load distribution for extreme score variations Addresses hot-spotting issues in max-score-picker while maintaining score-based preferences through configurable normalization strategies. Signed-off-by: Jooho Lee <[email protected]>
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Welcome @Jooho! |
Hi @Jooho. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
Signed-off-by: Jooho Lee <[email protected]>
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
randomGenerator.Shuffle(len(scoredPods), func(i, j int) { | ||
scoredPods[i], scoredPods[j] = scoredPods[j], scoredPods[i] | ||
}) | ||
if p.maxNumOfEndpoints < len(scoredPods) { | ||
scoredPods = scoredPods[:p.maxNumOfEndpoints] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part should probably leverage and reuse the existing random picker. there is no point in rewriting the logic.
I think it would be good to have random picker as a private field of the weightedRandomPicker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
type weightedRandomPickerParameters struct { | ||
MaxNumOfEndpoints int `json:"maxNumOfEndpoints"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should remove this and reuse the common picker paramters struct that is used by the other pickers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
pkg/epp/scheduling/framework/plugins/picker/weighted_random_picker.go
Outdated
Show resolved
Hide resolved
…logic Signed-off-by: Jooho Lee <[email protected]>
… all weights are zero Signed-off-by: Jooho Lee <[email protected]>
tests := []struct { | ||
name string | ||
input []*types.ScoredPod | ||
maxPods int // maxNumOfEndpoints for this test | ||
iterations int | ||
expectedProbabilities map[string]float64 // pod name -> expected probability | ||
tolerancePercent float64 // acceptable deviation percentage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way you implemented a probability based test. I think we should give it a try and hopefully we don't see flaky tests in CI.
I have several minor comments:
- can we set iterations as a const or a local variable and just use it across all the tests? I didn't understand why different tests have different number of iterations. also I assume 500 iterations should be enough to have representative results.
- can we move expectedProb to be calculated in the code and not set as input? it looks like magic numbers and this is an easy calculation (summing the scores, dividing score / sum).
- tolerance can also be a local variable or a const, isn't it? why should the tolerance be different between tests?
- nit: I think it's easier to understand if we use tolerance value in the range of [0,1] (instead of dividing by 100).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used 1000 iterations because 500 iterations sometimes make tests fail. The others followed your suggestions
Thx!
/ok-to-test |
continue | ||
} | ||
|
||
// Generate random number U in (0,1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be updated to// Generate random number U in [0.0, 1.0)
here?
It will be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No 0 is always excluded so the existing comment is correct.
u := randomGenerator.Float64()
if u == 0 {
u = 1e-10 // Avoid log(0) #<-- this will be like 0.0000000001
}
Signed-off-by: Jooho Lee <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Jooho The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Implements weighted random sampling picker with 4 normalization options:
Addresses hot-spotting issues in max-score-picker while maintaining score-based preferences through configurable normalization strategies.
Which issue(s) this PR fixes:
Fixes ##1411
Does this PR introduce a user-facing change?: