Conversation
…t in sandbox initialization
|
PR created by request on #364 |
|
i'll like to better understand your use case before reviewing this. i don't feel strongly that this is a need (at least now), and further diverges the different platforms from each other. also, the switch from u8 to f32 further keeps me hesitant (i'd rather lean towards separate flags for allocating |
|
Sure, I'll explain in a moment. I'm currently testing Python agents that need separate test environments, as that's how they'll operate in production: one environment per tenant. However, there's a major limitation right now due to resource allocation, considering them as full units. For example, on an 8-core machine, only 4-6 sandboxes can be started, and the last ones to start will begin to fail at startup because the machine itself blocks the resource. This problem also occurs in Kubernetes, which uses KVM, but it's solved by using fractional resource allocation, allowing initial usage that adjusts after a while, or allowing bursts rather than constantly having the resource occupied. You can try replicating this behavior by running a And from the API, make several startup requests. If they are concurrent, the failure will almost certainly occur. On Mac it happens on the 2nd or 3rd test, on Linux I noticed it on the 6th (considering it has a processor with more cores) |
This pull request updates the handling of CPU allocation across the microsandbox codebase to support fractional CPU values (e.g., 0.5, 0.25), enabling more granular resource throttling.
The changes span the CLI, configuration, runtime, and VM builder layers, and introduce cgroup-based CPU throttling for fractional CPUs on Linux systems.
Tests are also added to ensure correct parsing and behavior for both integer and fractional CPU values.
Fractional CPU support in configuration and CLI:
cpusandnum_vcpusfields and arguments from integer types (u8,u32) tof32in CLI argument definitions (msb.rs,msbrun.rs), core config structs, and builder APIs. Documentation updated to clarify support for fractional values and valid range (0.1 to 128.0). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]Runtime support for CPU throttling:
MicroVmMonitorto apply CPU throttling using Linux cgroups v2 when a fractional CPU value (<1.0) is requested, including cgroup name sanitization, creation, and cleanup. Warnings are logged if cgroups v2 is unavailable or on non-Linux systems. [1] [2] [3] [4] [5] [6] [7]Testing and validation:
None. [1] [2] [3] [4]These changes enable more flexible resource allocation for sandboxes and microVMs, and lay the groundwork for improved multi-tenancy and resource efficiency.