Documentation
¶
Overview ¶
Package weightedrandom implements a scheduling picker that selects endpoints randomly, where the probability of an endpoint being selected is proportional to its score.
For detailed behavioral intent and configuration, see the package README.
Index ¶
Constants ¶
const (
// WeightedRandomPickerType is the registered name of the weighted random picker plugin.
WeightedRandomPickerType = "weighted-random-picker"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type WeightedRandomPicker ¶
type WeightedRandomPicker struct {
// contains filtered or unexported fields
}
WeightedRandomPicker picks endpoint(s) from the list of candidates based on weighted random sampling using A-Res algorithm. Reference: https://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf.
The picker at its core is picking endpoints randomly, where the probability of the endpoint to get picked is derived from its weighted score. Algorithm: - Uses A-Res (Algorithm for Reservoir Sampling): keyᵢ = Uᵢ^(1/wᵢ) - Selects k items with largest keys for mathematically correct weighted sampling - More efficient than traditional cumulative probability approach
Key characteristics: - Mathematically correct weighted random sampling - Single pass algorithm with O(n + k log k) complexity
func NewWeightedRandomPicker ¶
func NewWeightedRandomPicker(maxNumOfEndpoints int) *WeightedRandomPicker
NewWeightedRandomPicker initializes a new WeightedRandomPicker and returns its pointer.
func (*WeightedRandomPicker) Pick ¶
func (p *WeightedRandomPicker) Pick(ctx context.Context, scoredEndpoints []*fwksched.ScoredEndpoint) *fwksched.ProfileRunResult
Pick selects the endpoint(s) randomly from the list of candidates, where the probability of the endpoint to get picked is derived from its weighted score.
func (*WeightedRandomPicker) TypedName ¶
func (p *WeightedRandomPicker) TypedName() fwkplugin.TypedName
TypedName returns the type and name tuple of this plugin instance.
func (*WeightedRandomPicker) WithName ¶
func (p *WeightedRandomPicker) WithName(name string) *WeightedRandomPicker
WithName sets the name of the picker.