-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limits the ressources available for the container (#203)
* feat: add a script which allow to set the limits of the container according to the ressources' host * 50 -> 70 * fix: use docker-compose.override.yml * clean up
- Loading branch information
1 parent
347acca
commit cb54382
Showing
6 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,6 @@ pyroengine/version.py | |
*.onnx | ||
# Release | ||
conda-dist/ | ||
|
||
docker-compose.yml.bak | ||
docker-compose.override.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# Define the percentage of host memory you want to allocate | ||
PERCENTAGE=70 | ||
|
||
# Get the total memory of the host system in kilobytes | ||
TOTAL_MEM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}') | ||
|
||
# Calculate the memory limit in kilobytes | ||
LIMIT_MEM_KB=$((TOTAL_MEM_KB * PERCENTAGE / 100)) | ||
|
||
# Convert the limit to a format Docker understands (e.g., "m" for megabytes) | ||
LIMIT_MEM_MB=$((LIMIT_MEM_KB / 1024))m | ||
|
||
# Define the Docker Compose file to modify | ||
DOCKER_COMPOSE_FILE="docker-compose.yml" | ||
|
||
# Backup the original Docker Compose file | ||
cp $DOCKER_COMPOSE_FILE "${DOCKER_COMPOSE_FILE}.bak" | ||
|
||
# Use awk to update the memory limits in the Docker Compose file, preserving indentation | ||
awk -v mem_limit="$LIMIT_MEM_MB" ' | ||
/services:/ { in_services=1 } | ||
in_services && /deploy:/ { in_deploy=1 } | ||
in_deploy && /resources:/ { in_resources=1 } | ||
in_resources && /limits:/ { in_limits=1 } | ||
in_limits && /memory:/ { | ||
$0 = gensub(/memory:.*/, "memory: " mem_limit, 1) | ||
} | ||
{ print } | ||
' "${DOCKER_COMPOSE_FILE}.bak" > "docker-compose.override.yml" | ||
|
||
echo "Memory limits set to $LIMIT_MEM_MB in $DOCKER_COMPOSE_FILE" |