-
Notifications
You must be signed in to change notification settings - Fork 161
Speedup Reward and EpochStake insertions #1292
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
Comments
DBSync sync time is 40% faster when disable-ledger is enabled, chiefly because the Reward and EpochStake tables aren't populated. If we remove the unique key check on the reward table during sync, we'll get a big improvement. This ticket refers to work that will temporarily remove the unique key check during syncing. |
@kderme can you clarify whether this performance hit is due to processing for the epoch boundary? |
No this operation is spread acrosss most of the epoch and not done during the epoch boundary |
So I’ve been trying to research postgresql constraint system and how it’s slowing down our inserts for rewards before db-sync reaches the tips of the chain. From what I gather even if we delay adding the constraint once the tip is reached/after a migration. The db would have to recalculate all the existing rows to check if adding constraints is valid. From what I gather there is another option of using So we could translate the bulk insert into a copy but I’m unsure of performance benefits or if it’s something that could even happen? |
I belive |
would these constraints be permanently removed as from my understanding
So even though we'd think by delaying adding them after the insertion would be more performant it might actually not be the case 🤔 |
When the unique key is inserted on a fully populated table it will take some time to check for the uniqueness in the whole table. However it is always faster to do a single check on a fully populated table, than do the check every time a new entry is inserted for this entry. This has been the basis for many other optimizations like #1293 |
To overcome the limitations of persistent it may be wise to completely remove the unique key from these 2 tables from TH. That way we can have a user defined Unique Key which lives outside Persistent and TH. To make this safer we can validate it against the Also before creating the Unique Key it's necessary to first check if it has already been created before. Postgres queries usually have a |
Uh oh!
There was an error while loading. Please reload this page.
Syncing with
disable-leger
provides a considerable speedup. This is because ledger rules are not applied and becauseReward
andEpochStake
tables are not populated. This provides the motivation to investigate why these tables take so long to populate.The reward table has a unique key which is checked every time a new entry is inserted. It exists because the reward table is never deleted. After a rollback the same values will be reattempted and the unique key guards against it. Since #1190 is done, there are no rollbacks when db-sync syncs, they only happen when db-sync reaches the tip of the chain. So for the most part, the unique constaint checks provides delays without any benefit. We should try and find a way to delay the migration which creates this unique key untill db-sync reaches the tip of the chain.
Also rewards are added in bug chunks. We should consider limit the size of the insertions. Persistant cache is also affected by it
Similar things apply to EpochStake.
Depends on #1087 #1293
The text was updated successfully, but these errors were encountered: