You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f0df3cc
Browse filesBrowse the repository at this point in the historyBrowse files
improvement(sandbox): warm capacity, startup timings, and clearer capacity errors for Kubernetes sandboxes (#10724)
* improvement(sandbox): warm capacity, startup timings, and clearer capacity errors for Kubernetes sandboxes
* fix(sandbox): count startup timings from the first create request
* fix(sandbox): time the running step from the sandbox container's own state
Copy file name to clipboardExpand all lines: apps/docs/content/docs/platform/self-hosting/sandboxes.mdx
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -357,7 +357,7 @@ A kind with no image fails closed with a configuration error. The Chat code-tool
357
357
358
358
Each sandbox gets the limits in `sandbox.kubernetes.resources` (1 CPU, 2 GiB memory, and 4 GiB ephemeral storage by default), and requests at half of each. The same values become the sandbox namespace's LimitRange maximum, so no container there can ask for more.
359
359
360
-
The ResourceQuota caps concurrent sandboxes at `quota.pods` (20 by default) and their total limits at `quota.cpu`, `quota.memory`, and `quota.ephemeralStorage`. A sandboxstarted past the quota fails with a provider-limit error instead of waiting. Size the quota and the sandbox nodes together: nodes that cannot fit the quota leave sandboxes pending until their start times out.
360
+
The ResourceQuota caps concurrent sandboxes at `quota.pods` (20 by default) and their total limits at `quota.cpu`, `quota.memory`, and `quota.ephemeralStorage`. It counts each sandbox's limits, not its requests, so the defaults admit exactly 20 sandboxes on every dimension (20 × 1 CPU, 2 GiB, and 4 GiB). Raising `sandbox.kubernetes.resources` without raising the matching quota lowers that count: with `resources.cpu: "2"`, the CPU quota stops at 10 sandboxes. Set each quota to `quota.pods` times the matching resource. A RuntimeClass `overhead` (VM runtimes have one) counts against the quota too, so add it to each sandbox's share. Session sandboxes (chat workbenches and Pi) hold their share until they expire. A sandbox started past the quota fails at once with a "Sandbox limit reached" error instead of waiting. Size the quota and the sandbox nodes together: nodes that cannot fit the quota leave sandboxes pending until their start times out.
361
361
362
362
Sim records no sandbox cost for this provider: you pay for the nodes. Set the kubelet's `podPidsLimit` on sandbox nodes (for example `4096`): the memory limit does not bound processes, so a fork bomb in user code otherwise exhausts the node's PIDs for every pod on it ([Kubernetes: Process ID limits](https://kubernetes.io/docs/concepts/policy/pid-limiting/)). Per-platform density:
363
363
@@ -371,6 +371,18 @@ A sandbox's start time is dominated by the first image pull on its node. `sandbo
371
371
372
372
On VM runtimes the image is loaded into each pod's VM at start (an EKS Nitro Sandbox runs its own containerd inside the guest), so measure how much pre-pulling helps on your platform before relying on it.
373
373
374
+
Each sandbox that starts logs one `Kubernetes sandbox pod ready` line with, in milliseconds from the create request, when each step was reached: the request accepted (`acceptedMs`), the pod scheduled to a node (`scheduledMs`), its agent copied in (`initializedMs`), the container running (`runningMs`), and the agent answering (`agentMs`). A sandbox that does not start logs `Kubernetes sandbox pod did not start` with the steps it reached. Use them to see where your start time goes before tuning anything.
375
+
376
+
### Warm capacity
377
+
378
+
When no sandbox node has room, a sandbox waits for your node autoscaler to add one, about 2 minutes on EKS Auto Mode, and may run into its 3-minute start deadline. `sandbox.kubernetes.warmCapacity.sandboxes: N` keeps room for N sandboxes free. The chart runs N placeholder pods in the release namespace at priority -10. Each one has a sandbox pod's requests and limits, and runs under the sandbox RuntimeClass (so its overhead is reserved too) with the same node selector and tolerations. When a sandbox needs the room, the scheduler evicts a placeholder and the sandbox starts on a running node. The evicted placeholder goes pending, and your autoscaler adds the next node in the background. This is the standard [cluster-autoscaler overprovisioning](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#how-can-i-configure-overprovisioning-with-cluster-autoscaler) pattern, and it works with cluster-autoscaler, Karpenter, EKS Auto Mode, and GKE.
379
+
380
+
- You pay for N idle sandbox slots. Under a VM runtime each placeholder is an idle VM, and on GKE Autopilot the placeholders are billed.
381
+
- The placeholders run outside the sandbox namespace, so they never count against `quota`. The chart refuses more room than `quota.pods`, which could never be used.
382
+
- Sandbox pods set no priority class, so they run at 0 and preempt the placeholders. A cluster whose default PriorityClass (`globalDefault: true`) is -10 or lower defeats this.
383
+
- Any pod at default priority can take the room. Give sandboxes dedicated nodes (`nodeSelector` and `tolerations`) so the room stays theirs.
384
+
- A placeholder holds room, not the image. The first sandbox on a newly added node still pulls the Function image unless `prePull` is on, and on VM runtimes the image also loads into each pod's VM at start, so measure the gain on your platform.
385
+
374
386
### Amazon EKS Auto Mode
375
387
376
388
What Sim's sandboxes need on EKS Auto Mode with Nitro Sandboxes (`runtimeClass.preset: isolated-sandbox`), beyond the chart:
`The Kubernetes sandbox namespace "${namespace}" has reached its ResourceQuota, so no new sandbox can start until running ones finish. Raise the quota or lower concurrent sandbox use. Cluster detail: ${failure.message}`
107
+
`Sandbox limit reached: the Kubernetes sandbox namespace "${namespace}" has used its ResourceQuota, so no new sandbox can start until running ones finish. Raise sandbox.kubernetes.quota (pods, cpu, memory, ephemeralStorage) in the Helm values, or the namespace's ResourceQuota directly, or run fewer sandboxes at once. See ${KUBERNETES_SANDBOX_CAPACITY_DOCS_URL}. Cluster detail: ${failure.message}`
{{- fail "sandbox.kubernetes.prePull.enabled=true needs sandbox.kubernetes.images.function.tag or .digest, so the DaemonSet holds the exact image the app runs" -}}
{{- fail (printf"sandbox.kubernetes.warmCapacity.sandboxes (%d) is above quota.pods (%d): room for more sandboxes than the quota admits is never used" (int $sbx.warmCapacity.sandboxes) (int $sbx.quota.pods)) -}}
998
+
{{- end -}}
996
999
{{- end -}}
997
1000
{{- end }}
998
1001
@@ -1067,3 +1070,22 @@ Kubernetes sandbox provider: env entries for the app container.
1067
1070
value: {{ .| quote }}
1068
1071
{{- end }}
1069
1072
{{- end }}
1073
+
1074
+
{{/*
1075
+
Kubernetes sandbox provider: what one sandbox pod requests of a resource, as the
1076
+
scheduler counts it: half the limit (halfQuantity in kubernetes/settings.ts), or
1077
+
the agent init container's request when that is larger (pod.ts), since a pod
1078
+
requests the larger of its init containers and the sum of its containers.
0 commit comments