Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kamran-m committed Aug 8, 2017
1 parent 072d525 commit f8f2139
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
5 changes: 1 addition & 4 deletions peer.go
Expand Up @@ -47,9 +47,6 @@ var (
// ErrNoNewPeers indicates that no previously unselected peer is available.
ErrNoNewPeers = errors.New("no new peer available")

// ErrZeroPeerConnectionCount indicates that the peer connection count is set to zero.
ErrZeroPeerConnectionCount = errors.New("peer connection count must be greater than 0")

peerRng = trand.NewSeeded()
)

Expand Down Expand Up @@ -103,7 +100,7 @@ func (l *PeerList) SetPeerConnectionCount(peerConnectionCount uint32) error {
defer l.Unlock()

if peerConnectionCount == 0 {
return ErrZeroPeerConnectionCount
return errors.New("peer connection count must be greater than 0")
}
l.peerConnectionCount = peerConnectionCount
return nil
Expand Down
32 changes: 6 additions & 26 deletions peer_test.go
Expand Up @@ -716,6 +716,7 @@ func TestPeerRandomSampling(t *testing.T) {
// the higher `peerConnectionCount` is, the smoother the impact of uneven scores
// become as we are random sampling among `peerConnectionCount` peers
{numPeers: 10, peerConnectionCount: 1, distMin: 1000, distMax: 1000},
{numPeers: 10, peerConnectionCount: 2, distMin: 470, distMax: 530},
{numPeers: 10, peerConnectionCount: 5, distMin: 160, distMax: 240},
{numPeers: 10, peerConnectionCount: 10, distMin: 50, distMax: 150},
{numPeers: 10, peerConnectionCount: 15, distMin: 50, distMax: 150},
Expand Down Expand Up @@ -758,35 +759,14 @@ func TestPeerRandomSampling(t *testing.T) {
}

func BenchmarkGetPeerWithPeerConnectionCount1(b *testing.B) {
numPeers := 10
peerConnectionCount := uint32(1)

ch := testutils.NewClient(b, nil)
defer ch.Close()
ch.SetRandomSeed(int64(100))
// Using a strategy that has uneven scores
strategy, _ := createScoreStrategy(0, 1)
ch.Peers().SetStrategy(strategy)
ch.Peers().SetPeerConnectionCount(peerConnectionCount)

for i := 0; i < numPeers; i++ {
hp := fmt.Sprintf("127.0.0.1:60%v", i)
ch.Peers().Add(hp)
}
b.ResetTimer()

for i := 0; i < b.N; i++ {
peer, _ := ch.Peers().Get(nil)
if peer == nil {
fmt.Println("Just a dummy check to guard against compiler optimization")
}
}
doBenchmarkGetPeerWithPeerConnectionCount(b, 10, uint32(1))
}

func BenchmarkGetPeerWithPeerConnectionCount10(b *testing.B) {
numPeers := 10
peerConnectionCount := uint32(10)
doBenchmarkGetPeerWithPeerConnectionCount(b, 10, uint32(10))
}

func doBenchmarkGetPeerWithPeerConnectionCount(b *testing.B, numPeers int, peerConnectionCount uint32) {
ch := testutils.NewClient(b, nil)
defer ch.Close()
ch.SetRandomSeed(int64(100))
Expand All @@ -804,7 +784,7 @@ func BenchmarkGetPeerWithPeerConnectionCount10(b *testing.B) {
for i := 0; i < b.N; i++ {
peer, _ := ch.Peers().Get(nil)
if peer == nil {
fmt.Println("Just a dummy check to guard against compiler optimization")
b.Fatal("Just a dummy check to guard against compiler optimization")
}
}
}
Expand Down

0 comments on commit f8f2139

Please sign in to comment.