Skip to content

Commit d30f09f

Browse files
authored
fix(libp2p): reduce dialer activity in browsers (#1970)
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.
1 parent e664d14 commit d30f09f

File tree

4 files changed

+67
-44
lines changed

4 files changed

+67
-44
lines changed

packages/libp2p/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
"sinon-ts": "^1.0.0"
192192
},
193193
"browser": {
194+
"./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js",
194195
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js"
195196
}
196197
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export * from './constants.defaults.js'
2+
3+
/**
4+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials
5+
*/
6+
export const MAX_PARALLEL_DIALS = 10
7+
8+
/**
9+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections
10+
*/
11+
export const MIN_CONNECTIONS = 5
12+
13+
/**
14+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxConnections
15+
*/
16+
export const MAX_CONNECTIONS = 100
17+
18+
/**
19+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency
20+
*/
21+
export const AUTO_DIAL_CONCURRENCY = 10
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout
3+
*/
4+
export const DIAL_TIMEOUT = 30e3
5+
6+
/**
7+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout
8+
*/
9+
export const INBOUND_UPGRADE_TIMEOUT = 30e3
10+
11+
/**
12+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial
13+
*/
14+
export const MAX_PEER_ADDRS_TO_DIAL = 25
15+
16+
/**
17+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
18+
*/
19+
export const MAX_PARALLEL_DIALS_PER_PEER = 10
20+
21+
/**
22+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
23+
*/
24+
export const AUTO_DIAL_INTERVAL = 5000
25+
26+
/**
27+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority
28+
*/
29+
export const AUTO_DIAL_PRIORITY = 0
30+
31+
/**
32+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialMaxQueueLength
33+
*/
34+
export const AUTO_DIAL_MAX_QUEUE_LENGTH = 100
35+
36+
/**
37+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
38+
*/
39+
export const INBOUND_CONNECTION_THRESHOLD = 5
40+
41+
/**
42+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxIncomingPendingConnections
43+
*/
44+
export const MAX_INCOMING_PENDING_CONNECTIONS = 10
Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
1-
/**
2-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout
3-
*/
4-
export const DIAL_TIMEOUT = 30e3
5-
6-
/**
7-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout
8-
*/
9-
export const INBOUND_UPGRADE_TIMEOUT = 30e3
1+
export * from './constants.defaults.js'
102

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

16-
/**
17-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial
18-
*/
19-
export const MAX_PEER_ADDRS_TO_DIAL = 25
20-
21-
/**
22-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
23-
*/
24-
export const MAX_PARALLEL_DIALS_PER_PEER = 10
25-
268
/**
279
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections
2810
*/
@@ -33,32 +15,7 @@ export const MIN_CONNECTIONS = 50
3315
*/
3416
export const MAX_CONNECTIONS = 300
3517

36-
/**
37-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
38-
*/
39-
export const AUTO_DIAL_INTERVAL = 5000
40-
4118
/**
4219
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency
4320
*/
4421
export const AUTO_DIAL_CONCURRENCY = 25
45-
46-
/**
47-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority
48-
*/
49-
export const AUTO_DIAL_PRIORITY = 0
50-
51-
/**
52-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialMaxQueueLength
53-
*/
54-
export const AUTO_DIAL_MAX_QUEUE_LENGTH = 100
55-
56-
/**
57-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
58-
*/
59-
export const INBOUND_CONNECTION_THRESHOLD = 5
60-
61-
/**
62-
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxIncomingPendingConnections
63-
*/
64-
export const MAX_INCOMING_PENDING_CONNECTIONS = 10

0 commit comments

Comments
 (0)