-
Notifications
You must be signed in to change notification settings - Fork 166
Persistent to Hasql #1938
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
base: master
Are you sure you want to change the base?
Persistent to Hasql #1938
Conversation
f80c67b
to
96182d8
Compare
89285ee
to
2db7312
Compare
a67562c
to
94f48af
Compare
cdab159
to
8ce46c6
Compare
08d56ec
to
f237b25
Compare
1938 - 1 - Variant/Tests Name Changes
ec1082f
to
fe197d6
Compare
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 did a pass of the cardano-db-sync
diffs
then logWarning trce $ Db.renderMigrationValidateError unknown | ||
else logError trce $ Db.renderMigrationValidateError unknown | ||
then logWarning trce $ DB.renderMigrationValidateError unknown | ||
else logError trce $ DB.renderMigrationValidateError unknown | ||
|
||
logInfo trce "Schema migration files validated" | ||
|
||
let runMigration mode = do |
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.
Avoid duplication between runMigration
and runIndexesMigration
. This can be done by defining a single function in runDbSyncNode
with type RunMigration
and passing it to both functions.
cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Other.hs
Outdated
Show resolved
Hide resolved
cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Other.hs
Outdated
Show resolved
Hide resolved
cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Other.hs
Outdated
Show resolved
Hide resolved
isFetchError :: OffChainVoteResult -> Bool | ||
isFetchError = \case | ||
OffChainVoteResultMetadata {} -> False | ||
OffChainVoteResultError {} -> True | ||
|
||
processResultsBatched :: MonadIO m => [OffChainVoteResult] -> DB.DbAction m () |
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.
Good idea to use pipeline here. Personal note to review it again.
pure False | ||
mBlockNo <- lift $ DB.queryBlockHashBlockNo (SBS.fromShort . getOneEraHash $ blockPointHash blk) | ||
case mBlockNo of | ||
Nothing -> throwError $ SNErrRollback "Rollback.prepareRollback: queryBlockHashBlockNo: Block hash not found" |
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.
In general the whole purpose of ExceptT is to have better "flow" and to avoid case patterns for errors. I think we lose this in many places.
6ad7d4d
to
87c8789
Compare
|
||
-- Parallel preparation of independent data | ||
(preparedTxIn, preparedMetadata, preparedMint, txOutChunks) <- liftIO $ do | ||
a1 <- async $ pure $ prepareTxInProcessing syncEnv grouped |
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.
This spawns threads, but they do so minimal work that I think it's not worth it. Due to laziness, they may even do no work at all.
cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Grouped.hs
Outdated
Show resolved
Hide resolved
b2df816
to
80cc82b
Compare
779de8b
to
54e8f11
Compare
d1362d8
to
1e41b5a
Compare
1e41b5a
to
1143664
Compare
f3b215c
to
1fb3c0e
Compare
maTxOutIdAddressToText _ = "" -- Skip non-variant IDs | ||
|
||
-------------------------------------------------------------------------------- | ||
textToMinIds :: TxOutVariantType -> Text -> Maybe MinIdsWrapper |
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.
This doesn't match minIdsCoreToText
. Should revert the old parser in Cardano.Db.Operations.Other.MinId
, except toSqlKey
.
updateBlockMetrics :: IO () | ||
updateBlockMetrics = do | ||
let metricsSetters = envMetricSetters syncEnv | ||
void $ async $ DB.runDbDirectLogged (fromMaybe mempty $ DB.dbTracer $ envDbEnv syncEnv) (envDbEnv syncEnv) $ do |
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.
Avoid using async, or use it with a different connection from the connection pool
Hasql Migration
Summary
The migration from Persistent to Hasql delivered a 3-4x performance improvement in epoch processing time, with some gains in cache efficiency.
Processing Time Comparison
Before (Persistent)
After (Hasql)
Improvement: 73% reduction in processing time (3.5x faster)
Resource Utilisation
Database Connections
Technical Factors Contributing to Performance
1. Eliminated ORM Overhead
2. Optimised SQL Generation
3. Type-Safe Operations
4. Connection Management
Epoch Context
Based on Cardano network data, each epoch processes approximately 21,600 blocks over a 5-day period. The performance improvement scales linearly with blockchain growth, making this migration critical for long-term sustainability.
Conclusion
The Hasql migration represents a significant infrastructure improvement, providing both immediate performance gains and better long-term scalability. The 73% reduction in processing time, positions the system for handling increased blockchain throughput.