Skip to content

Commit

Permalink
HashRingSelector made faster
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Biin committed Aug 27, 2016
1 parent ff4aa95 commit 971b978
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 34 deletions.
2 changes: 1 addition & 1 deletion example/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
go echoLoop(l3)

for {
var echoReq, dialErr = astraNet3.Dial("", "skynet2")
var echoReq, dialErr = astraNet3.Dial("vport2registry", "skynet2:10000")
if dialErr != nil {
panic(dialErr)
}
Expand Down
16 changes: 8 additions & 8 deletions registry/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ func (hrs HashRingSelector) Select(pool []generic.U) (idx int) {
if hrs.VBucket == 0 {
return int(rand.Int31n(int32(len(pool))))
}
var hr = consistent.New()

var hr, psMap = consistent.New(), make(map[string]int, len(pool))
hr.NumberOfReplicas = 1024
var psMap = make(map[string]int, len(pool))
var repr = make([]string, 0, len(pool))
for idx, p := range pool {
var pRepr = fmt.Sprint(p)
if _, found := psMap[pRepr]; found {
panic("Inconsistent string repr")
}
psMap[pRepr] = idx
hr.Add(pRepr)
var pS = fmt.Sprint(p)
repr = append(repr, pS)
psMap[pS] = idx
}
hr.Set(repr)

var idKey, _ = hr.Get(strconv.Itoa(hrs.VBucket))
return psMap[idKey]
}
Expand Down
16 changes: 8 additions & 8 deletions route/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ func (hrs HashRingSelector) Select(pool []RouteInfo) (idx int) {
if hrs.VBucket == 0 {
return int(rand.Int31n(int32(len(pool))))
}
var hr = consistent.New()

var hr, psMap = consistent.New(), make(map[string]int, len(pool))
hr.NumberOfReplicas = 1024
var psMap = make(map[string]int, len(pool))
var repr = make([]string, 0, len(pool))
for idx, p := range pool {
var pRepr = fmt.Sprint(p)
if _, found := psMap[pRepr]; found {
panic("Inconsistent string repr")
}
psMap[pRepr] = idx
hr.Add(pRepr)
var pS = fmt.Sprint(p)
repr = append(repr, pS)
psMap[pS] = idx
}
hr.Set(repr)

var idKey, _ = hr.Get(strconv.Itoa(hrs.VBucket))
return psMap[idKey]
}
Expand Down
16 changes: 8 additions & 8 deletions service/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ func (hrs HashRingSelector) Select(pool []ServiceInfo) (idx int) {
if hrs.VBucket == 0 {
return int(rand.Int31n(int32(len(pool))))
}
var hr = consistent.New()

var hr, psMap = consistent.New(), make(map[string]int, len(pool))
hr.NumberOfReplicas = 1024
var psMap = make(map[string]int, len(pool))
var repr = make([]string, 0, len(pool))
for idx, p := range pool {
var pRepr = fmt.Sprint(p)
if _, found := psMap[pRepr]; found {
panic("Inconsistent string repr")
}
psMap[pRepr] = idx
hr.Add(pRepr)
var pS = fmt.Sprint(p)
repr = append(repr, pS)
psMap[pS] = idx
}
hr.Set(repr)

var idKey, _ = hr.Get(strconv.Itoa(hrs.VBucket))
return psMap[idKey]
}
Expand Down
6 changes: 3 additions & 3 deletions transport/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (self *Router) CloseHandle(filter Filter, el *list.Element) {
var eMap = self.cbMap[filter]
if eMap != nil {
eMap.Remove(el)
}
if eMap.Len() == 0 {
delete(self.cbMap, filter)
if eMap.Len() == 0 {
delete(self.cbMap, filter)
}
}
self.cbLock.Unlock()
}
Expand Down
7 changes: 1 addition & 6 deletions vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,24 @@
{
"importpath": "github.com/cenk/backoff",
"repository": "https://github.com/cenk/backoff",
"vcs": "",
"revision": "cdf48bbc1eb78d1349cbda326a4a037f7ba565c6",
"branch": "master"
},
{
"importpath": "github.com/stathat/consistent",
"repository": "https://github.com/stathat/consistent",
"vcs": "",
"revision": "748f01b59d1b2218efe39513039e9ee31266d7c7",
"branch": "master"
},
{
"importpath": "github.com/zenhotels/btree-2d",
"repository": "https://github.com/zenhotels/btree-2d",
"vcs": "git",
"revision": "61901d6b1c202c811230766280183784276c9657",
"branch": "master",
"notests": true
"branch": "master"
},
{
"importpath": "stathat.com/c/consistent",
"repository": "https://github.com/stathat/consistent",
"vcs": "",
"revision": "748f01b59d1b2218efe39513039e9ee31266d7c7",
"branch": "master"
}
Expand Down

0 comments on commit 971b978

Please sign in to comment.