Sobes.tech
Middle

What happens to a container if the CPU limit is exceeded?

sobes.tech AI

Answer from AI

A container scheduler (e.g., Docker, Kubernetes) will limit its CPU resources. This manifests as:

  • The container will not be able to use more of its allocated processor time, even if there are available cores.
  • Processes inside the container will slow down, as they will be allocated fewer processor cycles.
  • The execution time of tasks inside the container will increase.
  • Logs from the container or scheduler may show messages about CPU throttling.
  • If CPU load constantly exceeds the limit, the performance of the application inside the container will significantly decrease, which can lead to timeouts, errors, and even application crashes.

Example of a CPU limit configuration in Kubernetes:

# resource-limits.yaml
apiVersion: v1
kind: Pod
metadata:
  name: limited-cpu-pod
spec:
  containers:
  - name: my-container
    image: my-image
    resources:
      limits:
        cpu: "500m"   # Limit to 0.5 CPU core

Example of a metric showing CPU throttling in Kubernetes (using cAdvisor/Prometheus):

# Metric showing the number of nanoseconds the process was throttled
container_cpu_cfs_throttled_periods_total

In Docker, limits are set at startup:

# Limit to 0.5 CPU core
docker run -it --cpus=".5" my-image