router: Optimize pruning zombie channels. #2799
Closed
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.
This commit introduces a different, more optimized, approach to prune zombie channels.
"zombie channels" stands for channels that their last channel policy update time was earlier than "channel expiry", configured by default to a period of 14 days.
The current approach iterates all channels in the graph in order to filter those in need. This approach is time consuming, several seconds on my mobile device for ~40,000 channels, while during this time the
db is locked in a transaction.
The proposed change is to use an existing functionality that utilize the fact that channel update are saved indexed by date. This way enables us to go over only a small subset of the channels, only those that were updated before the "channel expiry" time and further filter them for our need.
The same graph that took several seconds to prune was pruned, after the change in several milliseconds.
Currently the
pruneZombieChans
is running every hour, I think that the performance improvement will safely allow to run it on every restart and make sure LND starts up with no zombie channels.My measurements for ~40,000 channels.
Samsung galaxy s7
prune time before change: 5-12 seconds, depends on the current load.
prune time after change: 15 milliseconds.
Mac book pro 2.8 GHz Intel Core i7
prune time before change: ~400 milliseconds
prune time after change: 15 milliseconds.