-
Notifications
You must be signed in to change notification settings - Fork 37
send notifications synchronously #295
base: master
Are you sure you want to change the base?
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.
the other issue is that this is serial as opposed to parallel; not sure it is what we want.
In practice, all notifiees spawn their own goroutine however, so we might be fine.
Still, i'd like @Stebalien 's opinion here.
I agree with that reasoning. If we are worried about misbehaving consumers, perhaps we should add a
For some numerical context on why this is very important; when a libp2p node deals with large amounts of new streams, this particular bit of code accounts for about a third of all allocations, which adds a significant amount of pressure on the runtime:
The above is from a |
These arguments are quite convincing, and i agree pretty much. Still, this is something steven might feel very strongly about, so lets wait on him. |
For sure, happy to wait for the original authors of the code :) Just wanted to add a bit more context. |
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.
You're absolutely correct that we should fix the slow services. Unfortunately, this isn't one of those "change it and see what breaks" cases.
We already know what'll break. The issue here is bitswap. If we make this change, other services will have their disconnect/connect notifications massively delayed by bitswap on the gateways, preload nodes, etc.
Now, I don't actually know if that's a huge issue. But I just don't know.
If we're going to make this change, we need to either:
- Fix bitswap. That should be significantly easier now that we actually have true peer "disconnect" and "connect" events. Unfortunately, bitswap is a bit of a mess.
- Test this change on our infra to see what breaks.
notifyAll
is creating a lot of allocations (and therefore pressure on the GC) by notifying async. This shows up in scenarios where we receive a lot of connections / streams at the same time.-gcflags=-m
confirms why notifyAll is pretty allocation-heavy:Note that there's been some discussion about this a long time ago: #104 (comment). I'd argue though that if there's one misbehaving consumer, we have a problem no matter if we send the notifications sync or async, as
notifyAll
still waits for all notifications to be processed.The real question therefore is if the cost of spawning the go routines is less than what we gain from handling these notifications handled concurrently.
Thanks to @mvdan for his help debugging this.