Repository navigation
feat(commons): ConnectionPool.setProperty / setProperties for the DuckDB instance, the memory reserve included - #524
Closed
tanejagagan wants to merge 2 commits into
Conversation
…nus reserve Left unset, DuckDB sizes memory_limit from the memory it can see -- the cgroup limit in a container -- as if the process were DuckDB alone. It shares the process with the JVM: heap, Metaspace, threads, agents and Arrow's off-heap buffers sit on top of DuckDB's buffer pool under the same limit, so DuckDB's default plus the JVM can exceed the container's limit, and the kernel OOM-kills the process before DuckDB spills. Each service has had to hand-size memory_limit against its container limit and heap, and keep the two in step. ConnectionPool now sets, when duckdb.properties has no memory_limit: memory_limit = total - max heap - reserve (floor 128 MiB) total is the JVM's view of the machine (OperatingSystemMXBean getTotalMemorySize: the cgroup limit under UseContainerSupport), max heap is Runtime.maxMemory(), reserve defaults to 512 MiB for everything outside the heap. E.g. a 2 GiB container whose JVM has a 512 MiB max heap gets 1024 MiB. The computed value is logged at startup. Precedence: memory_limit in duckdb.properties wins; a startup script's SET memory_limit overrides later. -Ddazzleduck.duckdb.auto_memory_limit=false keeps DuckDB's own default; -Ddazzleduck.duckdb.memory_reserve_mib=N changes the reserve. Unknown total or unbounded heap leaves DuckDB's default, with a warning; a budget under 128 MiB is floored, with a warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kDB instance's properties, the memory reserve included The reserve was fixed at 512 MiB unless a -D system property said otherwise, so a service could not size it from its own configuration. ConnectionPool.setProperty (one) and setProperties (several, all checked before any is applied) take properties before the first connection: a DuckDB option (overriding duckdb.properties), or one of DazzleDuck's own keys, dazzleduck.duckdb.memory_reserve_mib and dazzleduck.duckdb.auto_memory_limit, which are removed before the properties reach DuckDB. The same keys work in duckdb.properties, with the system properties as the fallback. The instance is now created on the first connection instead of with the enum, since any static call initializes the enum and would arrive too late. A property set after that throws instead of being ignored, and a negative or non-numeric reserve is rejected rather than ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Superseded by #525: only the ConnectionPool change, without the computed memory_limit. |
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.
Summary
Builds on #523, which computes DuckDB's
memory_limitas container − heap − reserve. In #523 the reserve was fixed at 512 MiB unless a-Dsystem property said otherwise, so a service couldn't size it from its own configuration. This PR adds an API to set it, and any other DuckDB property, before the instance is created.This PR contains #523's commit. A PR from another fork can't use #523's branch as its base. Merge #523 first and this one shows only its own commit, or merge this one in place of #523.
setPropertysets one property andsetPropertiessets several.setPropertieschecks every entry before applying any, so one bad entry leaves none set.memory_limit,threads, ...) are passed through. DazzleDuck's owndazzleduck.duckdb.memory_reserve_mibanddazzleduck.duckdb.auto_memory_limitare used to compute the limit and then removed, because DuckDB rejects options it doesn't know. The same keys also work induckdb.properties. System properties with those names still work if neither sets them.setProperty/setPropertieswin overduckdb.properties, which wins over the computedmemory_limit. A startup script'sSET memory_limitstill overrides all of them.setPropertywould always have come too late. No callers change.IllegalStateExceptioninstead of being silently ignored. A negative or non-numeric reserve throwsIllegalArgumentException; feat(commons): default DuckDB memory_limit to container minus heap minus reserve #523 ignored it and used 512.Not in this PR
No service calls the API from its own config yet. In
Runtime, the call would go just beforeexecuteOnSingleton(startupScript); the otel collector and compactor would need the same.Tests
DuckDBMemoryLimitTestgains three tests: properties win over system properties and aren't passed to DuckDB; a bad reserve is rejected; setting properties after the instance exists is refused, for both variants.dazzleduck-sql-commonssuite: 784 run, 0 failures, 8 skipped (JDK 25). Javadoc builds.🤖 Generated with Claude Code