Skip to content

Commit 58dbcc3

Browse files
authored
Merge pull request #124 from weaveworks/tweak-coefficients
Tweak some coefficients
2 parents 7c98a18 + 353a1b4 commit 58dbcc3

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

gossip_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func TestRandomNeighbours(t *testing.T) {
294294
// Run randomNeighbours() several times, and count the distribution
295295
for trial := 0; trial < nTrials; trial++ {
296296
targets := r.randomNeighbours(ourself)
297-
expected := int(math.Min(math.Log2(float64(test.nPeers)), float64(test.nNeighbours)))
297+
expected := int(math.Min(2*math.Log2(float64(test.nPeers)), float64(test.nNeighbours)))
298298
require.Equal(t, expected, len(targets))
299299
total += len(targets)
300300
for _, p := range targets {

router.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var (
2424
const (
2525
tcpHeartbeat = 30 * time.Second
2626
maxDuration = time.Duration(math.MaxInt64)
27-
acceptMaxTokens = 100
28-
acceptTokenDelay = 100 * time.Millisecond // [2]
27+
acceptMaxTokens = 20
28+
acceptTokenDelay = 50 * time.Millisecond
2929
)
3030

3131
// Config defines dimensions of configuration for the router.

routes.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ func (r *routes) lookupOrCalculate(name PeerName, broadcast *broadcastRoutes, es
128128
return <-res
129129
}
130130

131-
// RandomNeighbours chooses min(log2(n_peers), n_neighbouring_peers)
131+
// RandomNeighbours chooses min(2 log2(n_peers), n_neighbouring_peers)
132132
// neighbours, with a random distribution that is topology-sensitive,
133133
// favouring neighbours at the end of "bottleneck links". We determine the
134134
// latter based on the unicast routing table. If a neighbour appears as the
135135
// value more frequently than others - meaning that we reach a higher
136136
// proportion of peers via that neighbour than other neighbours - then it is
137137
// chosen with a higher probability.
138138
//
139-
// Note that we choose log2(n_peers) *neighbours*, not peers. Consequently, on
139+
// Note that we choose 2log2(n_peers) *neighbours*, not peers. Consequently, on
140140
// sparsely connected peers this function returns a higher proportion of
141141
// neighbours than elsewhere. In extremis, on peers with fewer than
142142
// log2(n_peers) neighbours, all neighbours are returned.
@@ -152,7 +152,7 @@ func (r *routes) randomNeighbours(except PeerName) []PeerName {
152152
weights[dst]++
153153
}
154154
}
155-
needed := int(math.Min(math.Log2(float64(len(r.unicastAll))), float64(len(weights))))
155+
needed := int(math.Min(2*math.Log2(float64(len(r.unicastAll))), float64(len(weights))))
156156
destinations := make([]PeerName, 0, needed)
157157
for len(destinations) < needed {
158158
// Pick a random point on the distribution and linear search for it

0 commit comments

Comments
 (0)