Skip to content
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

[MTG-972] synchronizer optimized #333

Open
wants to merge 41 commits into
base: feature/MTG-868-slots-storage
Choose a base branch
from

Conversation

StanChe
Copy link
Contributor

@StanChe StanChe commented Dec 2, 2024

This change includes several fixes and optimizations as well as an additional tool to dump the DB into "indexable" csv.
The key change is related to bucketing/sharding of assets processing. The keyspace is divided into buckets/shards with each shard having its own iterator over assets. As of now 64 shares have proven itself as a good starting point for assets. And 8-16 shards for token_accounts. Each shard has its own iterator and is run in a separate blocking thread.

The results are as follows:
Dump (total 568G) created in < 1h 15mins:
image

Dump and load took slightly less then 5 hours in total:

{"timestamp":"2024-12-04T09:06:22.309882Z","level":"INFO","fields":{"message":"Starting Synchronizer server..."},"target":"synchronizer"}
{"timestamp":"2024-12-04T09:06:22.310528Z","level":"INFO","fields":{"message":"Starting metrics server on 0.0.0.0:6091"},"target":"metrics_utils::utils"}
{"timestamp":"2024-12-04T09:06:22.398263Z","level":"INFO","fields":{"message":"relation \"_sqlx_migrations\" already exists, skipping","log.target":"sqlx::postgres::notice","log.module_path":"sqlx::postgres::notice","log.file":"/usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.6.3/src/postgres/connection/stream.rs","log.line":157},"target":"sqlx::postgres::notice"}
{"timestamp":"2024-12-04T09:08:43.195226Z","level":"INFO","fields":{"message":"Dumping Fungible from the primary storage to /mnt/operational/migration_data"},"target":"nft_ingester::index_syncronizer"}
...
{"timestamp":"2024-12-04T11:48:16.049045Z","level":"INFO","fields":{"message":"All NFT assets loads complete. Finalizing the batch load"},"target":"nft_ingester::index_syncronizer"}
{"timestamp":"2024-12-04T12:02:18.730607Z","level":"INFO","fields":{"message":"All token accounts/fungibles loads complete. Finalizing the batch load"},"target":"nft_ingester::index_syncronizer"}
{"timestamp":"2024-12-04T12:47:22.920261Z","level":"INFO","fields":{"message":"Batch load finalized for fungibles"},"target":"nft_ingester::index_syncronizer"}
{"timestamp":"2024-12-04T12:47:22.987078Z","level":"INFO","fields":{"message":"Fungible Dump is complete and loaded"},"target":"nft_ingester::index_syncronizer"}
{"timestamp":"2024-12-04T12:47:22.987117Z","level":"INFO","fields":{"message":"Full synchronization finished successfully"},"target":"synchronizer"}
{"timestamp":"2024-12-04T14:03:31.515202Z","level":"INFO","fields":{"message":"Batch load finalized for NFTs"},"target":"nft_ingester::index_syncronizer"}
{"timestamp":"2024-12-04T14:03:31.601022Z","level":"INFO","fields":{"message":"NonFungible Dump is complete and loaded"},"target":"nft_ingester::index_syncronizer"}
{"timestamp":"2024-12-04T14:03:31.601060Z","level":"INFO","fields":{"message":"Full synchronization finished successfully"},"target":"synchronizer"}

… end or sync, core collection authority refactored - was potentially broken, now as straightforward as possible
authority
.as_ref()
.map(|auth| auth.authority.to_string())
.unwrap_or("".to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Default?

let config: ApiConfig = setup_config("API_");
init_logger(&config.get_log_level());
// init_logger(&config.get_log_level());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, delete it if it will not be used

}

#[tokio::main(flavor = "multi_thread")]
pub async fn main() -> Result<(), IngesterError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap() in this main() looks unnecessary especially while the main() returns Result

@@ -294,7 +296,7 @@ pub async fn get_by_ids<
},
);
}
Err(e) => {}
Err(_) => {}
Copy link
Contributor

@kstepanovdev kstepanovdev Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter is unused, indeed. However, completely swallowing the error looks dubious. Maybe should it be logged at least?

});
}

for (start, end) in fungible_shards.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like fungible shards are waiting for nft shards to be spawned, I don't think it's necessary. Nevertheless, it will not save much time in comparison with the work that should be done.

total_assets as f64 / duration.as_secs_f64()
);

while let Some(task) = fungible_tasks.join_next().await {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like fungible task will be awaited for results only when nfts are awaited. However, they might be done first. I mean, they will be executed in parallel but we always receive fungible results after the nft result while the order is not defined afaik.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants