Skip to content

Commit

Permalink
Add store_transactions bench case with SQL transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed May 3, 2024
1 parent 07e4876 commit c4e706b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion mithril-signer/benches/cardano_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ fn cardano_tx_db_connection() -> StdResult<ConnectionThreadSafe> {
Ok(connection)
}

async fn store_transactions_with_sqlite_transaction(
repository: CardanoTransactionRepository,
transactions: Vec<CardanoTransaction>,
) -> StdResult<()> {
repository.connection.execute("BEGIN TRANSACTION;")?;
repository.store_transactions(transactions).await?;
repository.connection.execute("END TRANSACTION;")?;

Ok(())
}

fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
(0..nb_transactions)
.map(|i| {
Expand All @@ -34,7 +45,7 @@ fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
}

fn bench_store_transactions_transactions(c: &mut Criterion) {
const NB_CARDANO_TRANSACTIONS: usize = 100000;
const NB_CARDANO_TRANSACTIONS: usize = 10000;
let runtime = tokio::runtime::Runtime::new().unwrap();

let mut group = c.benchmark_group("Create transactions");
Expand All @@ -49,6 +60,18 @@ fn bench_store_transactions_transactions(c: &mut Criterion) {
});
});

group.bench_function("store_transactions_with_sqlite_transaction", |bencher| {
bencher.to_async(&runtime).iter(|| async {
let connection = Arc::new(cardano_tx_db_connection().unwrap());
let repository = CardanoTransactionRepository::new(connection);
store_transactions_with_sqlite_transaction(
repository,
generate_transactions(NB_CARDANO_TRANSACTIONS),
)
.await
});
});

for chunks_size in [10, 50, 100, 200] {
group.bench_function(
format!("store_transactions_with_chunks_size = {}", chunks_size),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use mithril_persistence::sqlite::GetAllProvider;
/// This is a business oriented layer to perform actions on the database through
/// providers.
pub struct CardanoTransactionRepository {
connection: Arc<SqliteConnection>,
pub connection: Arc<SqliteConnection>,
}

impl CardanoTransactionRepository {
Expand Down

0 comments on commit c4e706b

Please sign in to comment.