Skip to content

Commit 8e2c7cd

Browse files
dlachaumesfauvel
authored andcommitted
Add store_transactions bench case with SQL transaction
1 parent c611e45 commit 8e2c7cd

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

mithril-signer/benches/cardano_transactions.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ fn cardano_tx_db_connection() -> StdResult<ConnectionThreadSafe> {
1919
Ok(connection)
2020
}
2121

22+
async fn store_transactions_with_sqlite_transaction(
23+
repository: CardanoTransactionRepository,
24+
transactions: Vec<CardanoTransaction>,
25+
) -> StdResult<()> {
26+
repository.connection.execute("BEGIN TRANSACTION;")?;
27+
repository.store_transactions(transactions).await?;
28+
repository.connection.execute("END TRANSACTION;")?;
29+
30+
Ok(())
31+
}
32+
2233
fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
2334
(0..nb_transactions)
2435
.map(|i| {
@@ -34,7 +45,7 @@ fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
3445
}
3546

3647
fn bench_store_transactions_transactions(c: &mut Criterion) {
37-
const NB_CARDANO_TRANSACTIONS: usize = 100000;
48+
const NB_CARDANO_TRANSACTIONS: usize = 10000;
3849
let runtime = tokio::runtime::Runtime::new().unwrap();
3950

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

63+
group.bench_function("store_transactions_with_sqlite_transaction", |bencher| {
64+
bencher.to_async(&runtime).iter(|| async {
65+
let connection = Arc::new(cardano_tx_db_connection().unwrap());
66+
let repository = CardanoTransactionRepository::new(connection);
67+
store_transactions_with_sqlite_transaction(
68+
repository,
69+
generate_transactions(NB_CARDANO_TRANSACTIONS),
70+
)
71+
.await
72+
});
73+
});
74+
5275
for chunks_size in [10, 50, 100, 200] {
5376
group.bench_function(
5477
format!("store_transactions_with_chunks_size = {}", chunks_size),

mithril-signer/src/database/repository/cardano_transaction_repository.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use mithril_persistence::sqlite::GetAllProvider;
3030
/// This is a business oriented layer to perform actions on the database through
3131
/// providers.
3232
pub struct CardanoTransactionRepository {
33-
connection: Arc<SqliteConnection>,
33+
pub connection: Arc<SqliteConnection>,
3434
}
3535

3636
impl CardanoTransactionRepository {

0 commit comments

Comments
 (0)