Skip to content

Commit b378a1b

Browse files
committed
add CI + docs
1 parent 2b2b2c6 commit b378a1b

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

.github/workflows/framework-golden-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jobs:
2222
config: smoke.toml
2323
count: 1
2424
timeout: 10m
25+
- name: TestSmoke
26+
config: smoke_limited_resources.toml
27+
count: 1
28+
timeout: 10m
2529
- name: TestSuiSmoke
2630
config: smoke_sui.toml
2731
count: 1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
# Components Resources
2+
3+
You can use `resources` to limit containers CPU/Memory for `NodeSet`, `Blockchain` and `PostgreSQL` components.
4+
```toml
5+
[blockchain_a.resources]
6+
cpus = 0.5
7+
memory_mb = 1048
8+
9+
[nodeset.db.resources]
10+
cpus = 2
11+
memory_mb = 2048
12+
13+
[nodeset.node_specs.node.resources]
14+
cpus = 1
15+
memory_mb = 1048
16+
```
17+
18+
Read more about resource constraints [here](https://docs.docker.com/engine/containers/resource_constraints/).
19+
20+
We are using `cpu-period` and `cpu-quota` for simplicity, and because it's working with an arbitrary amount of containers, it is absolute.
21+
22+
Memory swapping is off if you specify `resources` key.
23+
24+
Full configuration [example]()

framework/docker.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,17 @@ func ResourceLimitsFunc(h *container.HostConfig, resources *ContainerResources)
331331
if resources == nil {
332332
return
333333
}
334-
h.Memory = int64(resources.MemoryMb) * 1024 * 1024 // Memory in Mb
335-
h.MemoryReservation = int64(resources.MemoryMb) * 1024 * 1024 // Total memory that can be reserved (soft) in Mb
336-
// https://docs.docker.com/engine/containers/resource_constraints/ if memories are equal we don't have swap, read the docs
337-
h.MemorySwap = h.Memory // No swap for simplicity
338-
339-
// Set CPU limits using CPUQuota and CPUPeriod
340-
// we don't use runtime.NumCPU or docker API to get CPUs because h.CPUShares is relative to amount of containers you run
341-
// CPUPeriod and CPUQuota are absolute and easier to control
342-
h.CPUPeriod = 100000 // Default period (100ms)
343-
h.CPUQuota = int64(resources.CPUs * 100000) // Quota in microseconds (e.g., 0.5 CPUs = 50000)
334+
if resources.MemoryMb != 0 {
335+
h.Memory = int64(resources.MemoryMb) * 1024 * 1024 // Memory in Mb
336+
h.MemoryReservation = int64(resources.MemoryMb) * 1024 * 1024 // Total memory that can be reserved (soft) in Mb
337+
// https://docs.docker.com/engine/containers/resource_constraints/ if both values are equal swap is off, read the docs
338+
h.MemorySwap = h.Memory
339+
}
340+
if resources.CPUs != 0 {
341+
// Set CPU limits using CPUQuota and CPUPeriod
342+
// we don't use runtime.NumCPU or docker API to get CPUs because h.CPUShares is relative to amount of containers you run
343+
// CPUPeriod and CPUQuota are absolute and easier to control
344+
h.CPUPeriod = 100000 // Default period (100ms)
345+
h.CPUQuota = int64(resources.CPUs * 100000) // Quota in microseconds (e.g., 0.5 CPUs = 50000)
346+
}
344347
}

0 commit comments

Comments
 (0)