-
Notifications
You must be signed in to change notification settings - Fork 112
stream: limit the number of peers we sync with on bin 0 #1972
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why limit the number of peers only in bin 0, and not, say also in 1, or - maybe all bins < depth?
- The description of the PR says it's about limiting the number of peers in bin 0 but does not specify how it does that. One has to go through the code.
Maybe it has been discussed in private and is known to the author(s), but as I have been invited to review, I am missing this information, and I had to go through the code.
But what I can see from the code is that actually only concurrent InitPeer
calls are limited, but I understand InitPeer
to run quickly, and is only meant to establish subscriptions. So, after 3 InitPeer
s have run, there is no blocking for other peers, which means they end up in the kademlia in bin 0 anyway, so I don't understand what we really are limiting here - just so that there are not too many concurrent InitPeer
s ?
Bin
The PR description says:
And that exactly what it does. Limits the number of peers we sync with on bin 0 using a semaphore, which is exactly what I added (a semaphore).
@holisticode the buffered channel acts as a semaphore. When a peer that has if po == 0 {
select {
case s.binZeroSem <- struct{}{}:
case <-p.quit:
return
case <-s.quit:
return
}
defer func() { <-s.binZeroSem }()
} Because of the |
What I am saying is that it seems to me that "unspecified time in the future" does only apply if the function for subscription is running as a loop until it disconnects. I thought it was a function which would just establish subscriptions and then return right away (as the So it really depends on the subscription function I guess. To be honest, I am not so much of a fan of this type of blocking, because all peers exceeding the max number of peers in bin 0 (3) will block, and thus unnecessarily use up resources until, at some "unspecified time in the future", one peer would disconnect. |
Which resources are we talking about? a This method of blocking allows you to connect to a peer and have that peer to function correctly with all other protocols except for syncing (other streams in the stream protocol would potentially work uninterrupted in this manner). So you can maintain connectivity with the peer and select when to sync with it without having to connect to it. If you have any better solutions I'm happy to hear them out and implement them gladly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a hack, dont like
do we really need it?
i would not PR it if we would not need it :/ |
This PR aims to limit the number of peers with sync with on bin
0
using a semaphorefixes #1436