Update db config to production-friendly.

Four seconds to insert 10k records, with a prod-safe config. Stick with this design.
This commit is contained in:
Joe Ardent 2023-07-04 16:24:28 -07:00
parent 24926fed6a
commit 5e4f5c07d8
6 changed files with 19 additions and 64 deletions

64
Cargo.lock generated
View file

@ -241,7 +241,7 @@ dependencies = [
"axum-core", "axum-core",
"axum-macros", "axum-macros",
"bitflags 1.3.2", "bitflags 1.3.2",
"bytes 1.4.0", "bytes",
"futures-util", "futures-util",
"headers", "headers",
"http", "http",
@ -272,7 +272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bytes 1.4.0", "bytes",
"futures-util", "futures-util",
"http", "http",
"http-body", "http-body",
@ -290,7 +290,7 @@ checksum = "febf23ab04509bd7672e6abe76bd8277af31b679e89fa5ffc6087dc289a448a3"
dependencies = [ dependencies = [
"axum", "axum",
"axum-core", "axum-core",
"bytes 1.4.0", "bytes",
"cookie", "cookie",
"futures-util", "futures-util",
"http", "http",
@ -317,7 +317,7 @@ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"dyn-clone", "dyn-clone",
"eyre", "eyre",
"futures 0.3.28", "futures",
"ring", "ring",
"secrecy", "secrecy",
"serde", "serde",
@ -350,7 +350,7 @@ dependencies = [
"async-session", "async-session",
"axum", "axum",
"axum-extra", "axum-extra",
"futures 0.3.28", "futures",
"http-body", "http-body",
"tokio", "tokio",
"tower", "tower",
@ -476,16 +476,6 @@ version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
dependencies = [
"byteorder",
"iovec",
]
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.4.0" version = "1.4.0"
@ -775,12 +765,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "futures"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.28" version = "0.3.28"
@ -879,7 +863,6 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"pin-utils", "pin-utils",
"slab", "slab",
"tokio-io",
] ]
[[package]] [[package]]
@ -936,7 +919,7 @@ checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"bitflags 1.3.2", "bitflags 1.3.2",
"bytes 1.4.0", "bytes",
"headers-core", "headers-core",
"http", "http",
"httpdate", "httpdate",
@ -1008,7 +991,7 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
dependencies = [ dependencies = [
"bytes 1.4.0", "bytes",
"fnv", "fnv",
"itoa", "itoa",
] ]
@ -1019,7 +1002,7 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [ dependencies = [
"bytes 1.4.0", "bytes",
"http", "http",
"pin-project-lite", "pin-project-lite",
] ]
@ -1057,7 +1040,7 @@ version = "0.14.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4"
dependencies = [ dependencies = [
"bytes 1.4.0", "bytes",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-util", "futures-util",
@ -1132,15 +1115,6 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
version = "0.4.8" version = "0.4.8"
@ -1848,7 +1822,7 @@ dependencies = [
"atoi", "atoi",
"bitflags 1.3.2", "bitflags 1.3.2",
"byteorder", "byteorder",
"bytes 1.4.0", "bytes",
"chrono", "chrono",
"crc", "crc",
"crossbeam-queue", "crossbeam-queue",
@ -2045,7 +2019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes 1.4.0", "bytes",
"libc", "libc",
"mio", "mio",
"num_cpus", "num_cpus",
@ -2058,17 +2032,6 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "tokio-io"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674"
dependencies = [
"bytes 0.4.12",
"futures 0.1.31",
"log",
]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "2.1.0" version = "2.1.0"
@ -2137,7 +2100,7 @@ checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858"
dependencies = [ dependencies = [
"base64 0.13.1", "base64 0.13.1",
"bitflags 1.3.2", "bitflags 1.3.2",
"bytes 1.4.0", "bytes",
"futures-core", "futures-core",
"futures-util", "futures-util",
"http", "http",
@ -2155,7 +2118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8bd22a874a2d0b70452d5597b12c537331d49060824a95f49f108994f94aa4c" checksum = "a8bd22a874a2d0b70452d5597b12c537331d49060824a95f49f108994f94aa4c"
dependencies = [ dependencies = [
"bitflags 2.3.3", "bitflags 2.3.3",
"bytes 1.4.0", "bytes",
"futures-core", "futures-core",
"futures-util", "futures-util",
"http", "http",
@ -2561,7 +2524,6 @@ dependencies = [
"axum-test", "axum-test",
"chrono", "chrono",
"clap", "clap",
"futures-util",
"justerror", "justerror",
"optional_optional_user", "optional_optional_user",
"password-hash", "password-hash",

View file

@ -30,7 +30,6 @@ ulid = { version = "1", features = ["rand"] }
optional_optional_user = {path = "optional_optional_user"} optional_optional_user = {path = "optional_optional_user"}
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] } chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }
clap = { version = "4.3.10", features = ["derive", "env", "unicode", "suggestions", "usage"] } clap = { version = "4.3.10", features = ["derive", "env", "unicode", "suggestions", "usage"] }
futures-util = { version = "0.3.28", features = ["tokio-io"] }
tokio-retry = "0.3.0" tokio-retry = "0.3.0"
tokio-stream = "0.1.14" tokio-stream = "0.1.14"

View file

@ -2,4 +2,4 @@
-rw-r--r-- 1 ardent ardent 161K Jul 4 12:29 .witch-watch.db-wal -rw-r--r-- 1 ardent ardent 161K Jul 4 12:29 .witch-watch.db-wal
-rw-r--r-- 1 ardent ardent 32K Jul 4 12:29 .witch-watch.db-shm -rw-r--r-- 1 ardent ardent 32K Jul 4 12:29 .witch-watch.db-shm
3.5 seconds wall to add 10k movies, added by the omega user. 4 seconds wall to add 10k movies, added by the omega user.

View file

@ -1,12 +1,10 @@
use std::{ffi::OsString, pin::Pin, time::Duration}; use std::{ffi::OsString, pin::Pin, time::Duration};
use clap::Parser; use clap::Parser;
use futures_util::Stream;
//use futures_util::stream::TryStreamExt;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use tokio::task::JoinSet; use tokio::task::JoinSet;
use tokio_retry::Retry; use tokio_retry::Retry;
use tokio_stream::StreamExt; use tokio_stream::{Stream, StreamExt};
use witch_watch::{ use witch_watch::{
get_db_pool, get_db_pool,
import_utils::{add_watch_omega, ensure_omega, ImportMovieOmega}, import_utils::{add_watch_omega, ensure_omega, ImportMovieOmega},

View file

@ -9,7 +9,7 @@ use session_store::SqliteSessionStore;
use sqlx::{ use sqlx::{
migrate::Migrator, migrate::Migrator,
sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions}, sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions},
Executor, SqlitePool, SqlitePool,
}; };
use crate::{db_id::DbId, User}; use crate::{db_id::DbId, User};
@ -45,9 +45,9 @@ pub async fn get_db_pool() -> SqlitePool {
let conn_opts = SqliteConnectOptions::new() let conn_opts = SqliteConnectOptions::new()
.foreign_keys(true) .foreign_keys(true)
//.auto_vacuum(sqlx::sqlite::SqliteAutoVacuum::Incremental) .auto_vacuum(sqlx::sqlite::SqliteAutoVacuum::Incremental)
.journal_mode(SqliteJournalMode::Wal) .journal_mode(SqliteJournalMode::Wal)
.synchronous(sqlx::sqlite::SqliteSynchronous::Off) .synchronous(sqlx::sqlite::SqliteSynchronous::Normal)
.filename(&db_filename) .filename(&db_filename)
.busy_timeout(Duration::from_secs(TIMEOUT)) .busy_timeout(Duration::from_secs(TIMEOUT))
.create_if_missing(true); .create_if_missing(true);
@ -61,10 +61,6 @@ pub async fn get_db_pool() -> SqlitePool {
.await .await
.expect("can't connect to database"); .expect("can't connect to database");
// let mut conn = pool.acquire().await.unwrap();
// conn.execute("PRAGMA cache_size = 1000000;").await.unwrap();
// conn.execute("PRAGMA temp_store = MEMORY;").await.unwrap();
// let the filesystem settle before trying anything // let the filesystem settle before trying anything
// possibly not effective? // possibly not effective?
tokio::time::sleep(Duration::from_millis(500)).await; tokio::time::sleep(Duration::from_millis(500)).await;

View file

@ -8,7 +8,7 @@ const USER_EXISTS_QUERY: &str = "select count(*) from witches where id = $1";
const OMEGA_ID: u128 = u128::MAX; const OMEGA_ID: u128 = u128::MAX;
#[derive(Debug, sqlx::FromRow)] #[derive(Debug, sqlx::FromRow, Clone)]
pub struct ImportMovieOmega { pub struct ImportMovieOmega {
pub title: String, pub title: String,
pub year: Option<String>, pub year: Option<String>,