Skip to content

Commit

Permalink
Merge pull request #124 from weaveworks/tweak-coefficients
Browse files Browse the repository at this point in the history
Tweak some coefficients
  • Loading branch information
bboreham committed Nov 5, 2019
2 parents 7c98a18 + 353a1b4 commit 58dbcc3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestRandomNeighbours(t *testing.T) {
// Run randomNeighbours() several times, and count the distribution
for trial := 0; trial < nTrials; trial++ {
targets := r.randomNeighbours(ourself)
expected := int(math.Min(math.Log2(float64(test.nPeers)), float64(test.nNeighbours)))
expected := int(math.Min(2*math.Log2(float64(test.nPeers)), float64(test.nNeighbours)))
require.Equal(t, expected, len(targets))
total += len(targets)
for _, p := range targets {
Expand Down
4 changes: 2 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var (
const (
tcpHeartbeat = 30 * time.Second
maxDuration = time.Duration(math.MaxInt64)
acceptMaxTokens = 100
acceptTokenDelay = 100 * time.Millisecond // [2]
acceptMaxTokens = 20
acceptTokenDelay = 50 * time.Millisecond
)

// Config defines dimensions of configuration for the router.
Expand Down
6 changes: 3 additions & 3 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ func (r *routes) lookupOrCalculate(name PeerName, broadcast *broadcastRoutes, es
return <-res
}

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

0 comments on commit 58dbcc3

Please sign in to comment.