Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: closing ping streams #2692

Merged
merged 5 commits into from
May 13, 2024

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented May 10, 2024

Description

We're opening ping streams every 2 minutes but not closing them. This means we get an ever increasing amount of stale streams. Therefore, closing the stream after the ping.

Changes

  • close ping stream after usage

Testing

Tested it by calling

proc connectedPeers*(pm: PeerManager, protocol: string): (seq[PeerId], seq[PeerId]) =
## Returns the peerIds of physical connections (in and out)
## containing at least one stream with the given protocol.
var inPeers: seq[PeerId]
var outPeers: seq[PeerId]
for peerId, muxers in pm.switch.connManager.getConnections():
for peerConn in muxers:
let streams = peerConn.getStreams()
if streams.anyIt(it.protocol == protocol):
if peerConn.connection.transportDir == Direction.In:
inPeers.add(peerId)
elif peerConn.connection.transportDir == Direction.Out:
outPeers.add(peerId)
return (inPeers, outPeers)
and
proc getNumStreams*(pm: PeerManager, protocol: string): (int, int) =
var
numStreamsIn = 0
numStreamsOut = 0
for peerId, muxers in pm.switch.connManager.getConnections():
for peerConn in muxers:
for stream in peerConn.getStreams():
if stream.protocol == protocol:
if stream.dir == Direction.In:
numStreamsIn += 1
elif stream.dir == Direction.Out:
numStreamsOut += 1
return (numStreamsIn, numStreamsOut)

inside keepaliveLoop() and logging the outputs

The conclusions were:

  • without calling conn.close(), the output of getNumStreams() grew indefinitely
  • calling conn.close(), the output of getNumStreams() varied but was stable
  • calling conn.close()did not affect the output of connectedPeers(), which means that indeed it didn't affect the physical connections

Issue

closes #2462

@gabrielmer gabrielmer self-assigned this May 10, 2024
Copy link

github-actions bot commented May 10, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2692-rln-v1

Built from 7a6c35f

Copy link

github-actions bot commented May 10, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2692-rln-v2

Built from 7a6c35f

@gabrielmer gabrielmer changed the title chore: [DEBUG] investigating open ping connections chore: closing ping streams May 10, 2024
@gabrielmer gabrielmer marked this pull request as ready for review May 10, 2024 16:23
@gabrielmer gabrielmer force-pushed the debug-investigating-open-ping-connections branch from 30e0f6d to 115eccd Compare May 10, 2024 16:24
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Isn't this feature is disabled by default?

@gabrielmer
Copy link
Contributor Author

Good catch. Isn't this feature is disabled by default?

Yes! So the feature is disabled by default, but in nwaku-compose we do start the node with keep-alive=true

@AlbertoSoutullo
Copy link

Yes! So the feature is disabled by default, but in nwaku-compose we do start the node with keep-alive=true

Wait, one question so I can understand this. Are you saying that this behavior were happening only if we had the keep-alive flag set to True?

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

Was wondering why we were not seeing this in waku_streams_peers but just realized we only consider waku protocols (ping is excluded).

good catch

@gabrielmer
Copy link
Contributor Author

Wait, one question so I can understand this. Are you saying that this behavior were happening only if we had the keep-alive flag set to True?

Yes, if keep-alive is set to false then we wouldn't open those ping connections every 2 minutes that make the open connections to grow indefinitely

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks! 💯
As a possible future optimization we should only dial once at the beginning and then keep using that connection on further pings

@gabrielmer gabrielmer merged commit 7d4857e into master May 13, 2024
14 of 15 checks passed
@gabrielmer gabrielmer deleted the debug-investigating-open-ping-connections branch May 13, 2024 10:07
@AlbertoSoutullo
Copy link

Yes, if keep-alive is set to false then we wouldn't open those ping connections every 2 minutes that make the open connections to grow indefinitely

Then I will need to doublecheck this in our simulations, because we are not using that flag...

Ivansete-status pushed a commit that referenced this pull request May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: close stale ping connections
5 participants