Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): SQLite checkpoints no longer block the event loop #19324

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/19324/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 4 changed files with 93 additions and 24 deletions (loading 1).

x
0 of 4 viewed, 4 left
6 additions and 24 deletionsapps/server/src/persistence/Sqlite.test.tsModified
View file
@@ -58,31 +58,13 @@
);
});
​
-it.effect("shrinks the WAL file back to the size limit after a large write", () => {
- const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-sqlite-wal-"));
- const dbPath = NodePath.join(tempDir, "state.sqlite");
- const walFileSize = () => NodeFS.statSync(`${dbPath}-wal`).size;
- // About 25% more 4 KB rows than the limit holds, in one transaction.
- const rowCount = Math.ceil((WAL_SIZE_LIMIT_BYTES * 1.25) / 4000);
-​
- return Effect.gen(function* () {
+it.effect("limits the WAL file size in the shared persistence setup", () =>
+ Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
- yield* sql`CREATE TABLE wal_probe(payload BLOB)`;
- yield* sql`
- WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < ${rowCount})
- INSERT INTO wal_probe(payload) SELECT randomblob(4000) FROM n
- `;
- assert.isAbove(walFileSize(), WAL_SIZE_LIMIT_BYTES);
-​
- // The auto-checkpoint after the large commit copied every frame into the
- // database, so the next commit restarts the WAL and cuts the file back.
- yield* sql`INSERT INTO wal_probe(payload) VALUES (x'00')`;
- assert.isAtMost(walFileSize(), WAL_SIZE_LIMIT_BYTES);
- }).pipe(
- Effect.provide(SqlitePersistence.layerFromPath(dbPath).pipe(Layer.provide(NodeServices.layer))),
- Effect.ensuring(Effect.sync(() => NodeFS.rmSync(tempDir, { recursive: true, force: true }))),
- );