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

identify: refactor sending of Identify pushes #1984

Merged
merged 9 commits into from
Feb 8, 2023

Conversation

marten-seemann
Copy link
Contributor

@marten-seemann marten-seemann commented Jan 6, 2023

Fixes #1965.

This is a major refactor of Identify. The general idea here is:

  • Get rid of peerHandler. Adding and removing handlers was not trivial, since we had to deal with (concurrent) disconnect events. Instead of tracking peers, we now track individual connections.
  • The peer handler logic was also consuming one Go routine per connection, making the identify implementation a very heavy resource consumer. We now only spawn a single Go routine for the Identify service, and up to 32 temporary Go routines when we're actually pushing updates (which happens rarely).
  • This refactor will make it pretty straightforward to return IdentifyWait not only when we receive the response for the Identify request, but also when we receive an Identify Push. This will be useful once nodes start pushing Identify right after a connection is established (see Tracking Issue: QUIC 0.5-RTT Optimization #1961 why we want this). Since this PR already contains a bunch of changes, this will be done in a followup PR.
  • I would also claim / hope that this PR fixes the numerous flaky Identify tests.

Fixes #1747. Fixes #1584. Fixes #1523. Fixes #1164. Fixes #1101. Fixes #938.

@marten-seemann marten-seemann changed the base branch from identify-remove-delta to master January 7, 2023 05:51
@p-shahi p-shahi mentioned this pull request Jan 9, 2023
35 tasks
@marten-seemann marten-seemann force-pushed the refactor-identify-push-sending branch 4 times, most recently from c6d5c8b to f5fa030 Compare January 12, 2023 07:22
@@ -528,7 +528,7 @@ func TestLimitedStreams(t *testing.T) {
}

wg.Wait()
if !within(time.Since(before), time.Second*2, time.Second) {
if !within(time.Since(before), time.Second*3, time.Second) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're now more eager to send an Identify Push: We do it even when we don't know if the peer support push yet (i.e. before the initial identify exchange completes). This means that we now have to fit the Identify message through the (bandwidth-limited) pipe as well, which messes with the timing here.

@marten-seemann marten-seemann force-pushed the refactor-identify-push-sending branch 5 times, most recently from 63a38de to e31c6e9 Compare January 13, 2023 05:05
@marten-seemann marten-seemann force-pushed the refactor-identify-push-sending branch 3 times, most recently from b309b9b to 7fae446 Compare February 2, 2023 22:11
@marten-seemann marten-seemann marked this pull request as ready for review February 3, 2023 00:48
@marten-seemann
Copy link
Contributor Author

Fixed (hopefully) all of the flaky tests. This is ready for review now.

p2p/protocol/identify/id.go Show resolved Hide resolved
if err != nil { // connection might have been closed recently
return
}
// TODO: find out if the peer supports push if we didn't have any information about push support
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you want to handle this TODO? Should be as easy as checking the error returned either above or below (or both?)

p2p/protocol/identify/id.go Outdated Show resolved Hide resolved
p2p/protocol/identify/id.go Outdated Show resolved Hide resolved
ids.currentSnapshot.Lock()
snapshot := ids.currentSnapshot.snapshot
ids.currentSnapshot.Unlock()
if !e.Timestamp.Before(snapshot.timestamp) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Who updates e.Timestamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now done in sendIdentifyResp. Not sure how to properly test it though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A unit test that makes sure we have the timestamp in the connection after doing an identify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to test behavior, not implementation specifics.

@MarcoPolo
Copy link
Collaborator

The peer handler logic was also consuming one Go routine per connection, making the identify implementation a very heavy resource consumer. We now only spawn a single Go routine for the Identify service, and up to 32 temporary Go routines when we're actually pushing updates (which happens rarely).

It's not a long lived Go routine, but this still spawns a Go routine per connection to drive the identify. I think this is okay since it's bounded by the number of connections we have.

@marten-seemann
Copy link
Contributor Author

The peer handler logic was also consuming one Go routine per connection, making the identify implementation a very heavy resource consumer. We now only spawn a single Go routine for the Identify service, and up to 32 temporary Go routines when we're actually pushing updates (which happens rarely).

It's not a long lived Go routine, but this still spawns a Go routine per connection to drive the identify. I think this is okay since it's bounded by the number of connections we have.

It's limited by a semaphore, so we only spawn a maximum of 32 Go routines (plus the one that's driving the respective round of Identify Push), no matter how many connections we're actually handling.

@marten-seemann marten-seemann merged commit 235f25b into master Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants