fix(compiler): cap DuckDB threads so a cgroup-capped instance doesn't OOM at boot#42
Merged
Merged
Conversation
… OOM at boot DuckDB honors the memory cgroup (memory_limit ~= 80% of the container limit) but scales its thread count to the HOST core count, ignoring the CPU cgroup. In a 1 GB container on a 12-core host that's 12 threads sharing an 819 MiB cap (~68 MiB/thread, below DuckDB's ~125 MiB/thread floor), which OOMs at boot validation: 'failed to pin block of size 256.0 KiB'. Pin threads to 4 in createInMemoryDuckDB so every instance stays within the cap regardless of host core count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #41. With the `.tmp` spill bug fixed, the NAS container exposed a second, distinct failure at boot validation:
```
dataset 'macro_breakdown_today': Out of Memory Error: failed to pin block of
size 256.0 KiB (819.0 MiB/819.1 MiB used)
```
Root cause
DuckDB honors the memory cgroup (auto `memory_limit` ≈ 80% of the 1 GB container = 819 MiB) but scales its thread count to the host core count, ignoring the (absent) CPU cgroup. On a 12-core host that's 12 threads sharing 819 MiB ≈ 68 MiB/thread — below DuckDB's recommended ~125 MiB/thread floor — so the buffer manager can't pin blocks and OOMs at boot. The data is tiny (~5 MB); this is purely a thread-count vs. memory-cap mismatch, not data volume.
Fix
Pin `threads: "4"` in `createInMemoryDuckDB()` so every in-memory instance stays within a cgroup-capped budget regardless of host core count (>125 MiB/thread at 819 MiB; DuckDB clamps to core count on smaller boxes). `memory_limit` is left to DuckDB's correct cgroup-aware default.
Test
Added a guard in `writers.test.ts` asserting `threads=4` and a writable `temp_directory`. `pnpm build && pnpm typecheck && pnpm test && pnpm lint` all pass.