-
Notifications
You must be signed in to change notification settings - Fork 465
Optimize SQL queries in pull_missing_blocks #1458
Conversation
@@ -14,56 +14,56 @@ import { handleError, INFURA_ROOT_URL } from '../utils'; | |||
// Number of blocks to save at once. | |||
const BATCH_SAVE_SIZE = 1000; | |||
// Maximum number of requests to send at once. | |||
const MAX_CONCURRENCY = 10; | |||
const MAX_CONCURRENCY = 20; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also increased the maximum number of concurrent requests. I've been monitoring memory and CPU usage and this should speed up the script without taxing resources too much. We can adjust further in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Getting rid of the WHERE.. NOT IN
clause should speed things up a lot.
Couple questions:
- do we expect insignificant amount of overlap in block numbers across different events?
- if not, did you also try the original UNION query with the new
JOIN... NOT NULL
clause and find that removing the UNION query sped things up significantly? I would expect theWHERE... NOT IN
clause to be the primary slowdown, not the UNION, but don't know offhand.
If yes to one or both, looks good to merge for me 👍
We expect overlap between block numbers across different events. However, since we save any newly found blocks before checking for missing events in the next table in the list, this doesn't result in any duplicated work. In other words, if the same block is missing in both
I just tested locally and adding |
Makes sense to me :) |
7889a03
to
1d25925
Compare
Description
This PR optimizes the query for finding missing blocks. The old implementation is bogging down our SQL server and occasionally causing queries to take over one hour! In a full-ish database with many events and blocks the new implementation is at least a 1000x performance increase.
Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.