Skip to content

Commit

Permalink
fix(libp2p): reduce dialer activity in browsers (#1970)
Browse files Browse the repository at this point in the history
Use a different set of defaults for browsers vs node - from testing
we never really see more than 20x connections so there's no point
having the auto-dialler trying to reach 50x, also reduce the number
of concurrent dials and how many peers we try to autodial at once.

This is to reduce overall CPU usage in order to make existing
connections more stable.
  • Loading branch information
achingbrain authored Aug 15, 2023
1 parent e664d14 commit d30f09f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 44 deletions.
1 change: 1 addition & 0 deletions packages/libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"sinon-ts": "^1.0.0"
},
"browser": {
"./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js",
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js"
}
}
21 changes: 21 additions & 0 deletions packages/libp2p/src/connection-manager/constants.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export * from './constants.defaults.js'

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials
*/
export const MAX_PARALLEL_DIALS = 10

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections
*/
export const MIN_CONNECTIONS = 5

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxConnections
*/
export const MAX_CONNECTIONS = 100

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency
*/
export const AUTO_DIAL_CONCURRENCY = 10
44 changes: 44 additions & 0 deletions packages/libp2p/src/connection-manager/constants.defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout
*/
export const DIAL_TIMEOUT = 30e3

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout
*/
export const INBOUND_UPGRADE_TIMEOUT = 30e3

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial
*/
export const MAX_PEER_ADDRS_TO_DIAL = 25

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
*/
export const MAX_PARALLEL_DIALS_PER_PEER = 10

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
*/
export const AUTO_DIAL_INTERVAL = 5000

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority
*/
export const AUTO_DIAL_PRIORITY = 0

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialMaxQueueLength
*/
export const AUTO_DIAL_MAX_QUEUE_LENGTH = 100

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
*/
export const INBOUND_CONNECTION_THRESHOLD = 5

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxIncomingPendingConnections
*/
export const MAX_INCOMING_PENDING_CONNECTIONS = 10
45 changes: 1 addition & 44 deletions packages/libp2p/src/connection-manager/constants.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout
*/
export const DIAL_TIMEOUT = 30e3

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout
*/
export const INBOUND_UPGRADE_TIMEOUT = 30e3
export * from './constants.defaults.js'

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials
*/
export const MAX_PARALLEL_DIALS = 100

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial
*/
export const MAX_PEER_ADDRS_TO_DIAL = 25

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
*/
export const MAX_PARALLEL_DIALS_PER_PEER = 10

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections
*/
Expand All @@ -33,32 +15,7 @@ export const MIN_CONNECTIONS = 50
*/
export const MAX_CONNECTIONS = 300

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
*/
export const AUTO_DIAL_INTERVAL = 5000

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency
*/
export const AUTO_DIAL_CONCURRENCY = 25

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority
*/
export const AUTO_DIAL_PRIORITY = 0

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialMaxQueueLength
*/
export const AUTO_DIAL_MAX_QUEUE_LENGTH = 100

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
*/
export const INBOUND_CONNECTION_THRESHOLD = 5

/**
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxIncomingPendingConnections
*/
export const MAX_INCOMING_PENDING_CONNECTIONS = 10

0 comments on commit d30f09f

Please sign in to comment.