[ 
https://issues.apache.org/jira/browse/SCB-1414?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

chenshuo updated SCB-1414:
--------------------------
    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 {
 i = rand.Int()
 rrIdxMap[key] = i
 }
 rrIdxMap[key]++
 mu.Unlock()
 return i
 }

 mu.RUnlock()
 mu.Lock()
 rrIdxMap[key]++
 mu.Unlock()
 return i
}
        Summary:  Roundbin load balancing algorithm optimizes performance  by 
using sync/atomic instead of mutex.  (was: The loadbalanceroundbin )

>  Roundbin load balancing algorithm optimizes performance  by using 
> sync/atomic instead of mutex.
> ------------------------------------------------------------------------------------------------
>
>                 Key: SCB-1414
>                 URL: https://issues.apache.org/jira/browse/SCB-1414
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>            Reporter: chenshuo
>            Priority: Major
>
> 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 {
>  i = rand.Int()
>  rrIdxMap[key] = i
>  }
>  rrIdxMap[key]++
>  mu.Unlock()
>  return i
>  }
>  mu.RUnlock()
>  mu.Lock()
>  rrIdxMap[key]++
>  mu.Unlock()
>  return i
> }



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to