Skip to content

fix(docker): raise JVM direct memory above the app's baseline footprint - #1414

Merged
FelixTJDietrich merged 1 commit into
mainfrom
fix/jvm-direct-memory
Jul 21, 2026
Merged

fix(docker): raise JVM direct memory above the app's baseline footprint#1414
FelixTJDietrich merged 1 commit into
mainfrom
fix/jvm-direct-memory

Conversation

@FelixTJDietrich

@FelixTJDietrich FelixTJDietrich commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Incident

Login (and every DB-backed request) failing. From the app-server logs:

OutOfMemoryError: Cannot reserve 8192 bytes of direct buffer memory (limit: 10485760)
  at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication
→ HikariPool-1 - Connection is not available, request timed out after 45000ms

Root cause (verified, not a bandaid)

NMT on staging shows the direct-buffer pool is ~14 MB and flat (two samples, 30s apart → no growth):

Other (direct buffers): 14,553 KB … 14,553 KB

No leak, no unbounded spike — the app's steady off-heap footprint just sits above the buildpack's 10 MB default, so Postgres couldn't get the small buffer for its connection handshake and the pool drained. The 10 MB default is an arbitrary Cloud Foundry inheritance, not tuned for this app.

Sizing — why 128 MB (not 256)

On a container the memory calculator budgets direct memory against heap (10M direct + 240M code + 250M stacks + metaspace + heap), so an oversized cap steals heap. Best practice is to size to actual usage + headroom, not a round large number (BellSoft JVM memory guide, GigaSpaces JVM tuning).

Against ~14 MB steady, 128 MB is ~9× headroom — comfortably above the 10 MB that OOM'd and any observed level, with room for backfill bursts — while returning ~128 MB to heap versus a 256 MB cap. Env-overridable via APP_MAX_DIRECT_MEMORY if a heavy backfill ever approaches it.

Scope

Set via JAVA_TOOL_OPTIONS, which the buildpack honors (detects the user flag, skips its own 10 MB, re-budgets heap within mem_limit).

Verification

Applied live on staging (that restored login): OOM/pool timeouts stopped, readiness UP, GET /api/identity-providers returns the provider list. This PR makes it durable. docker compose config validates.

🤖 Generated with Claude Code

@FelixTJDietrich
FelixTJDietrich requested a review from a team as a code owner July 21, 2026 13:29
@github-actions github-actions Bot added bug Something isn't working ci GitHub Actions, workflows, build pipeline changes infrastructure Docker, containers, and deployment infrastructure size:S labels Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Docker Compose application services now configure JVM direct memory through APP_MAX_DIRECT_MEMORY, defaulting to 256M. A changeset documents the patch release and operator override.

Changes

JVM Direct Memory Configuration

Layer / File(s) Summary
Configure service direct memory
docker/compose.app.yaml, docker/preview/compose.app.yaml, .changeset/jvm-direct-memory.md
Application server, worker, and preview appserver services set JAVA_TOOL_OPTIONS with a configurable 256M direct-memory default; the changeset documents the release and override variable.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: increasing JVM direct memory in Docker configs.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/jvm-direct-memory

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@FelixTJDietrich
FelixTJDietrich force-pushed the fix/jvm-direct-memory branch from e7bd658 to 546bccc Compare July 21, 2026 13:35
@FelixTJDietrich FelixTJDietrich changed the title fix(docker): raise JVM direct memory so I/O can't starve Postgres fix(docker): raise JVM direct memory above the app's baseline footprint Jul 21, 2026
The buildpack pins -XX:MaxDirectMemorySize=10M (an arbitrary Cloud Foundry
inheritance), which sits just below the application server's steady off-heap NIO
footprint (NATS + HTTP; measured ~14M, flat). Once it fills, Postgres can't
allocate the direct buffer for its connection handshake, the Hikari pool drains,
and every DB-backed request fails — including login. Not a leak or a load spike:
the default is simply too low.

Pin MaxDirectMemorySize to 128M (~9x the steady footprint; env-overridable via
APP_MAX_DIRECT_MEMORY) on the server and worker roles, and on the preview
app-server where it first surfaced. The buildpack re-budgets heap to stay within
mem_limit, so the value is kept close to need rather than over-reserving heap.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012stCYrymLyX9VZ8PrPUs88
@FelixTJDietrich
FelixTJDietrich force-pushed the fix/jvm-direct-memory branch from 546bccc to 9bc760f Compare July 21, 2026 13:41
@FelixTJDietrich
FelixTJDietrich merged commit a425261 into main Jul 21, 2026
21 of 22 checks passed
@FelixTJDietrich
FelixTJDietrich deleted the fix/jvm-direct-memory branch July 21, 2026 13:41
@github-actions

Copy link
Copy Markdown
Contributor

📚 Documentation Preview

Preview has been removed (PR closed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci GitHub Actions, workflows, build pipeline changes infrastructure Docker, containers, and deployment infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant