feat(prove_membership_relative_to_smaller_mmr): add spawn_blocking#937
feat(prove_membership_relative_to_smaller_mmr): add spawn_blocking#937skaunov wants to merge 1 commit into
prove_membership_relative_to_smaller_mmr): add spawn_blocking#937Conversation
less starving the caller thread while parallelizing `PeerLoopHandler::batch_response`
f11889b to
7f01499
Compare
spawn_blocking to prove_membership_relative_to_smaller_mmrprove_membership_relative_to_smaller_mmr): add spawn_blocking
| let node_indices = | ||
| tokio::task::spawn_blocking(move || auth_path_node_indices(num_leafs, leaf_index)) | ||
| .await?; | ||
| let ap_elements = self.digests.get_many(&node_indices).await; |
There was a problem hiding this comment.
Does this actually make a difference? Will the peer_loop not just stay blocked, waiting for the spawned task to finish? Each peer loop already runs in their own, individual tasks (read: thread), so the call to auth_path_node_indices doesn't block other peer loops.
There was a problem hiding this comment.
Thank you for the context! I did not think about it from that angle: it just looked to me as a book example of spawn_blocking though I'm not sure if this is computational enough (though seems so to me, or I would not bother). X)
So about the tasks. Ain't a scheduler expects a task to yield anyway, and while it only brute blocking its own task (though this is just a function: it can be used in the other contexts), it still a bit starves its scheduler as it's not happy to do its job along computing this thing? Sorry for such a long question but it's sincere question.
P.s. I got into auth_path_node_indices once more, and now feel like I overestimated it computations. So I'm confused on this terminally. Thank you for bearing with me here!
|
Not convinced of this. Please reopen if you see a good reason to. |
|
IIRC there are quite few level of indirection in the function to quickly grasp what amount of computing does it do. That's why I was asking your help to wrap my head around this. I mean would be glad to understand this better. Until then let me just assume that as the thing is generally logarithmic it's a non-issue. (Though from the place where the changes are proposed it look like textbook candidate for this to not get in the way for example of work stealing.) |
|
The function looks incredibly fast to me. You could benhcmark the function if you think I'm wrong. If you're looking for bottlenecks in neptune-core, it's all things related to proving (Triton VM), and whenever a whole block has to be loaded from disk. |
|
Thank you for swift explanation!! I got here after spawning blocking another call, and as I'm using this function there as well, was thinking that may be it's similar. But got a bit lost in what got called during this one. (If I'm getting the things right, some membership proving functions are quite heavy.) Then after your review I started to get how logarithmic this one is, but still was confused. And now I'm sure, and can get the logic better (will take a couple of looks into this part)! So thank you again! |
|
IIRC, the maintenance of removal records is also quite slow. So if you're looking to speed up the mutator set code, that would be a good place to look. |
|
Will note it too, thank you! Feel like closing #903 first though. 🏁 |
less starving the caller thread plus parallelizing
PeerLoopHandler::batch_response