Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions model/channel_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ func GetRandomSatisfiedChannel(group string, model string, retry int) (*Channel,
}
// Calculate the total weight of all channels up to endIdx
totalWeight := sumWeight * smoothingFactor

// totalWeight 小于等于0时,给每个渠道加100的权重,然后进行随机选择
if totalWeight <= 0 {
if len(targetChannels) > 0 {
totalWeight = len(targetChannels) * 100
randomWeight := rand.Intn(totalWeight)
for _, channel := range targetChannels {
randomWeight -= 100
if randomWeight <= 0 {
return channel, nil
}
}
}
return nil, errors.New("no available channels")
}
// Generate a random value in the range [0, totalWeight)
randomWeight := rand.Intn(totalWeight)

Expand Down