You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/discoveryregistry/zookeeper/load_balancing.go

27 lines
410 B

package zookeeper
import (
"sync"
"google.golang.org/grpc"
)
type RoundRobin struct {
index int
lock sync.Mutex
}
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn, err error) {
if len(conns) == 0 {
return nil, ErrConnIsNil
}
r.lock.Lock()
defer r.lock.Unlock()
if r.index < len(conns)-1 {
r.index++
} else {
r.index = 0
}
return conns[r.index], nil
}