Skip to content

Commit 155f2d3

Browse files
szachovyCopilot
andcommitted
Add container resource limits for all services
Set memory, CPU, and PID limits: MySQL Server (2G/2CPU/500), MySQL Mgmt (1G/1CPU/200), Redis (768M/0.5CPU/100), Superset (2G/2CPU). Prevents OOM kills and noisy-neighbor resource starvation between services. memswap_limit equals mem_limit to disable swap for all containers. Closes #73 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0ab8ce7 commit 155f2d3

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* Dependabot updates for `github-actions` and `terraform` ecosystems. (#29)
1616
* CI workflow to build and push service images to GitHub Container Registry on master merge. (#97)
1717
* Pull-first with local build fallback for container images during deployment. (#97)
18+
* Container resource limits (memory, CPU, PIDs) for all services. (#73)
1819

1920
### Changed
2021

services/mysql-mgmt/docker_compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ services:
100100
image: "ghcr.io/szachovy/superset-cluster-mysql-mgmt:latest"
101101
pull_policy: "missing"
102102
user: "superset"
103+
mem_limit: "1g"
104+
memswap_limit: "1g"
105+
cpus: 1.0
106+
pids_limit: 200
103107
entrypoint:
104108
- "/bin/bash"
105109
- "-c"

src/container.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ def run(self) -> None:
236236
network="host",
237237
cap_add=["SYS_NICE"],
238238
security_opt=[f"seccomp={seccomp_parsed}"],
239+
mem_limit="2g",
240+
memswap_limit="2g",
241+
nano_cpus=2000000000,
242+
pids_limit=500,
239243
environment={
240244
"MYSQL_INITDB_SKIP_TZINFO": "true",
241245
"MYSQL_ROOT_PASSWORD_FILE": "/var/run/mysqld/mysql_root_password",
@@ -399,6 +403,10 @@ def run(self) -> None:
399403
name="redis",
400404
hostname="redis",
401405
network="superset-network",
406+
mem_limit="768m",
407+
memswap_limit="768m",
408+
nano_cpus=500000000,
409+
pids_limit=100,
402410
healthcheck={
403411
'test': ["CMD", "redis-cli", "ping"],
404412
'interval': self.healthcheck_interval * 1000000000,
@@ -456,6 +464,10 @@ def run(self) -> None:
456464
],
457465
maxreplicas=1,
458466
env=[f"VIRTUAL_IP_ADDRESS={self.virtual_ip_address}"],
467+
resources=docker.types.Resources(
468+
mem_limit=2147483648,
469+
nano_cpus=2000000000
470+
),
459471
endpoint_spec=docker.types.EndpointSpec(
460472
mode="vip",
461473
ports={443: 443}

0 commit comments

Comments
 (0)