Skip to content

Commit

Permalink
add CI + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Jan 21, 2025
1 parent 2b2b2c6 commit b378a1b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/framework-golden-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions book/src/framework/components/resources.md
Original file line number Diff line number Diff line change
@@ -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]()
23 changes: 13 additions & 10 deletions framework/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit b378a1b

Please sign in to comment.