Repository navigation
Split composite DB index on htlc_infos table - #2946
Merged
Merged
Conversation
Member
Author
|
Note that I didn't add any test because we already have migration tests from v2 to the latest version that fill the |
We were previously using a composite index on both the `channel_id` and the `commitment_number` in the `htlc_infos` table. This table is used to store historical HTLC information to be able to publish penalty txs when a malicious peer publishes a revoked commitment. This table is usually the largest DB table on nodes that relay a lot of payments, because it grows with the number of HTLCs received and sent (and only shrinks when channels are closed or spliced). Using a composite index makes sense, but leads to increased memory usage compared to separate indices, thus reducing performance because this is a table on which we write a lot, but almost never read (only when we detect a revoked force-close). The read performance doesn't seem to be negatively impacted anyway when splitting the indices, and the memory usage is greatly improved. The migration may take some time depending on the size of the table, but we cannot get around this. Thanks to @DerEwige for the performance investigation that lead to this change (see #2932 for more details).
t-bast
force-pushed
the
shrink-htlc-infos-index
branch
from
January 30, 2025 15:44
9ff1af3 to
c2c6bd1
Compare
Member
Author
|
I've ran some tests on a local snapshot of our node's DB. I'm running postgres directly on my dev laptop and triggering the migration from that same machine, so results will likely differ from a real deployment, but they're still instructive:
|
pm47
approved these changes
Feb 10, 2025
pm47
left a comment
Member
There was a problem hiding this comment.
LGTM, sorry for the late review!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We were previously using a composite index on both the
channel_idand thecommitment_numberin thehtlc_infostable. This table is used to store historical HTLC information to be able to publish penalty txs when a malicious peer publishes a revoked commitment. This table is usually the largest DB table on nodes that relay a lot of payments, because it grows with the number of HTLCs received and sent (and only shrinks when channels are closed or spliced).Using a composite index makes sense, but leads to increased memory usage compared to separate indices, thus reducing performance because this is a table on which we write a lot, but almost never read (only when we detect a revoked force-close). The read performance doesn't seem to be negatively impacted anyway when splitting the indices, and the memory usage is greatly improved.
The migration may take some time depending on the size of the table, but we cannot get around this.
Thanks to @DerEwige for the performance investigation that lead to this change (see #2932 for more details).