Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
Mersher and servicecenter are implemented by go-chassiss.The roundbin load balancing algorithm in go-chassis use function 'pick'.
The function 'pick' in go-chassis use mutex to add cursor value. Can we use sync/atomic to get better performance?
func pick(key string) int {
mu.RLock()
i, ok := rrIdxMap[key]
if !ok {
mu.RUnlock()
mu.Lock()
i, ok = rrIdxMap[key]
if !ok
rrIdxMap[key]++
mu.Unlock()
return i
}
mu.RUnlock()
mu.Lock()
rrIdxMap[key]++
mu.Unlock()
return i
}