> ## Documentation Index
> Fetch the complete documentation index at: https://docs.controlplane.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Capacity AI

> Automatically optimize container CPU and memory allocation using historical usage analysis to reduce costs while maintaining performance.

## Overview

Workloads can leverage intelligent allocation of their container's resources (CPU and Memory) by using Capacity AI.

Capacity AI uses an analysis of historical usage to adjust the resources up/down between the configured minimum and maximum values of each container.

This can significantly reduce cost but may, in rare cases, cause temporary performance issues with sudden spikes in usage depending on the autoscaling settings of the workload.

If capacity AI is disabled, the amount of resources configured is set using the provided cpu and memory settings for each container.

## Resource Minimums

`minCpu` and `minMemory` are typically used only when Capacity AI is enabled. However, [stateful workloads](/reference/workload/types#stateful) always respect these fields.

## Limit Capacity AI update frequency

You can set the highest frequency that Capacity AI is allowed to update the resources of a workload by setting the `capacityAIUpdateMinutes` field in the workload options.
By defualt (when not set), Capacity AI can update the resources as frequently as necessary.

```yaml YAML theme={null}
kind: workload
spec:
  defaultOptions:
    capacityAIUpdateMinutes: 30 # Capacity AI can update resources at most once every 30 minutes
```

## In-place Resource Sizing

When Capacity AI adjusts the CPU or memory allocations for containers, the corresponding Kubernetes pods will have their resources resized **in place**, without requiring a pod restart or recreation.
This is currently not supported for serverless workloads.

<Note>
  Some programs may not take advantage of the updated resources automatically.
  E.g. if a program reserves resources on startup and does not scale dynamically.
</Note>

## Caveats

| Restriction                                    | Reason                                                  |
| :--------------------------------------------- | :------------------------------------------------------ |
| Not available with CPU Utilization autoscaling | Dynamic CPU allocation conflicts with CPU-based scaling |
| Not available with multi-metric autoscaling    | Multi-metric requires stable resource baselines         |
| Not supported for Stateful workloads           | Stateful workloads need predictable resource allocation |

See [Autoscaling](/reference/workload/autoscaling) for scaling strategy details and [Workload Types](/reference/workload/types) for type-specific capabilities.

<Info>
  Capacity AI will prevent the ratio of memory and cpu from diverging by a large percentage.
</Info>

<Note>Changes made to a workload will reset its historical usage and will restart the analysis process.</Note>

## Minimum Capacity AI

When resources are not being used, Capacity AI will downscale CPU usage to a minimum of 25 millicores. The minimum will increase depending on the memory size being recommended by Capacity AI using a 1:3 ratio of CPU millicores to memory MiB.
