js-waku icon indicating copy to clipboard operation
js-waku copied to clipboard

feat: maintain max open connection & prune unhealthy connections from peer store

Open danisharora099 opened this issue 4 months ago • 1 comments

Problem

Currently, js-waku nodes manage to maintain 15-30 connections at the same time when run against TWN, which raises concerns about bandwidth consumption. There is no cap on the number of connections, and without proper connection management, this could result in excessive resource usage, especially as the network grows. Additionally, the PeerStore could grow with unhealthy peers, complicating future dials when connections are needed

Key concerns:

  • No cap on active connections, potentially increasing bandwidth consumption.
  • Peers in the PeerStore may include unhealthy peers that can’t be dialed efficiently when needed.
  • Dialing is necessary to determine if a peer supports the needed protocols, but excessive dials could result in resource wastage.

Proposed Solutions

  • Implement a cap of N active connections
  • Remove unhealthy peers from the PeerStore to avoid attempting dials on unreliable peers. Retain only healthy and dialable peers
    • Implement pruning logic to efficiently scan and filter peers before attempting dials, to ensure only healthy connections are retained
    • Before attempting a dial, use initial filtering based on:
      • Multiaddr supports websockets
      • ENR contains useful information to pre-filter dialable peers
  • Ensure that connections used by critical protocols (e.g., Filter) are never capped or dropped
  • For peers discovered through Peer Exchange, establish connections temporarily, utilize them, and then drop them to maintain the cap

Notes

  • Even though we will prune peers, it’s important to dial peers initially to confirm if they are dialable and then disconnect if they aren’t needed at that time
  • This will also help manage PeerStore more efficiently, especially as the network scales and the number of peers increases

danisharora099 avatar Oct 08 '24 09:10 danisharora099