-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve efficiency of aggregated statistics
We have some statistics that are derived from the entire block history, namely transaction count and payload size. Previously, these were computed on the fly each request, which requires an expensive full table scan and, in the case of payload size, a large sum. This change adds a new table `aggregate`, which stores these cumulative values _at each block height_. This table is kept up to date by a background task scanning the block stream. Now, looking up the values of these statistics just requires reading a single row in this table. This approach has numerous benefits in addition to a massive performance improvement: * we can now easily look up the values of these statistics at any historical block height, or for any historical _range_ of blocks * instead of returning inaccurate counts when data is missing, we will simply return that we don't have the counts yet for the requested block height, since the aggregate table won't be populated for that row * requests that explicitly specify a range or upper bound are easily cachable
- Loading branch information
Showing
19 changed files
with
712 additions
and
115 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE aggregate ( | ||
height BIGINT PRIMARY KEY REFERENCES header (height) ON DELETE CASCADE, | ||
num_transactions BIGINT NOT NULL, | ||
payload_size BIGINT NOT NULL | ||
); |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.