lnd
lnd copied to clipboard
Misson Control Store: Improve performance
The current implementation of the Misson Control Store has a one second ticker that trims the DB, ensuring only the latest 1000 entries are kept.
That ticker was added in https://github.com/lightningnetwork/lnd/pull/5515 as a way to improve performance by batching and de-duplicating the updates to the db.
However, its current implementation can be significantly improved by doing a few pointed changes. In particular:
- There is no need to open a db tx when there is no work.
- The ticker does not need to run continuously, only when there are items in the queue that need to be persisted.
- The current implementation duplicates the entire in-memory cache of the store, which is not ideal when there are only a few entries that need to be added
This PR improves the situation iteratively on each commit. A set of benchmarks is added to verify the performance improvement.
This is the final result (using a bbolt MC store):
MissionControlStoreFlushing/no_additional_results-7 221µs ±15% 0µs ± 2% -99.86% (p=0.000 n=10+10)
MissionControlStoreFlushing/one_additional_result-7 359µs ±40% 44µs ± 8% -87.87% (p=0.000 n=10+10)
MissionControlStoreFlushing/ten_additional_results-7 344µs ± 9% 129µs ±29% -62.61% (p=0.000 n=9+10)
MissionControlStoreFlushing/100_additional_results-7 987µs ±28% 621µs ±22% -37.06% (p=0.000 n=10+10)
MissionControlStoreFlushing/250_additional_results-7 2.02ms ±37% 1.53ms ±41% -24.62% (p=0.005 n=10+10)
MissionControlStoreFlushing/500_additional_results-7 2.88ms ±11% 2.84ms ±18% ~ (p=0.780 n=9+10)
name old alloc/op new alloc/op delta
MissionControlStoreFlushing/no_additional_results-7 139kB ± 0% 0kB -100.00% (p=0.000 n=10+10)
MissionControlStoreFlushing/one_additional_result-7 153kB ± 0% 19kB ± 0% -87.37% (p=0.000 n=10+10)
MissionControlStoreFlushing/ten_additional_results-7 175kB ± 0% 41kB ± 0% -76.35% (p=0.000 n=8+8)
MissionControlStoreFlushing/100_additional_results-7 350kB ± 0% 222kB ± 0% -36.63% (p=0.000 n=10+10)
MissionControlStoreFlushing/250_additional_results-7 651kB ± 0% 535kB ± 0% -17.75% (p=0.000 n=8+10)
MissionControlStoreFlushing/500_additional_results-7 1.14MB ± 0% 1.04MB ± 0% -8.57% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
MissionControlStoreFlushing/no_additional_results-7 1.06k ± 0% 0.00k -100.00% (p=0.000 n=10+10)
MissionControlStoreFlushing/one_additional_result-7 1.15k ± 0% 0.12k ± 0% -90.02% (p=0.000 n=10+10)
MissionControlStoreFlushing/ten_additional_results-7 1.49k ± 0% 0.46k ± 0% -69.36% (p=0.000 n=10+10)
MissionControlStoreFlushing/100_additional_results-7 4.90k ± 0% 3.87k ± 0% -21.07% (p=0.000 n=10+10)
MissionControlStoreFlushing/250_additional_results-7 10.6k ± 0% 9.6k ± 0% -9.75% (p=0.000 n=10+10)
MissionControlStoreFlushing/500_additional_results-7 20.1k ± 0% 19.1k ± 0% -5.15% (p=0.000 n=9+10)
As can be seen, there is a significant improvement in cpu and memory usage when up to 100 additional results are added (i.e. up to 100 txs/second flowing through the node).
The improvement is specially significant when no new results are added to a full MC store, which is relevant for nodes that have a low or only episodic volument of payments (e.g. a mostly end user node or mobile node).
[!IMPORTANT]
Review skipped
Auto reviews are limited to specific labels.
Labels to auto review (1)
- llm-review
Please check the settings in the CodeRabbit UI or the
.coderabbit.yaml
file in this repository. To trigger a single review, invoke the@coderabbitai review
command.You can disable this status message by setting the
reviews.review_status
tofalse
in the CodeRabbit configuration file.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>.
-
Generate unit testing code for this file.
-
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitai
in a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file.
-
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitai
in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai generate interesting stats about this repository and render them as a table.
-
@coderabbitai show all the console.log statements in this repository.
-
@coderabbitai read src/utils.ts and generate unit testing code.
-
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
-
@coderabbitai help me debug CodeRabbit configuration file.
-
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (invoked as PR comments)
-
@coderabbitai pause
to pause the reviews on a PR. -
@coderabbitai resume
to resume the paused reviews. -
@coderabbitai review
to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full review
to do a full review from scratch and review all the files again. -
@coderabbitai summary
to regenerate the summary of the PR. -
@coderabbitai resolve
resolve all the CodeRabbit review comments. -
@coderabbitai configuration
to show the current CodeRabbit configuration for the repository. -
@coderabbitai help
to get help.
Additionally, you can add @coderabbitai ignore
anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml
)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yaml
file to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Going through the lint/CI failures now, might need some refactoring to deal with the type checks required from using non-generic *list.List
Lint issues are fixed, I believe the other CI failures are just flakes.
@bitromortac sent commit https://github.com/lightningnetwork/lnd/pull/8549/commits/fb4367831fe8766f64e20288a9ab110304ce2f36 to clean up the mission control tests and address your comments.
Also rebased to address the conflict.
@bitromortac: review reminder @matheusd, remember to re-request review from reviewers when ready
@ellemouton Thank you for the thorough review! I believe I addressed all of your points.
Also, rebased against current master.
Not sure what to do about the release notes, given the v0.18 RCs are already out (move to v0.19 or v0.18.1 or something else).
thanks for the quick turn around! I'll check it out soon.
im also not sure re release notes.... cc @saubyk for that :)
tagged for 18.1
tagged for 18.1
On a second thought, 18.1 is already getting bloated and this doesn't seem urgent so moving to 0.19
Removed commit with type safety and moved release notes to v0.19.0.md.
@matheusd - note the failing linter check
Sorry for the misses. Updated.
@matheusd, remember to re-request review from reviewers when ready
@saubyk - happy for this to be merged? I think it is g2g
Tagged for 18.1. Release notes need update
@matheusd - thanks for your patience 🙏 I think we wanna move this to 0.18.1 instead of 0.19 so do you mind doing one last update and moving the release notes to the 0.18.1 doc pls?
oh no @matheusd - looks like there is a merge conflict 🙈 one more rebase pls 🙏 will then merge this asap so that this can be the last one!