diff --git a/.github/workflows/framework-golden-tests.yml b/.github/workflows/framework-golden-tests.yml index 1ae744165..fe851cffd 100644 --- a/.github/workflows/framework-golden-tests.yml +++ b/.github/workflows/framework-golden-tests.yml @@ -22,6 +22,10 @@ jobs: config: smoke.toml count: 1 timeout: 10m + - name: TestSmoke + config: smoke_limited_resources.toml + count: 1 + timeout: 10m - name: TestSuiSmoke config: smoke_sui.toml count: 1 diff --git a/book/src/framework/components/resources.md b/book/src/framework/components/resources.md index eceba4e06..faa5360da 100644 --- a/book/src/framework/components/resources.md +++ b/book/src/framework/components/resources.md @@ -1 +1,24 @@ # Components Resources + +You can use `resources` to limit containers CPU/Memory for `NodeSet`, `Blockchain` and `PostgreSQL` components. +```toml +[blockchain_a.resources] +cpus = 0.5 +memory_mb = 1048 + +[nodeset.db.resources] +cpus = 2 +memory_mb = 2048 + +[nodeset.node_specs.node.resources] +cpus = 1 +memory_mb = 1048 +``` + +Read more about resource constraints [here](https://docs.docker.com/engine/containers/resource_constraints/). + +We are using `cpu-period` and `cpu-quota` for simplicity, and because it's working with an arbitrary amount of containers, it is absolute. + +Memory swapping is off if you specify `resources` key. + +Full configuration [example]() \ No newline at end of file diff --git a/framework/docker.go b/framework/docker.go index 7ad57885c..637dc4b38 100644 --- a/framework/docker.go +++ b/framework/docker.go @@ -331,14 +331,17 @@ func ResourceLimitsFunc(h *container.HostConfig, resources *ContainerResources) if resources == nil { return } - h.Memory = int64(resources.MemoryMb) * 1024 * 1024 // Memory in Mb - h.MemoryReservation = int64(resources.MemoryMb) * 1024 * 1024 // Total memory that can be reserved (soft) in Mb - // https://docs.docker.com/engine/containers/resource_constraints/ if memories are equal we don't have swap, read the docs - h.MemorySwap = h.Memory // No swap for simplicity - - // Set CPU limits using CPUQuota and CPUPeriod - // we don't use runtime.NumCPU or docker API to get CPUs because h.CPUShares is relative to amount of containers you run - // CPUPeriod and CPUQuota are absolute and easier to control - h.CPUPeriod = 100000 // Default period (100ms) - h.CPUQuota = int64(resources.CPUs * 100000) // Quota in microseconds (e.g., 0.5 CPUs = 50000) + if resources.MemoryMb != 0 { + h.Memory = int64(resources.MemoryMb) * 1024 * 1024 // Memory in Mb + h.MemoryReservation = int64(resources.MemoryMb) * 1024 * 1024 // Total memory that can be reserved (soft) in Mb + // https://docs.docker.com/engine/containers/resource_constraints/ if both values are equal swap is off, read the docs + h.MemorySwap = h.Memory + } + if resources.CPUs != 0 { + // Set CPU limits using CPUQuota and CPUPeriod + // we don't use runtime.NumCPU or docker API to get CPUs because h.CPUShares is relative to amount of containers you run + // CPUPeriod and CPUQuota are absolute and easier to control + h.CPUPeriod = 100000 // Default period (100ms) + h.CPUQuota = int64(resources.CPUs * 100000) // Quota in microseconds (e.g., 0.5 CPUs = 50000) + } }