From cc0d99f1e8210ebb870ae3e7518331f5520ecee1 Mon Sep 17 00:00:00 2001 From: Daniel <115043334+danielxnj@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:15:11 -0500 Subject: [PATCH 1/2] feat(k8s): let large workers reserve less memory than their limit Add DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT (75-100, default 100). It lowers the memory request of workers of 64Gi or more. The limit and the DuckDB memory_limit do not change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01GepAgyXv5zVvQV5cbnRF8F --- cmd/duckgres-controlplane/main.go | 1 + configresolve/resolve.go | 10 ++++ configresolve/resolve_k8s_test.go | 31 ++++++++++ controlplane/control.go | 5 ++ controlplane/headroom.go | 3 +- controlplane/headroom_test.go | 21 +++++++ controlplane/k8s_pool.go | 4 ++ controlplane/k8s_pool_spawn.go | 36 +++++++++--- controlplane/k8s_pool_test.go | 58 ++++++++++++++++++- controlplane/multitenant.go | 1 + controlplane/worker_pool.go | 11 ++++ .../connection-string-worker-profile.md | 2 +- docs/design/worker-ttl-pool.md | 2 +- k8s/README.md | 1 + main.go | 1 + 15 files changed, 175 insertions(+), 12 deletions(-) diff --git a/cmd/duckgres-controlplane/main.go b/cmd/duckgres-controlplane/main.go index b082c4cb3..708be06ab 100644 --- a/cmd/duckgres-controlplane/main.go +++ b/cmd/duckgres-controlplane/main.go @@ -265,6 +265,7 @@ func main() { ServiceAccount: resolved.K8sWorkerServiceAccount, WorkerCPURequest: resolved.K8sWorkerCPURequest, WorkerMemoryRequest: resolved.K8sWorkerMemoryRequest, + WorkerMemoryRequestPercent: resolved.K8sWorkerMemoryRequestPercent, WorkerNodeSelector: resolved.K8sWorkerNodeSelector, WorkerTolerationKey: resolved.K8sWorkerTolerationKey, WorkerTolerationValue: resolved.K8sWorkerTolerationValue, diff --git a/configresolve/resolve.go b/configresolve/resolve.go index f74d28d55..2f1db157c 100644 --- a/configresolve/resolve.go +++ b/configresolve/resolve.go @@ -105,6 +105,7 @@ type Resolved struct { K8sWorkerServiceAccount string K8sWorkerCPURequest string K8sWorkerMemoryRequest string + K8sWorkerMemoryRequestPercent int K8sWorkerNodeSelector string K8sWorkerTolerationKey string K8sWorkerTolerationValue string @@ -208,6 +209,7 @@ func ResolveEffective(fileCfg *configloader.FileConfig, cli CLIInputs, getenv fu var k8sWorkerSecret, k8sWorkerConfigMap, k8sWorkerImagePullPolicy string k8sWorkerServiceAccount := controlplane.DefaultK8sWorkerServiceAccount var k8sWorkerCPURequest, k8sWorkerMemoryRequest string + var k8sWorkerMemoryRequestPercent int var k8sWorkerNodeSelector, k8sWorkerTolerationKey, k8sWorkerTolerationValue string var k8sReshardPodCPU, k8sReshardPodMemory string var k8sExploratoryTierEnabled bool @@ -807,6 +809,13 @@ func ResolveEffective(fileCfg *configloader.FileConfig, cli CLIInputs, getenv fu if v := getenv("DUCKGRES_K8S_WORKER_MEMORY_REQUEST"); v != "" { k8sWorkerMemoryRequest = v } + if v := getenv("DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT"); v != "" { + if n, err := strconv.Atoi(v); err == nil && n >= controlplane.MinWorkerMemoryRequestPercent && n <= 100 { + k8sWorkerMemoryRequestPercent = n + } else { + warn("Invalid DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT (want " + strconv.Itoa(controlplane.MinWorkerMemoryRequestPercent) + "-100): " + v) + } + } if v := getenv("DUCKGRES_K8S_WORKER_NODE_SELECTOR"); v != "" { k8sWorkerNodeSelector = v } @@ -1196,6 +1205,7 @@ func ResolveEffective(fileCfg *configloader.FileConfig, cli CLIInputs, getenv fu K8sWorkerServiceAccount: k8sWorkerServiceAccount, K8sWorkerCPURequest: k8sWorkerCPURequest, K8sWorkerMemoryRequest: k8sWorkerMemoryRequest, + K8sWorkerMemoryRequestPercent: k8sWorkerMemoryRequestPercent, K8sWorkerNodeSelector: k8sWorkerNodeSelector, K8sWorkerTolerationKey: k8sWorkerTolerationKey, K8sWorkerTolerationValue: k8sWorkerTolerationValue, diff --git a/configresolve/resolve_k8s_test.go b/configresolve/resolve_k8s_test.go index 6884bea72..1d33f4748 100644 --- a/configresolve/resolve_k8s_test.go +++ b/configresolve/resolve_k8s_test.go @@ -94,6 +94,37 @@ func TestResolveEffectiveRejectsInvalidClientIdleTimeoutMax(t *testing.T) { } } +func TestResolveEffectiveK8sWorkerMemoryRequestPercent(t *testing.T) { + for _, tc := range []struct { + value string + want int + warns int + }{ + {"", 0, 0}, + {"75", 75, 0}, + {"100", 100, 0}, + {"74", 0, 1}, + {"101", 0, 1}, + {"75%", 0, 1}, + } { + t.Run(tc.value, func(t *testing.T) { + var warned []string + resolved := ResolveEffective(nil, CLIInputs{}, func(key string) string { + if key == "DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT" { + return tc.value + } + return "" + }, func(msg string) { warned = append(warned, msg) }) + if resolved.K8sWorkerMemoryRequestPercent != tc.want { + t.Fatalf("K8sWorkerMemoryRequestPercent = %d, want %d", resolved.K8sWorkerMemoryRequestPercent, tc.want) + } + if len(warned) != tc.warns { + t.Fatalf("warnings = %v, want %d", warned, tc.warns) + } + }) + } +} + func TestResolveEffectiveParsesK8sWorkerDefaultTTL(t *testing.T) { resolved := ResolveEffective(nil, CLIInputs{}, func(key string) string { if key == "DUCKGRES_K8S_WORKER_DEFAULT_TTL" { diff --git a/controlplane/control.go b/controlplane/control.go index 70d1c2a00..b0a2ee481 100644 --- a/controlplane/control.go +++ b/controlplane/control.go @@ -166,6 +166,11 @@ type K8sConfig struct { WorkerPriorityClassName string // PriorityClass for worker pods, so they preempt overprovision headroom pause pods (empty = none) AWSRegion string // AWS region for STS client + // WorkerMemoryRequestPercent sets the memory request of large worker pods as + // a percent of their memory limit (env-only + // DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT). 0 or 100 = equal to the limit. + WorkerMemoryRequestPercent int + // Reshard runner pod shape (env-only DUCKGRES_RESHARD_POD_CPU / // DUCKGRES_RESHARD_POD_MEMORY; requests=limits, Guaranteed QoS). Empty = // built-in defaults (2 CPU / 8Gi). Reshard ops run in dedicated per-op diff --git a/controlplane/headroom.go b/controlplane/headroom.go index 88b4aaf4d..b46c933d1 100644 --- a/controlplane/headroom.go +++ b/controlplane/headroom.go @@ -287,7 +287,8 @@ func (p *K8sWorkerPool) headroomTarget(ctx context.Context) (headroomPlan, bool) slog.Warn("Headroom: invalid default worker memory for placeholder sizing.", "value", p.workerMemoryRequest, "error", err) return headroomPlan{}, false } - memBytes = q.Value() + req := p.workerMemoryRequestForLimit(q) + memBytes = req.Value() } plan.cpu = *resource.NewMilliQuantity(cpuMillis, resource.DecimalSI) plan.mem = *resource.NewQuantity(memBytes, resource.BinarySI) diff --git a/controlplane/headroom_test.go b/controlplane/headroom_test.go index 64ca5c9f0..b5be8f0d4 100644 --- a/controlplane/headroom_test.go +++ b/controlplane/headroom_test.go @@ -193,6 +193,27 @@ func TestReconcileHeadroomFreshClusterFallsBackToDefaultShape(t *testing.T) { } } +// The configured fallback shape reserves what a real worker of that shape +// requests, so it follows the lowered memory request of a large worker. +func TestReconcileHeadroomFallbackUsesWorkerMemoryRequest(t *testing.T) { + cs := fake.NewSimpleClientset() + emulateGenerateName(cs) + p := newHeadroomPool(cs, &fakeSpawnLogStore{}) + p.workerCPURequest = "15" + p.workerMemoryRequest = "120Gi" + p.workerMemoryRequestPercent = 75 + + p.reconcileHeadroom(context.Background()) + + pods := listHeadroomPods(t, cs) + if len(pods) != 1 { + t.Fatalf("expected 1 placeholder, got %d", len(pods)) + } + if got := pods[0].Spec.Containers[0].Resources.Requests.Memory().Value(); got != 90<<30 { + t.Fatalf("placeholder memory request = %d, want 90Gi", got) + } +} + // The fleet-relative cap bounds a spawn storm: peak burst 50 with 20 live // workers is capped at ceil(25% × 20) = 5 — fleet size is the CEILING, never // the target, so a big fleet alone (peak 0) still gets only the floor. diff --git a/controlplane/k8s_pool.go b/controlplane/k8s_pool.go index 203e915f7..799f1cca6 100644 --- a/controlplane/k8s_pool.go +++ b/controlplane/k8s_pool.go @@ -75,6 +75,9 @@ type K8sWorkerPool struct { workerTolerationValue string // taint value for NoSchedule toleration workerPriorityClassName string // PriorityClass for worker pods (preempts overprovision pause pods) + // Memory request of large workers as a percent of the limit; 0 = equal to the limit. + workerMemoryRequestPercent int + // Headroom controller holds preemptible low-priority placeholder pods so a // worker spawn schedules immediately (preempting a placeholder) instead of // waiting on a fresh Karpenter node. Slot count and size are derived @@ -202,6 +205,7 @@ func newK8sWorkerPool(cfg K8sWorkerPoolConfig, clientset kubernetes.Interface) ( workerTolerationValue: cfg.WorkerTolerationValue, workerPriorityClassName: cfg.WorkerPriorityClassName, + workerMemoryRequestPercent: cfg.WorkerMemoryRequestPercent, placeholderImage: cfg.PlaceholderImage, placeholderPriorityClassName: cfg.PlaceholderPriorityClassName, diff --git a/controlplane/k8s_pool_spawn.go b/controlplane/k8s_pool_spawn.go index 04be6e846..ae157092d 100644 --- a/controlplane/k8s_pool_spawn.go +++ b/controlplane/k8s_pool_spawn.go @@ -533,8 +533,8 @@ func (p *K8sWorkerPool) spawnReservedWorkerForSlot(ctx context.Context, id int, // workerResources returns resource requests and limits for a worker pod. // Set via DUCKGRES_K8S_WORKER_CPU_REQUEST / DUCKGRES_K8S_WORKER_MEMORY_REQUEST. -// Returns empty (BestEffort) if neither is set. -// When set, limits are equal to requests (Guaranteed QoS). +// Limits are equal to requests (Guaranteed QoS), except for the memory request +// of a large worker when workerMemoryRequestPercent is below 100. func (p *K8sWorkerPool) workerResources() corev1.ResourceRequirements { return p.workerResourcesForProfile(WorkerProfile{}) } @@ -650,11 +650,12 @@ func (p *K8sWorkerPool) workerPodEnv(secretName string, workerResources corev1.R } // workerMemoryHygieneEnv derives the memory/thread env vars for a worker pod -// from its resolved resource requests. See the call site comment in -// spawnWorker for why these must be set before any session exists. +// from its resolved resources. Memory comes from the limit (the pod cgroup): +// the request can be lower, see workerMemoryRequestPercent. See the call site +// comment in spawnWorker for why these must be set before any session exists. func workerMemoryHygieneEnv(res corev1.ResourceRequirements) []corev1.EnvVar { var env []corev1.EnvVar - if mem, ok := res.Requests[corev1.ResourceMemory]; ok { + if mem, ok := res.Limits[corev1.ResourceMemory]; ok { memBytes := uint64(mem.Value()) if lim := duckdbMemoryLimitForPodMemory(memBytes); lim != "" { env = append(env, corev1.EnvVar{Name: "DUCKGRES_MEMORY_LIMIT", Value: lim}) @@ -674,9 +675,10 @@ func workerMemoryHygieneEnv(res corev1.ResourceRequirements) []corev1.EnvVar { // workerResourcesForProfile builds the pod resource requirements for a worker of // the given profile: the profile's CPU/Memory when set, otherwise the pool-global // request (today's behavior). Requests are mirrored to Limits so the pod is -// Guaranteed QoS — required before bin-packing colocated workers. A colocated -// profile always carries non-empty CPU/Memory (resolver-enforced), so it never -// degrades to BestEffort. +// Guaranteed QoS — required before bin-packing colocated workers. The one +// exception is the memory request of a large worker, which +// workerMemoryRequestPercent can lower. A colocated profile always carries +// non-empty CPU/Memory (resolver-enforced), so it never degrades to BestEffort. func (p *K8sWorkerPool) workerResourcesForProfile(profile WorkerProfile) corev1.ResourceRequirements { // Workers must never be BestEffort: with no pod anti-affinity, resource // requests are the ONLY thing keeping two workers from overcommitting a @@ -706,5 +708,23 @@ func (p *K8sWorkerPool) workerResourcesForProfile(profile WorkerProfile) corev1. for k, v := range requests { limits[k] = v.DeepCopy() } + memLimit := limits[corev1.ResourceMemory] + requests[corev1.ResourceMemory] = p.workerMemoryRequestForLimit(memLimit) return corev1.ResourceRequirements{Requests: requests, Limits: limits} } + +// workerMemoryRequestForLimit returns the memory request of a worker pod with +// the given memory limit: workerMemoryRequestPercent of the limit for a large +// worker, and the limit itself for every other worker. +// +// DuckDB's memory_limit is at most 75% of the pod (workerMemoryHeadroomBytes), +// so a request of at least MinWorkerMemoryRequestPercent still reserves all of +// it. Only the headroom above memory_limit is shared between the workers of a +// node. Small workers are excluded: they use most of their headroom. +func (p *K8sWorkerPool) workerMemoryRequestForLimit(limit resource.Quantity) resource.Quantity { + pct := int64(p.workerMemoryRequestPercent) + if pct < MinWorkerMemoryRequestPercent || pct >= 100 || limit.Value() < workerMemoryRequestPercentMinBytes { + return limit.DeepCopy() + } + return *resource.NewQuantity(limit.Value()*pct/100, resource.BinarySI) +} diff --git a/controlplane/k8s_pool_test.go b/controlplane/k8s_pool_test.go index 35f299cce..9eaf5be6c 100644 --- a/controlplane/k8s_pool_test.go +++ b/controlplane/k8s_pool_test.go @@ -3356,6 +3356,54 @@ func TestWorkerResources_NeitherSet(t *testing.T) { } } +// A lowered memory request applies to large workers only. Their limit and their +// CPU stay as they are, and every other worker keeps Guaranteed QoS. +func TestWorkerResources_MemoryRequestPercent(t *testing.T) { + cases := []struct { + name string + percent int + memory string + want string + }{ + {"unset keeps request equal to limit", 0, "360Gi", "360Gi"}, + {"100 keeps request equal to limit", 100, "360Gi", "360Gi"}, + {"below the minimum is ignored", 50, "360Gi", "360Gi"}, + {"75 percent of a large worker", 75, "360Gi", "270Gi"}, + {"75 percent of the pool default", 75, "120Gi", "90Gi"}, + {"smallest large worker", 75, "64Gi", "48Gi"}, + {"small worker keeps request equal to limit", 75, "32Gi", "32Gi"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + pool := &K8sWorkerPool{workerMemoryRequestPercent: tc.percent} + res := pool.workerResourcesForProfile(WorkerProfile{CPU: "32", Memory: tc.memory}) + if got, want := res.Requests.Memory().Value(), resource.MustParse(tc.want); got != want.Value() { + t.Fatalf("memory request = %d, want %s", got, tc.want) + } + if got, want := res.Limits.Memory().Value(), resource.MustParse(tc.memory); got != want.Value() { + t.Fatalf("memory limit = %d, want %s", got, tc.memory) + } + if req, lim := res.Requests.Cpu(), res.Limits.Cpu(); req.Cmp(*lim) != 0 || req.String() != "32" { + t.Fatalf("cpu request/limit = %s/%s, want 32/32", req, lim) + } + }) + } +} + +// The request must always cover DuckDB's memory_limit. Only the headroom above +// it can be shared between the workers of a node. +func TestWorkerMemoryRequestCoversDuckDBMemoryLimit(t *testing.T) { + pool := &K8sWorkerPool{workerMemoryRequestPercent: MinWorkerMemoryRequestPercent} + for gib := int64(1); gib <= 512; gib++ { + limit := *resource.NewQuantity(gib<<30, resource.BinarySI) + req := pool.workerMemoryRequestForLimit(limit) + duckDB := uint64(limit.Value()) - workerMemoryHeadroomBytes(uint64(limit.Value())) + if uint64(req.Value()) < duckDB { + t.Fatalf("%dGi worker: request %d is below the DuckDB memory_limit %d", gib, req.Value(), duckDB) + } + } +} + func TestSetWorkerResources(t *testing.T) { pool := &K8sWorkerPool{ workerCPURequest: "500m", @@ -4557,7 +4605,12 @@ func TestWorkerMemoryHygieneEnv(t *testing.T) { if mem != "" { req[corev1.ResourceMemory] = resource.MustParse(mem) } - return corev1.ResourceRequirements{Requests: req} + return corev1.ResourceRequirements{Requests: req, Limits: req} + } + lowRequest := mk("32", "360Gi") + lowRequest.Requests = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("32"), + corev1.ResourceMemory: resource.MustParse("270Gi"), } cases := []struct { name string @@ -4576,6 +4629,9 @@ func TestWorkerMemoryHygieneEnv(t *testing.T) { // "4GB" here would turn the 40% reserve into 50%. {"fractional-GiB budget is not truncated to whole GB", mk("4", "8Gi"), map[string]string{ "DUCKGRES_MEMORY_LIMIT": "4915MB", "GOMEMLIMIT": "1024MiB", "DUCKGRES_THREADS": "10"}}, + // Memory sizing follows the limit (the pod cgroup), not a lowered request. + {"request below limit", lowRequest, map[string]string{ + "DUCKGRES_MEMORY_LIMIT": "270GB", "GOMEMLIMIT": "46080MiB", "DUCKGRES_THREADS": "80"}}, {"no requests -> no env", corev1.ResourceRequirements{}, map[string]string{}}, } for _, tc := range cases { diff --git a/controlplane/multitenant.go b/controlplane/multitenant.go index e08ed8f1a..1417d4d59 100644 --- a/controlplane/multitenant.go +++ b/controlplane/multitenant.go @@ -289,6 +289,7 @@ func SetupMultiTenant( ServiceAccount: cfg.K8s.ServiceAccount, WorkerCPURequest: cfg.K8s.WorkerCPURequest, WorkerMemoryRequest: cfg.K8s.WorkerMemoryRequest, + WorkerMemoryRequestPercent: cfg.K8s.WorkerMemoryRequestPercent, WorkerNodeSelector: parseNodeSelector(cfg.K8s.WorkerNodeSelector), WorkerTolerationKey: cfg.K8s.WorkerTolerationKey, WorkerTolerationValue: cfg.K8s.WorkerTolerationValue, diff --git a/controlplane/worker_pool.go b/controlplane/worker_pool.go index ea8b8a426..e63c76599 100644 --- a/controlplane/worker_pool.go +++ b/controlplane/worker_pool.go @@ -9,6 +9,16 @@ import ( ) const DefaultK8sWorkerServiceAccount = "duckgres-worker" + +// MinWorkerMemoryRequestPercent is the lowest accepted memory request of a +// worker pod, as a percent of its memory limit. It equals the largest share of +// a pod that DuckDB's memory_limit can take, so the request always covers it. +const MinWorkerMemoryRequestPercent = 75 + +// workerMemoryRequestPercentMinBytes is the smallest worker memory limit that +// WorkerMemoryRequestPercent applies to. +const workerMemoryRequestPercentMinBytes = 64 << 30 + const DefaultWorkerSpawnRetryAfter = 45 * time.Second // WorkerCapacityExhaustedError is returned when a worker can't be acquired @@ -120,6 +130,7 @@ type K8sWorkerPoolConfig struct { ServiceAccount string // ServiceAccount name for worker pods (default: "duckgres-worker") WorkerCPURequest string // CPU request for worker pods (e.g., "500m"). Empty = BestEffort. WorkerMemoryRequest string // Memory request for worker pods (e.g., "1Gi"). Empty = BestEffort. + WorkerMemoryRequestPercent int // Memory request of large worker pods as a percent of the memory limit. 0 or 100 = equal to the limit. WorkerNodeSelector map[string]string // Node selector for worker pods. Nil = no selector. WorkerTolerationKey string // Taint key for worker pod NoSchedule toleration. Empty = no toleration. WorkerTolerationValue string // Taint value for worker pod NoSchedule toleration. diff --git a/docs/design/connection-string-worker-profile.md b/docs/design/connection-string-worker-profile.md index 35f7c839c..dc5c30e04 100644 --- a/docs/design/connection-string-worker-profile.md +++ b/docs/design/connection-string-worker-profile.md @@ -24,7 +24,7 @@ options=-c duckgres.worker_tier=backfill # ergonomic alias = {cpu, mem, c - **`WorkerProfile{CPU, Memory, Colocate, NodeSelector}` is a new match dimension on `WorkerAssignment`**, orthogonal to the per-org `Image` axis — NOT folded into the image string. Pod resources/nodeSelector/anti-affinity are pool-global mutable state today, so the profile must travel per-acquisition. A reserved/warm worker may only be handed to a request whose profile `Equal()`s it; absent profile = the **default** profile, never "any". - **Default profile normalizes to empty CPU/Memory + `Colocate=false`** (NOT literal 46/360). The pool-global request applies for empty fields. This keeps pre-existing `worker_records` rows (`"","",false`) claimable with no migration `UPDATE`. - **Runtime-store delta: additive GORM columns, no `.sql` migration** (`worker_records` is AutoMigrated on boot). Adds `ProfileCPU`, `ProfileMemory`, `ProfileColocate` + composite index. -- **Guaranteed QoS already holds** (`workerResources()` copies requests→limits) and MUST be preserved; colocated profiles are always non-empty (clamped 4/16) so they never schedule BestEffort. +- **Guaranteed QoS already holds** (`workerResources()` copies requests→limits) and MUST be preserved by default. `DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT` is the one opt-in exception: it lowers the memory request of workers of 64Gi or more, never below DuckDB's `memory_limit`; colocated profiles are always non-empty (clamped 4/16) so they never schedule BestEffort. - **Wire-supplied cpu/mem are clamped to `[min,max]`, behind a per-deployment gate, and accounted against a per-org resource quota** (count-based `maxWorkers` is insufficient when pods vary ~50×). Explicit `colocate=false` is separately gated (a full node is the expensive button). - **Warmth = a shape-aware colocated warm pool + node headroom.** Each configured colocated shape (e.g. 4/16 and 8/48) is kept warm to its own target, background-replenished and topped up on claim; on top of that, overprovision pause pods on the bin-pack nodepool hold node headroom so a burst beyond the warm pool schedules without a fresh Karpenter node. Worker pods carry a PriorityClass above the pause pods so they preempt the headroom. The client's deepened `connect_timeout` + retry absorbs any residual cold-node latency. diff --git a/docs/design/worker-ttl-pool.md b/docs/design/worker-ttl-pool.md index 7898c5908..bb141503d 100644 --- a/docs/design/worker-ttl-pool.md +++ b/docs/design/worker-ttl-pool.md @@ -149,7 +149,7 @@ only) it: spawn-storm bug's placeholder cost. Fleet size is only the CEILING, never the target — an idle-worker leak cannot pull the placeholder count up (the amplification failure of the retired demand-proportional mode); -- slot SIZE = the componentwise max worker shape spawned in the last 7 days, +- slot SIZE = the componentwise max of the worker requests spawned in the last 7 days, falling back to the live fleet's max shape, then to the pool's configured/default worker request (fresh empty cluster). Client-sized (GUC) workers can exceed any configured maximum, so sizing from observed spawns is diff --git a/k8s/README.md b/k8s/README.md index 95a385826..8d69846f9 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -75,6 +75,7 @@ Key flags for Kubernetes multitenant mode: | `--k8s-worker-configmap` | `DUCKGRES_K8S_WORKER_CONFIGMAP` | ConfigMap name for worker config | | - | `DUCKGRES_K8S_WORKER_CPU_REQUEST` | Default worker pod CPU request/limit. Local manifests set `500m`; production should override for workload needs. | | - | `DUCKGRES_K8S_WORKER_MEMORY_REQUEST` | Default worker pod memory request/limit. Local manifests set `512Mi`; production should override for workload needs. | +| - | `DUCKGRES_K8S_WORKER_MEMORY_REQUEST_PERCENT` | Memory request of worker pods of 64Gi or more, as a percent (75-100) of their memory limit. Unset = 100 (Guaranteed QoS). A lower value packs large workers closer together; the limit and DuckDB's `memory_limit` do not change. | The worker Secret setting is a base name for per-worker RPC Secrets. Each worker pod gets its own derived Secret containing its RPC bearer token and TLS material. If the derived Secret does not exist, the control plane creates it before spawning the pod. diff --git a/main.go b/main.go index 65fe62d3b..87570d59d 100644 --- a/main.go +++ b/main.go @@ -408,6 +408,7 @@ func main() { ServiceAccount: resolved.K8sWorkerServiceAccount, WorkerCPURequest: resolved.K8sWorkerCPURequest, WorkerMemoryRequest: resolved.K8sWorkerMemoryRequest, + WorkerMemoryRequestPercent: resolved.K8sWorkerMemoryRequestPercent, WorkerNodeSelector: resolved.K8sWorkerNodeSelector, WorkerTolerationKey: resolved.K8sWorkerTolerationKey, WorkerTolerationValue: resolved.K8sWorkerTolerationValue, From 218f9b1ab22039028ba520bc35477a903b4f9948 Mon Sep 17 00:00:00 2001 From: Daniel <115043334+danielxnj@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:18:54 -0500 Subject: [PATCH 2/2] fix(k8s): keep the size threshold in the kubernetes build The constant is unused without the kubernetes build tag. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01GepAgyXv5zVvQV5cbnRF8F --- controlplane/k8s_pool_spawn.go | 4 ++++ controlplane/worker_pool.go | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controlplane/k8s_pool_spawn.go b/controlplane/k8s_pool_spawn.go index ae157092d..1b1bd33ae 100644 --- a/controlplane/k8s_pool_spawn.go +++ b/controlplane/k8s_pool_spawn.go @@ -713,6 +713,10 @@ func (p *K8sWorkerPool) workerResourcesForProfile(profile WorkerProfile) corev1. return corev1.ResourceRequirements{Requests: requests, Limits: limits} } +// workerMemoryRequestPercentMinBytes is the smallest worker memory limit that +// WorkerMemoryRequestPercent applies to. +const workerMemoryRequestPercentMinBytes = 64 << 30 + // workerMemoryRequestForLimit returns the memory request of a worker pod with // the given memory limit: workerMemoryRequestPercent of the limit for a large // worker, and the limit itself for every other worker. diff --git a/controlplane/worker_pool.go b/controlplane/worker_pool.go index e63c76599..ede4834d7 100644 --- a/controlplane/worker_pool.go +++ b/controlplane/worker_pool.go @@ -15,10 +15,6 @@ const DefaultK8sWorkerServiceAccount = "duckgres-worker" // a pod that DuckDB's memory_limit can take, so the request always covers it. const MinWorkerMemoryRequestPercent = 75 -// workerMemoryRequestPercentMinBytes is the smallest worker memory limit that -// WorkerMemoryRequestPercent applies to. -const workerMemoryRequestPercentMinBytes = 64 << 30 - const DefaultWorkerSpawnRetryAfter = 45 * time.Second // WorkerCapacityExhaustedError is returned when a worker can't be acquired