Skip to content

Commit

Permalink
EVM-525 Write load test for adding peers (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed May 24, 2023
1 parent ef089fb commit 96d0d89
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
7 changes: 5 additions & 2 deletions network/server_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ func (s *Server) setupDiscovery() error {

// Set the PeerAdded event handler
routingTable.PeerAdded = func(p peer.ID) {
info := s.host.Peerstore().PeerInfo(p)
s.addToDialQueue(&info, common.PriorityRandomDial)
// this is called from the lock. because of that execute addToDialQueue on separated routine
go func() {
info := s.host.Peerstore().PeerInfo(p)
s.addToDialQueue(&info, common.PriorityRandomDial)
}()
}

// Set the PeerRemoved event handler
Expand Down
2 changes: 0 additions & 2 deletions network/server_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func (s *Server) AddPeer(id peer.ID, direction network.Direction) {

// Emit the event alerting listeners
// WARNING: THIS CALL IS POTENTIALLY BLOCKING
// UNDER HEAVY LOAD. IT SHOULD BE SUBSTITUTED
// WITH AN EVENT SYSTEM THAT ACTUALLY WORKS
s.emitEvent(id, peerEvent.PeerConnected)
}

Expand Down
8 changes: 1 addition & 7 deletions network/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,13 +1025,7 @@ func TestPeerAdditionDeletion(t *testing.T) {
}

t.Run("peers are added correctly", func(t *testing.T) {
server := createServer()

//nolint:godox
// TODO increase this number to something astronomical
// when the networking package has an event system that actually works,
// as emitEvent can completely bug out when under load inside Server.AddPeer (to be fixed in EVM-525)
generateAndAddPeers(server, 10)
generateAndAddPeers(createServer(), 2500)
})

t.Run("no duplicate peers added", func(t *testing.T) {
Expand Down

0 comments on commit 96d0d89

Please sign in to comment.