Skip to content

Commit

Permalink
chore(torii-core): WAL journal mode & remove max conns (#2439)
Browse files Browse the repository at this point in the history
* fix(torii-core): sqlite shared cache

* use options

* fmt

* database url

* chore

* shared cache better

* removbe max connections

* shared memory is by default on

* fmt
  • Loading branch information
Larkooo authored Sep 19, 2024
1 parent 0da6f0c commit 7c5a1f5
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use clap::{ArgAction, Parser};
use dojo_metrics::{metrics_process, prometheus_exporter};
use dojo_utils::parse::{parse_socket_address, parse_url};
use dojo_world::contracts::world::WorldContractReader;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::sqlite::{
SqliteAutoVacuum, SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous,
};
use sqlx::SqlitePool;
use starknet::core::types::Felt;
use starknet::providers::jsonrpc::HttpTransport;
Expand Down Expand Up @@ -153,19 +155,15 @@ async fn main() -> anyhow::Result<()> {
})
.expect("Error setting Ctrl-C handler");

let database_url = format!("sqlite:{}", &args.database);
let options =
SqliteConnectOptions::from_str(&database_url)?.create_if_missing(true).with_regexp();
let pool = SqlitePoolOptions::new()
.min_connections(1)
.max_connections(5)
.connect_with(options)
.await?;
let mut options =
SqliteConnectOptions::from_str(&args.database)?.create_if_missing(true).with_regexp();

// Performance settings
options = options.auto_vacuum(SqliteAutoVacuum::None);
options = options.journal_mode(SqliteJournalMode::Wal);
options = options.synchronous(SqliteSynchronous::Normal);

// Disable auto-vacuum
sqlx::query("PRAGMA auto_vacuum = NONE;").execute(&pool).await?;
sqlx::query("PRAGMA journal_mode = WAL;").execute(&pool).await?;
sqlx::query("PRAGMA synchronous = NORMAL;").execute(&pool).await?;
let pool = SqlitePoolOptions::new().min_connections(1).connect_with(options).await?;

// Set the number of threads based on CPU count
let cpu_count = std::thread::available_parallelism().unwrap().get();
Expand Down

0 comments on commit 7c5a1f5

Please sign in to comment.