Skip to content

Add real CpuCap implementations for VMs (CPU quota / millicores, percentage cap) #601

Open

Description

@manoelcampos

Follow-up of #597 and PR #595.

Context

PR #595 added the sealed CpuCap interface. It limits the MIPS a machine can request from the machine where it runs. Right now CpuCapNone is its only implementation, and every VM uses it by default (CpuCap.NONE). The extension point works, but no implementation actually limits the CPU yet.

Proposal

Add real CpuCap implementations for VMs, which can be used now:

Implementation Models Example
A cap given in CPUs (or millicores) KVM/libvirt quota/period, Xen cap, VMware CPU limit 1.5 CPUs (or 1500m) for a 2-core VM
A cap given as a percentage of each core burstable VM baseline (AWS T3/T4g, Azure B) 20% of each vCPU

These are only examples: one implementation may cover both.

Container CPU quotas (Docker --cpus, Kubernetes limits.cpu) use the same contract. So they'll only need these classes once containers are supported (#592 step 7). This issue doesn't depend on container support.

Design notes

  • Implementations must be immutable, so one instance can be shared by many VMs. Records work well for that.
  • A cap given in CPUs limits the total CPU time, not each core. The simplest model spreads it evenly over the working cores:
    • limitCoreMips = mips × min(1, cpus / workingCores);
    • divide by the working cores, not all cores, so a VM with failed cores still gets its whole quota (see the M2 review finding).
  • Burstable instances with CPU credits (bursting above the baseline for a while) need state over time. They don't fit an immutable cap, so they'd be a separate design. They're out of scope here.
  • Each new class must be added to CpuCap's permits clause. CpuCapTest already checks the contract 0 <= limited MIPS <= core MIPS for every permitted class, and fails if one isn't tested.

Tasks

  • Implement the cap(s), with Javadoc linking the real mechanisms they model.
  • Add them to CpuCapTest.allCaps(), plus specific tests: values at and above the number of cores, failed cores, 0.
  • Add an example to cloudsimplus-examples comparing capped and uncapped VMs.
  • Measure the cost per VM (JOL) and check that results with CpuCap.NONE don't change.

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions