-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace string DB fields with more appropriate data types #2932
Comments
That choice was made because we currently favor usability/readability (when browsing the DB using standard DB tools) over performance. We've found that the performance hit wasn't noticeable, so we haven't changed this. We can change this in the future when performance starts becoming a real bottleneck, but that isn't a priority at all right now. Also, this should be motivated by reproducible benchmarks to ensure that the performance gain is worth the DB migration complexity. |
There is only one table that is really a problem right now
At 250 million entries it reached a size of 100GB and the index is more than 25 GB (which is the main problem). Because of this the index does not fit into my memory anymore which causes huge performance problems. Especially if a compaction is running while éclair is deleting rows form that table the node suffers heavy performance loss. This is really the only table that causes problem and could benefit from some optimization. |
Gotcha, this is indeed the table that grows the most as HTLCs are processed. It gets better with splicing, which lets us remove old entries after a splice, but it's still that DB that will grow the most. It's a bit annoying to update, because if we want to change the |
For makes the corellation a big more complex (needs 2 steps or a join) But could reduce the size of the table (space on diks) and also the index by a lot I'll try to do some peromance test on that with 50m+ insersts and deleets in the next few weeks and post results in here, once I'm done |
I made some small tests and I think I found the main issue and a possible solution You are using a composite index of But the index gets so big, it does consume 30-50% of the total table space. Composite index vs 2 separate indexes Proposed optimization Decrease of total table size by more than 50% Small 100k table before optimization Small 100k table after optimization 17 MB total for my table this would mean reduction of the index from 25 GB to about 3.5 GB |
I have analyzed it some more: You can use this SQL statement on your PG instance to verify my findings
It is basically only inserts and deletes on htlc_info. So, turning the compound index into 2 separate indexes would not hurt performance at all even when the compound index fits into the memory. The least invasive version would be to leave This would lead to no changes in the code (for accessing the DB) and minimal DB migration. This would shrink the total DB by about 45% and the index would shrink by about 85% |
Thanks for the investigation!
Sounds acceptable, do you want to open a PR for that?
Is the DB migration really minimal? Re-building two indices on the |
Once the investigation is done. I would like to leave the implementation to you guys. My Scala is really lacking.
I guess every change we do (change datatype of a field, change an index) would require to read the whole table. So, there is no cheap solution here. You are right rebuilding the index will take some time. It might be better to add the new indexes before dropping the old one. How big is your DB right now? I’ve managed to bring mine down to about 65 million entries by replacing a lot of older channels during 2 sat/vb times. I could either make a copy or my DB or do a mockup DB with the same size to test the durations. |
We "only* have 21 million rows, it's smaller than yours! I'm curious to know what the migration time is to re-create the index in that case. |
ok. I will do a mockup DB with 20m entries and test it, should take me about 2 hours to do multiple runs. |
I did 4 runs in total TLDR: about 90s to create both new indexes DB server used is (I assume you have a bit a stronger system) My live node uses the same DB server. Because of this setup there was quite some variation in duration time for the new indexes. I created 50 channels with 400’000 commits on each channel. I’ll post the slowest run here: total size: 7106 MB Index creation duration: 94.4 seconds Size after creating new indexes and dropping old index: total size: 3917 MB
you can use this select to check your size:
(Note: this will show you the size on disk, not the actual size. If your table was bigger in the past and you never did a "full vacuum", it will show you larger size) |
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).
Thanks for investigating this, I made the change in #2946. |
For example you chose to store the UUIDs in text fields
Which make them use 36 byte instead of 16 byte if you would use the built in
UUID
data typeIf you would revamp to use
BIGINT
where it is possible instead you would go down to 8 byte.This would shrink the database (and the indexes in particularly) and make the whole DB a lot faster.
The text was updated successfully, but these errors were encountered: