Documentation
¶
Index ¶
- func InitWeightedLB()
- type CostAwareLB
- func (lb *CostAwareLB) GetStats() map[string]interface{}
- func (lb *CostAwareLB) GetWeight(channelID int64) float64
- func (lb *CostAwareLB) RecordFailure(channelID int64)
- func (lb *CostAwareLB) RecordSuccess(channelID int64, responseTimeMs float64)
- func (lb *CostAwareLB) RegisterChannel(channelID int64, baseWeight int, balance float64, costPerToken float64)
- func (lb *CostAwareLB) SelectChannel(channelIDs []int64) int64
- func (lb *CostAwareLB) SetCostWeights(weights CostWeights)
- type CostAwareWeightRecord
- type CostWeights
- type WeightRecord
- type WeightedLB
- func (lb *WeightedLB) GetAllWeights() map[int64]float64
- func (lb *WeightedLB) GetWeight(channelID int64) float64
- func (lb *WeightedLB) RecordFailure(channelID int64)
- func (lb *WeightedLB) RecordSuccess(channelID int64, responseTimeMs float64)
- func (lb *WeightedLB) RegisterChannel(channelID int64, baseWeight int, balance float64)
- func (lb *WeightedLB) RemoveChannel(channelID int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitWeightedLB ¶
func InitWeightedLB()
InitWeightedLB initializes the global WeightedLB instance
Types ¶
type CostAwareLB ¶
type CostAwareLB struct {
// contains filtered or unexported fields
}
CostAwareLB manages cost-aware load balancing
func GetCostAwareLB ¶
func GetCostAwareLB() *CostAwareLB
GetCostAwareLB returns the global cost-aware load balancer
func (*CostAwareLB) GetStats ¶
func (lb *CostAwareLB) GetStats() map[string]interface{}
GetStats returns load balancing statistics
func (*CostAwareLB) GetWeight ¶
func (lb *CostAwareLB) GetWeight(channelID int64) float64
GetWeight calculates and returns the cost-aware weight
func (*CostAwareLB) RecordFailure ¶
func (lb *CostAwareLB) RecordFailure(channelID int64)
RecordFailure records a failed request
func (*CostAwareLB) RecordSuccess ¶
func (lb *CostAwareLB) RecordSuccess(channelID int64, responseTimeMs float64)
RecordSuccess records a successful request with response time
func (*CostAwareLB) RegisterChannel ¶
func (lb *CostAwareLB) RegisterChannel(channelID int64, baseWeight int, balance float64, costPerToken float64)
RegisterChannel registers a channel with cost information
func (*CostAwareLB) SelectChannel ¶
func (lb *CostAwareLB) SelectChannel(channelIDs []int64) int64
SelectChannel selects the best channel based on weights
func (*CostAwareLB) SetCostWeights ¶
func (lb *CostAwareLB) SetCostWeights(weights CostWeights)
SetCostWeights updates the cost weights configuration
type CostAwareWeightRecord ¶
type CostAwareWeightRecord struct {
ChannelID int64
BaseWeight int
DynamicWeight float64
AvgResponseMs float64
SuccessCount int64
FailureCount int64
Balance float64 // 渠道余额
CostPerToken float64 // 上游单价 (USD/1M tokens)
QualityScore float64 // 质量评分 (0-1)
LastUpdated time.Time
}
CostAwareWeightRecord stores cost-aware dynamic weight adjustment data
type CostWeights ¶
type CostWeights struct {
ResponseTime float64 `json:"response_time"`
SuccessRate float64 `json:"success_rate"`
Cost float64 `json:"cost"`
Balance float64 `json:"balance"`
}
CostWeights defines weights for different factors
func CostOptimizedWeights ¶
func CostOptimizedWeights() CostWeights
CostOptimizedWeights returns weights for cost optimization
func DefaultCostWeights ¶
func DefaultCostWeights() CostWeights
DefaultCostWeights returns recommended weights
func PerformanceOptimizedWeights ¶
func PerformanceOptimizedWeights() CostWeights
PerformanceOptimizedWeights returns weights for performance
type WeightRecord ¶
type WeightRecord struct {
ChannelID int64
BaseWeight int
DynamicWeight float64
AvgResponseMs float64
SuccessCount int64
FailureCount int64
Balance float64 // 渠道余额(成本代理)
LastUpdated time.Time
}
WeightRecord stores dynamic weight adjustment data for a channel
type WeightedLB ¶
type WeightedLB struct {
// contains filtered or unexported fields
}
WeightedLB manages dynamic weight adjustment based on response time
func GetWeightedLB ¶
func GetWeightedLB() *WeightedLB
GetWeightedLB returns the global WeightedLB instance
func (*WeightedLB) GetAllWeights ¶
func (lb *WeightedLB) GetAllWeights() map[int64]float64
GetAllWeights returns all channel weights (for debugging)
func (*WeightedLB) GetWeight ¶
func (lb *WeightedLB) GetWeight(channelID int64) float64
GetWeight returns the current dynamic weight for a channel
func (*WeightedLB) RecordFailure ¶
func (lb *WeightedLB) RecordFailure(channelID int64)
RecordFailure records a failed request and reduces weight
func (*WeightedLB) RecordSuccess ¶
func (lb *WeightedLB) RecordSuccess(channelID int64, responseTimeMs float64)
RecordSuccess records a successful request and adjusts weight (lower response time = higher weight)
func (*WeightedLB) RegisterChannel ¶
func (lb *WeightedLB) RegisterChannel(channelID int64, baseWeight int, balance float64)
RegisterChannel registers a channel with its base weight and balance
func (*WeightedLB) RemoveChannel ¶
func (lb *WeightedLB) RemoveChannel(channelID int64)
RemoveChannel removes a channel from tracking