From b04bcb5b0cf8dc4164419f5a7421cbad94087fe4 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Thu, 23 Apr 2026 15:52:35 +0100 Subject: [PATCH] feat(base): env var for duckdb reader-pool size --- .../core/base/query-cache/query-cache.config.ts | 2 ++ .../environment/environment.service.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/apps/server/src/core/base/query-cache/query-cache.config.ts b/apps/server/src/core/base/query-cache/query-cache.config.ts index 44b7d3f5..1f0dd3af 100644 --- a/apps/server/src/core/base/query-cache/query-cache.config.ts +++ b/apps/server/src/core/base/query-cache/query-cache.config.ts @@ -10,6 +10,7 @@ export type QueryCacheConfig = { threads: number; trace: boolean; tempDirectory: string; + readerPoolSize: number; }; @Injectable() @@ -25,6 +26,7 @@ export class QueryCacheConfigProvider { threads: env.getBaseQueryCacheThreads(), trace: env.getBaseQueryCacheTrace(), tempDirectory: env.getBaseQueryCacheTempDirectory(), + readerPoolSize: env.getBaseQueryCacheReaderPoolSize(), }; } } diff --git a/apps/server/src/integrations/environment/environment.service.ts b/apps/server/src/integrations/environment/environment.service.ts index 3ef0b95b..74ef4d8e 100644 --- a/apps/server/src/integrations/environment/environment.service.ts +++ b/apps/server/src/integrations/environment/environment.service.ts @@ -385,4 +385,20 @@ export class EnvironmentService { 10, ); } + + getBaseQueryCacheReaderPoolSize(): number { + // Number of reader connections held open against the shared DuckDB + // instance. Reads are dispatched via `withReader()` which checks out a + // connection, runs the query, returns it. Bigger pool = more concurrent + // reads without serialization, at the cost of per-connection overhead + // (each connection carries its own catalog snapshot + prepared-statement + // cache ~= 300 KB). + // + // Default 4 matches libuv's default thread-pool size. Raise to 8+ if + // you see p99 list latency correlate with concurrent request volume. + return parseInt( + this.configService.get('BASE_QUERY_CACHE_READER_POOL_SIZE', '4'), + 10, + ); + } }