Skip to content

Commit e711af8

Browse files
authored
Merge branch 'main' into tt-1936-seth-simulated-backend
2 parents e6d9102 + 8e7f8a1 commit e711af8

File tree

18 files changed

+135
-28
lines changed

18 files changed

+135
-28
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

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [Debugging Tests](framework/components/debug.md)
2323
- [Components Cleanup](framework/components/cleanup.md)
2424
- [Components Caching](framework/components/caching.md)
25+
- [Components Resources](framework/components/resources.md)
2526
- [Mocking Services](framework/components/mocking.md)
2627
- [Copying Files](framework/copying_files.md)
2728
- [External Environment](framework/components/external.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Components Resources
2+
3+
You can use `resources` to limit containers CPU/Memory for `NodeSet`, `Blockchain` and `PostgreSQL` components.
4+
5+
```toml
6+
[blockchain_a.resources]
7+
cpus = 0.5
8+
memory_mb = 1048
9+
10+
[nodeset.db.resources]
11+
cpus = 2
12+
memory_mb = 2048
13+
14+
[nodeset.node_specs.node.resources]
15+
cpus = 1
16+
memory_mb = 1048
17+
```
18+
19+
Read more about resource constraints [here](https://docs.docker.com/engine/containers/resource_constraints/).
20+
21+
We are using `cpu-period` and `cpu-quota` for simplicity, and because it's working with an arbitrary amount of containers, it is absolute.
22+
23+
How quota and period works:
24+
25+
- To allocate `1 CPU`, we set `CPUQuota = 100000` and `CPUPeriod = 100000` (1 full period).
26+
- To allocate `0.5 CPU`, we set `CPUQuota = 50000` and `CPUPeriod = 100000`.
27+
- To allocate `2 CPUs`, we set `CPUQuota = 200000` and `CPUPeriod = 100000`.
28+
29+
Read more about [CFS](https://engineering.squarespace.com/blog/2017/understanding-linux-container-scheduling).
30+
31+
When the `resources.memory_mb` key is not empty, we disable swap, ensuring the container goes OOM when memory is exhausted, allowing for more precise detection of sudden memory spikes.
32+
33+
Full configuration [example](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/smoke_limited_resources.toml)

framework/.changeset/v0.4.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Set cgroups resource for containers

framework/components/blockchain/anvil.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func newAnvil(in *Input) (*Output, error) {
4848
ExposedPorts: []string{bindPort},
4949
HostConfigModifier: func(h *container.HostConfig) {
5050
h.PortBindings = framework.MapTheSamePort(bindPort)
51+
framework.ResourceLimitsFunc(h, in.ContainerResources)
5152
},
5253
Networks: []string{framework.DefaultNetworkName},
5354
NetworkAliases: map[string][]string{

framework/components/blockchain/aptos.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func newAptos(in *Input) (*Output, error) {
4949
},
5050
HostConfigModifier: func(h *container.HostConfig) {
5151
h.PortBindings = framework.MapTheSamePort(bindPort)
52+
framework.ResourceLimitsFunc(h, in.ContainerResources)
5253
},
5354
ImagePlatform: "linux/amd64",
5455
Cmd: []string{

framework/components/blockchain/besu.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func newBesu(in *Input) (*Output, error) {
6868
Labels: framework.DefaultTCLabels(),
6969
HostConfigModifier: func(h *container.HostConfig) {
7070
h.PortBindings = framework.MapTheSamePort(bindPortWs, bindPort)
71+
framework.ResourceLimitsFunc(h, in.ContainerResources)
7172
},
7273
WaitingFor: wait.ForListeningPort(nat.Port(in.Port)).WithStartupTimeout(15 * time.Second).WithPollInterval(200 * time.Millisecond),
7374
Cmd: entryPoint,

framework/components/blockchain/blockchain.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package blockchain
22

33
import (
44
"fmt"
5+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
56
"github.com/testcontainers/testcontainers-go"
67
)
78

@@ -25,7 +26,8 @@ type Input struct {
2526
// programs to deploy on solana-test-validator start
2627
// a map of program name to program id
2728
// there needs to be a matching .so file in contracts_dir
28-
SolanaPrograms map[string]string `toml:"solana_programs"`
29+
SolanaPrograms map[string]string `toml:"solana_programs"`
30+
ContainerResources *framework.ContainerResources `toml:"resources"`
2931
}
3032

3133
// Output is a blockchain network output, ChainID and one or more nodes that forms the network

framework/components/blockchain/geth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func newGeth(in *Input) (*Output, error) {
167167
ExposedPorts: []string{bindPort},
168168
HostConfigModifier: func(h *container.HostConfig) {
169169
h.PortBindings = framework.MapTheSamePort(bindPort)
170+
framework.ResourceLimitsFunc(h, in.ContainerResources)
170171
h.Mounts = append(h.Mounts, mount.Mount{
171172
Type: mount.TypeBind,
172173
Source: keystoreDir,

framework/components/blockchain/solana.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func newSolana(in *Input) (*Output, error) {
105105
WithPollInterval(100 * time.Millisecond),
106106
HostConfigModifier: func(h *container.HostConfig) {
107107
h.PortBindings = framework.MapTheSamePort(bindPort, wsBindPort)
108+
framework.ResourceLimitsFunc(h, in.ContainerResources)
108109
h.Mounts = append(h.Mounts, mount.Mount{
109110
Type: mount.TypeBind,
110111
Source: contractsDir,

0 commit comments

Comments
 (0)