Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

restrictSize performance issue #205

Closed
twoeths opened this issue Aug 19, 2022 · 16 comments · Fixed by #231
Closed

restrictSize performance issue #205

twoeths opened this issue Aug 19, 2022 · 16 comments · Fixed by #231
Labels
kind/stale need/author-input Needs input from the original author P1 High: Likely tackled by core team if no one steps up

Comments

@twoeths
Copy link
Contributor

twoeths commented Aug 19, 2022

Description

  • restrictSize() in libp2p-mplex@0.10.5 has taken 5% of cpu time in lodestar

Screen Shot 2022-08-19 at 11 30 04

  • We have another branch with migrate to libp2p-mplex@5.0.0, and restrictSize() even took more than 11% of cpu time

Screen Shot 2022-08-19 at 11 31 34

@twoeths
Copy link
Contributor Author

twoeths commented Aug 19, 2022

attaching 2 lodestar profiles above

@wemeetagain
Copy link
Member

Screenshot from 2022-08-19 08-38-23
I see this in the profile, I think the issue may be due to node --inspect

@twoeths
Copy link
Contributor Author

twoeths commented Aug 23, 2022

@wemeetagain you're right, I wrote a benchmark and there's no different with or without the restrictSize function

@twoeths twoeths closed this as completed Aug 23, 2022
@twoeths
Copy link
Contributor Author

twoeths commented Oct 3, 2022

reopening the issue, I disabled "async stack trace" and it still shows 4% of cpu time is used for restrictSize

Detail

No async hook there @wemeetagain

The version used in lodestar is @libp2p/mplex@5.2.4

@mpetrunic
Copy link
Member

Triage notes: probably a side effect of not queuing up messages (which needs to be fixed).

@mpetrunic mpetrunic added the P1 High: Likely tackled by core team if no one steps up label Nov 15, 2022
@achingbrain
Copy link
Member

probably a side effect of not queuing up messages

Not sure about this - restrictSize is only used for incoming messages to ensure the remote hasn't sent us something bigger than the max supported message size, the queueing up of messages relates to outgoing messages instead.

@achingbrain
Copy link
Member

it still shows 4% of cpu time is used for restrictSize

What happens when you expand the tree all the way down? From what I can see restrictSize takes 4%, but runMicrotasks takes 3.8%. Most of the cpu time is in yield * msg which will wait before continuing so it might end up inside this._handleIncoming since that's where control is yielded to, so it'd be good to dig a bit deeper.

@twoeths
Copy link
Contributor Author

twoeths commented Nov 23, 2022

  • Top down view:

Screen Shot 2022-11-23 at 10 23 56

  • Bottom up view

Screen Shot 2022-11-23 at 10 24 37

@achingbrain
Copy link
Member

I've refactored restrictSize out of the codebase here: #231 in order to apply the size limit before decoding messages instead of afterwards.

I don't think it's going to change the amount of CPU usage significantly as we're still doing the same operations so it might be worth re-running the benchmark after that PR is merged.

@mpetrunic mpetrunic linked a pull request Nov 24, 2022 that will close this issue
@achingbrain
Copy link
Member

This has been shipped now - could you please re-run the benchmarks with libp2p@next and see if it's still a bottleneck?

@p-shahi p-shahi added the need/author-input Needs input from the original author label Dec 6, 2022
@p-shahi
Copy link
Member

p-shahi commented Dec 6, 2022

@tuyennhv Please re-run the benchmarks when you get a chance 🙏

@github-actions
Copy link

Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.

@achingbrain
Copy link
Member

@tuyennhv will you have time to re-run these benchmarks soon?

@twoeths
Copy link
Contributor Author

twoeths commented Dec 14, 2022

sorry I missed this, this was found during profiling a lodestar node. There's a work-in-progress to upgrade libp2p ChainSafe/lodestar#4717 , will double check there

@github-actions
Copy link

Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.

@github-actions
Copy link

This issue was closed because it is missing author input.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/stale need/author-input Needs input from the original author P1 High: Likely tackled by core team if no one steps up
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants