A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
perf(api): vacuum the kv table on a fixed dead-row threshold
Hampus9040f1b70ee6
diff --git a/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts b/fluxer_api/src/api/database/PostgresKvQueryExecutor.tsindex 35584455e..4876f7339 100644--- a/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts+++ b/fluxer_api/src/api/database/PostgresKvQueryExecutor.ts@@ -95,7 +95,13 @@ const POSTGRES_KV_MESSAGES_PARTITION_MIGRATION = 'messages_partition_key_v1';const POSTGRES_KV_SORT_ID_MIGRATION = 'sort_id_v1';const POSTGRES_KV_SORT_ID_TABLES = ['messages', 'message_reactions'];const POSTGRES_KV_SORT_ID_BACKFILL_BATCH = 5000;-const POSTGRES_KV_STORAGE_OPTIONS = ['fillfactor=85'];+const POSTGRES_KV_STORAGE_OPTIONS = [+ 'fillfactor=85',+ 'autovacuum_vacuum_scale_factor=0',+ 'autovacuum_vacuum_threshold=20000',+ 'autovacuum_vacuum_insert_scale_factor=0.05',+ 'autovacuum_analyze_scale_factor=0.01',+];const POSTGRES_KV_ALTER_LOCK_TIMEOUT = '10s';const POSTGRES_KV_SCHEMA_ATTEMPTS = 3;const KV_WRITE_PARALLELISM = 4;diff --git a/fluxer_api/src/api/database/PostgresKvRustParity.test.ts b/fluxer_api/src/api/database/PostgresKvRustParity.test.tsindex b03c67b1c..71a5bfd81 100644--- a/fluxer_api/src/api/database/PostgresKvRustParity.test.ts+++ b/fluxer_api/src/api/database/PostgresKvRustParity.test.ts@@ -69,6 +69,14 @@ describe('Postgres KV schema parity between the API and fluxer_svc', () => {}});+ it('sets the same table storage options', () => {+ const typescript = /POSTGRES_KV_STORAGE_OPTIONS = \[([^\]]*)\]/.exec(TYPESCRIPT_SOURCE)?.[1] ?? '';+ const rust = /POSTGRES_KV_STORAGE_OPTIONS: &\[&str\] = &\[([^\]]*)\]/.exec(RUST_SOURCE)?.[1] ?? '';+ const options = (list: string) => [...list.matchAll(/['"]([a-z_]+=[0-9.]+)['"]/g)].map((match) => match[1]);+ expect(options(typescript).length).toBeGreaterThan(0);+ expect(options(rust)).toEqual(options(typescript));+ });+it('fills and reads sort ids for the same tables', () => {expect(TYPESCRIPT_SOURCE).toContain("POSTGRES_KV_SORT_ID_TABLES = ['messages', 'message_reactions']");expect(RUST_SOURCE).toContain('POSTGRES_KV_SORT_ID_TABLES: &[&str] = &["messages", "message_reactions"]');diff --git a/fluxer_svc/src/postgres.rs b/fluxer_svc/src/postgres.rsindex 0cdfe1baa..8fa9d8dc6 100644--- a/fluxer_svc/src/postgres.rs+++ b/fluxer_svc/src/postgres.rs@@ -29,7 +29,13 @@ const POSTGRES_KV_MESSAGES_PARTITION_MIGRATION: &str = "messages_partition_key_vconst POSTGRES_KV_SORT_ID_MIGRATION: &str = "sort_id_v1";const POSTGRES_KV_SORT_ID_TABLES: &[&str] = &["messages", "message_reactions"];const POSTGRES_KV_SORT_ID_RECHECK: Duration = Duration::from_secs(30);-const POSTGRES_KV_STORAGE_OPTIONS: &[&str] = &["fillfactor=85"];+const POSTGRES_KV_STORAGE_OPTIONS: &[&str] = &[+ "fillfactor=85",+ "autovacuum_vacuum_scale_factor=0",+ "autovacuum_vacuum_threshold=20000",+ "autovacuum_vacuum_insert_scale_factor=0.05",+ "autovacuum_analyze_scale_factor=0.01",+];const POSTGRES_KV_ALTER_LOCK_TIMEOUT: &str = "10s";const POSTGRES_KV_SCHEMA_ATTEMPTS: u32 = 3;const POSTGRES_KV_SCHEMA_RETRY_DELAY: Duration = Duration::from_millis(250);