Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak some coefficients #124

Merged
merged 3 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))))
bboreham marked this conversation as resolved.
Show resolved Hide resolved
destinations := make([]PeerName, 0, needed)
for len(destinations) < needed {
// Pick a random point on the distribution and linear search for it
Expand Down