runtime: per-container memory and CPU limits#68
Conversation
Adds RunSpec.MemoryBytes (int64) and RunSpec.NanoCPUs (int64) so
callers can size each container's resources. Docker enforces via
cgroups (HostConfig.Memory + NanoCPUs); apple enforces by sizing the
per-container VM at boot (ContainerConfiguration.resources.cpus +
memoryInBytes). Apple's apiserver takes integer CPU counts, so the
bridge rounds fractional nano-cpus up to the next whole CPU.
Compose orchestrator reads from deploy.resources.limits (memory +
cpus) with a fallback to the legacy top-level mem_limit / cpus, which
matches docker compose's own precedence.
Loosens the §2.2 refusal of deploy: — we now accept deploy when it
only carries resources.limits with memory/cpus. Anything else inside
deploy (replicas, mode, placement, update_config, rollback_config,
restart_policy, endpoint_mode, labels, reservations, pids, devices,
generic_resources) keeps its specific typed refusal so users see what
to drop. Updates the two existing tests that used an empty Deploy{}
as a refusal trigger to use Deploy{Mode: "global"} instead.
Motivation: bringing up the dap monorepo on the applecontainer
backend, pnpm install on the app service got OOM-killed at apple's
1 GiB per-VM default. Without RunSpec resource fields, callers had no
way to raise the limit through this library.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR adds end-to-end container resource limit support: it defines ChangesContainer resource limits (memory and CPU)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Adds
RunSpec.MemoryBytes(int64) andRunSpec.NanoCPUs(int64) so callers can size each container's resources through this library. Maps to:HostConfig.Memory+HostConfig.NanoCPUs(cgroup enforcement).ContainerConfiguration.resources.memoryInBytes+.cpus, sizing the per-container VM at boot. Apple takes an integer CPU count, so the bridge rounds fractional nano-cpus up to the next whole CPU (e.g.1_500_000_000→ 2 cpus).Compose orchestrator translates
deploy.resources.limits.{memory,cpus}with a fallback to the legacy top-levelmem_limit/cpus, matching docker compose's own precedence.Loosens the §2.2 refusal of
deploy:— we now acceptdeploy:when it only carriesresources.limitswith memory/cpus. Everything else insidedeploy:(replicas, mode, placement, update_config, rollback_config, restart_policy, endpoint_mode, labels, reservations, pids, devices, generic_resources) keeps a specific typed refusal so the user sees exactly what to drop.Motivation
Bringing up the dap monorepo on the applecontainer backend,
pnpm installon theappservice got OOM-killed at apple's 1 GiB per-VM default. Without resource fields onRunSpec, callers had no way to raise the limit through this library.After this PR,
deploy.resources.limits.memory: 8gin the dap compose file flows through to apple's VM at boot — verified end-to-end:MemTotal=8222028 kBreported inside the container.Test plan
go test ./compose/... ./runtime/...(unit + bridge integration)TestUp_ResourceLimitsTranslatepins compose → RunSpec translation across modern/legacy/precedence/unset cases.appservice comes up with 8 GiB / 6 CPUs as specified.Deploy: &DeployConfig{}refusal tests updated to useMode: "global"(an actually-unsupported sub-field) since empty Deploy is now accepted.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
deploy.resources.limitssettings.Improvements
Tests