Skip to content

Commit

Permalink
Merge pull request #568 from oceanprotocol/issue-optimize-cpu
Browse files Browse the repository at this point in the history
improve peer discovery time, avoid connect again on connection handler
  • Loading branch information
alexcos20 authored Aug 14, 2024
2 parents 2f6e729 + 886c74e commit 4febd84
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion env.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
- `P2P_ipV6BindWsPort`: Port used on IPv6 WS connections. Defaults to `0` (Use whatever port is free. When running as docker, please set it explicitly). Example: `0`
- `P2P_ANNOUNCE_ADDRESSES`: List of addresses to announce to the network. Example: `"[\"/ip4/1.2.3.4/tcp/8000\"]"`
- `P2P_ANNOUNCE_PRIVATE`: Announce private IPs. Default: `True`
- `P2P_pubsubPeerDiscoveryInterval`: Interval (in ms) for discovery using pubsub. Defaults to `1000` (one second). Example: `1000`
- `P2P_pubsubPeerDiscoveryInterval`: Interval (in ms) for discovery using pubsub. Defaults to `3000` (three seconds). Example: `3000`
- `P2P_dhtMaxInboundStreams`: Maximum number of DHT inbound streams. Defaults to `500`. Example: `500`
- `P2P_dhtMaxOutboundStreams`: Maximum number of DHT outbound streams. Defaults to `500`. Example: `500`
- `P2P_mDNSInterval`: Interval (in ms) for discovery using mDNS. Defaults to `20000` (20 seconds). Example: `20000`
Expand All @@ -64,6 +64,7 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
- `P2P_AUTODIALPEERRETRYTHRESHOLD`: When we've failed to dial a peer, do not autodial them again within this number of ms. Default: 1000 \* 120
- `P2P_AUTODIALCONCURRENCY`: When dialling peers from the peer book to keep the number of open connections, add dials for this many peers to the dial queue at once. Default: 5
- `P2P_MAXPEERADDRSTODIAL`: Maximum number of addresses allowed for a given peer before giving up. Default: 5
- `P2P_AUTODIALINTERVAL`: Auto dial interval (miliseconds). Amount of time between close and open of new peer connection. Default: 5000

## Additional Nodes (Test Environments)

Expand Down
1 change: 1 addition & 0 deletions src/@types/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface OceanNodeP2PConfig {
autoDialPeerRetryThreshold: number
autoDialConcurrency: number
maxPeerAddrsToDial: number
autoDialInterval: number
}

export interface OceanNodeConfig {
Expand Down
12 changes: 5 additions & 7 deletions src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,9 @@ export class OceanP2P extends EventEmitter {
if (details) {
const peerId = details.detail
P2P_LOGGER.debug('Connection established to:' + peerId.toString()) // Emitted when a peer has been found
try {
// DO WE REALLY NEED THIS?
this._libp2p.services.pubsub.connect(peerId.toString())
} catch (e) {
P2P_LOGGER.error(e.message)
}
// try {
// this._libp2p.services.pubsub.connect(peerId.toString())
// } catch (e) {}
}
}

Expand Down Expand Up @@ -335,7 +332,8 @@ export class OceanP2P extends EventEmitter {
maxConnections: config.p2pConfig.maxConnections,
autoDialPeerRetryThreshold: config.p2pConfig.autoDialPeerRetryThreshold,
autoDialConcurrency: config.p2pConfig.autoDialConcurrency,
maxPeerAddrsToDial: config.p2pConfig.maxPeerAddrsToDial
maxPeerAddrsToDial: config.p2pConfig.maxPeerAddrsToDial,
autoDialInterval: config.p2pConfig.autoDialInterval
}
}
if (config.p2pConfig.bootstrapNodes && config.p2pConfig.bootstrapNodes.length > 0) {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
),
pubsubPeerDiscoveryInterval: getIntEnvValue(
process.env.P2P_pubsubPeerDiscoveryInterval,
1000
3000 // every 3 seconds
),
dhtMaxInboundStreams: getIntEnvValue(process.env.P2P_dhtMaxInboundStreams, 500),
dhtMaxOutboundStreams: getIntEnvValue(process.env.P2P_dhtMaxOutboundStreams, 500),
Expand Down Expand Up @@ -539,7 +539,8 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
1000 * 120
),
autoDialConcurrency: getIntEnvValue(process.env.P2P_AUTODIALCONCURRENCY, 5),
maxPeerAddrsToDial: getIntEnvValue(process.env.P2P_MAXPEERADDRSTODIAL, 5)
maxPeerAddrsToDial: getIntEnvValue(process.env.P2P_MAXPEERADDRSTODIAL, 5),
autoDialInterval: getIntEnvValue(process.env.P2P_AUTODIALINTERVAL, 5000)
},
// Only enable provider if we have a DB_URL
hasProvider: !!getEnvValue(process.env.DB_URL, ''),
Expand Down

0 comments on commit 4febd84

Please sign in to comment.