Skip to content

Commit 60ee2fe

Browse files
LouisHaftmannclaude
andcommitted
fix(db): wait for the SQLite writer instead of syncing every part
Syncing each part halved upload speed on fast disks. The 500s came from sqlx's 30 s acquire timeout, not from the backlog itself: with a 10 min timeout, requests on a slow disk wait up to ~40 s and none fail, and the upload path stays as fast as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4232829 commit 60ee2fe

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎src/db.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod migrations;
55

66
use std::future::Future;
77
use std::str::FromStr as _;
8+
use std::time::Duration;
89

910
use sea_orm::sea_query::{Alias, Expr, ExprTrait as _, Func, LikeExpr};
1011
use sea_orm::{
@@ -73,6 +74,8 @@ impl Dialect {
7374
/// SQLite read connections; WAL readers don't block each other or the writer.
7475
const READ_CONNECTIONS: u32 = 8;
7576
const SERVER_CONNECTIONS: u32 = 10;
77+
/// Longer than clients wait for a response; sqlx adds it to `Instant::now()`, so it must be finite.
78+
const SQLITE_ACQUIRE_TIMEOUT: Duration = Duration::from_secs(600);
7679
const IN_MEMORY: &str = ":memory:";
7780

7881
/// Connection pools plus the dialect their queries are rendered for.
@@ -124,7 +127,14 @@ impl Db {
124127
// SQLite allows one writer; a single connection serializes access the way the
125128
// database expects instead of surfacing `SQLITE_BUSY` under load. A local file
126129
// can't go stale, and pinging it on every checkout doubles the queue on it.
127-
let pool_options = || SqlitePoolOptions::new().test_before_acquire(false);
130+
// On a disk slower than the uploads, every commit waits behind the page cache's
131+
// writeback backlog, and the queue for the writer grows past sqlx's 30 s default.
132+
// A request then waits for its turn instead of failing.
133+
let pool_options = || {
134+
SqlitePoolOptions::new()
135+
.test_before_acquire(false)
136+
.acquire_timeout(SQLITE_ACQUIRE_TIMEOUT)
137+
};
128138
if path.as_os_str() == IN_MEMORY {
129139
// An in-memory database lives in its one connection, so it has no readers
130140
// and is gone once that connection closes.

‎src/storage/filesystem.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ impl FilesystemAdapter {
152152
file.write_all(&chunk).await?;
153153
}
154154
file.flush().await?;
155-
// Paces uploads to the disk. Without it, parts pile up in the page cache faster
156-
// than a slow disk writes them back, and every SQLite commit waits behind that
157-
// backlog until database requests time out.
158-
file.sync_data().await?;
159155
if let Some(parent) = path.parent() {
160156
fs::create_dir_all(parent).await?;
161157
}

‎website/src/content/docs/storage-drivers/file-system.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ The path to the filesystem storage location. The folder will be created if it do
1717

1818
The cache server process needs read and write access to this path (and permission to create it). No other permissions are required for this driver.
1919

20-
## Slow disks
21-
22-
The server syncs each uploaded part to disk before it confirms the part. Uploads therefore run at the speed of the disk, and unwritten data can't pile up in memory and stall the SQLite database behind it.
23-
2420
## Eager merge
2521

2622
The filesystem driver has no direct downloads, so [`EAGER_MERGE`](/configuration#eager_merge) gains little here. It copies the parts into the merged file at upload time and doubles disk use per entry until the parts cleanup job runs. Leave it off unless you want the first restore to read a single file.

0 commit comments

Comments
 (0)