Fetch the repository succeeded.
package serverMgr
import (
"fmt"
"gitee.com/night-tc/gobige/msgdef/protomsg"
)
//防止后续逻辑有修改,先不直接用嵌套了 looby{rand}
// 优先分配小服务ID
type ServerMapByMinID struct {
ServerMapByRand
}
func NewServerMapByMinID() (result *ServerMapByMinID) {
result = new(ServerMapByMinID)
result.Srvli = make(map[uint64]map[uint64]IServerInfo)
return
}
// 根据负载逻辑,获取服务器
func (this *ServerMapByMinID) GetBalancing(stype, groupid uint32) (result IServerInfo, err error) {
this.Lock.RLock()
defer this.Lock.RUnlock()
result = nil
key := uint64(stype)<<32 + uint64(groupid)
if li, ok := this.Srvli[key]; ok {
//优先使用服务器号更小的
for _, v := range li {
if v.GetStatus() != protomsg.ServerStatus_DefaultOK {
continue
}
if result == nil {
result = v
continue
}
if result.GetServerID() > v.GetServerID() {
result = v
continue
}
}
if result != nil {
if result.GetLoad() < 80 {
return result, nil
}
}
//如果最小id服务器负载不满足,这里会使用基本分配规则
for _, v := range li {
if v.GetLoad() < 80 {
return v, nil
}
if result == nil {
result = v
continue
}
if v.GetLoad() < 90 {
if result != nil && result.GetLoad() > v.GetLoad() {
result = v
}
}
}
}
if result == nil {
return result, fmt.Errorf("Server list is empty, Type %d", stype)
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。