func (rrb *roundrobinBalancer) Distribute() int {
	rrb.mutex.Lock()
	defer rrb.mutex.Unlock()
	for {
		rrb.i = (rrb.i + 1) % rrb.lenOfWeights
		if rrb.i == 0 {
			rrb.cw = rrb.cw - rrb.maxGCD
			if rrb.cw <= 0 {
				rrb.cw = rrb.maxWeight
				if rrb.cw == 0 {
					return 0
				}
			}
		}
		if rrb.weights[rrb.i] >= rrb.cw {
			return rrb.i
		}
	}
}
Distribute to implement round robin algorithm, returns the idx of the choosing in ws ([]W)
TODO(@yeqown): changing to no lock call
package proxy
import (
	"sync"
)
type IBalancer interface {
	Distribute() int
}
type W interface {
	Weight() int
}
type Weight uint
func (w Weight) Weight() int {
	return int(w)
}
func NewBalancer(ws []W) IBalancer {
	rrb := roundrobinBalancer{
		mutex:        sync.Mutex{},
		weights:      make([]int, len(ws)),
		maxWeight:    0,
		maxGCD:       1,
		lenOfWeights: len(ws),
		i:            -1,
		cw:           0,
	}
	tmpGCD := make([]int, 0, rrb.lenOfWeights)
	for idx, w := range ws {
		rrb.weights[idx] = w.Weight()
		if w.Weight() > rrb.maxWeight {
			rrb.maxWeight = w.Weight()
		}
		tmpGCD = append(tmpGCD, w.Weight())
	}
	rrb.maxGCD = nGCD(tmpGCD, rrb.lenOfWeights)
	return &rrb
}
type roundrobinBalancer struct {
	mutex        sync.Mutex
	weights      []int  
	maxWeight    int    
	maxGCD       int    
	lenOfWeights int    
	i            int    
	cw           int    
}