Skip to content

Commit

Permalink
Merge pull request input-output-hk#1347 from input-output-hk/greg/132…
Browse files Browse the repository at this point in the history
…7/enhance_performances

enhance Aggregator SQLite performances
  • Loading branch information
ghubertpalo authored Nov 14, 2023
2 parents 53088d3 + 589764a commit dd4c113
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.4.9"
version = "0.4.10"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/commands/serve_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl ServeCommand {
}

join_set.spawn(async { tokio::signal::ctrl_c().await.map_err(|e| e.to_string()) });
dependencies_builder.vanish();
dependencies_builder.vanish().await;

if let Err(e) = join_set.join_next().await.unwrap()? {
crit!("A critical error occurred: {e}");
Expand Down
17 changes: 16 additions & 1 deletion mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ impl DependenciesBuilder {
}

// configure session
connection
.execute("pragma journal_mode = wal; pragma synchronous = normal;")
.map_err(|e| DependenciesBuilderError::Initialization {
message: "SQLite initialization: could not enable WAL.".to_string(),
error: Some(e.into()),
})?;

connection
.execute("pragma foreign_keys=true")
.map_err(|e| DependenciesBuilderError::Initialization {
Expand All @@ -273,6 +280,12 @@ impl DependenciesBuilder {
Ok(connection)
}

async fn drop_sqlite_connection(&self) {
if let Some(connection) = &self.sqlite_connection {
let _ = connection.execute("pragma analysis_limit=400; pragma optimize;");
}
}

/// Get SQLite connection
pub async fn get_sqlite_connection(&mut self) -> Result<Arc<ConnectionWithFullMutex>> {
if self.sqlite_connection.is_none() {
Expand Down Expand Up @@ -1196,5 +1209,7 @@ impl DependenciesBuilder {
}

/// Remove the dependencies builder from memory to release Arc.
pub fn vanish(self) {}
pub async fn vanish(self) {
self.drop_sqlite_connection().await;
}
}

0 comments on commit dd4c113

Please sign in to comment.