From 8d4d02a9316413ed43bf4ce3b4597f657ef36f8b Mon Sep 17 00:00:00 2001 From: notshivansh Date: Sat, 4 Oct 2025 03:43:19 +0530 Subject: [PATCH 1/3] add go mem limit. --- ebpf-run.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ebpf-run.sh b/ebpf-run.sh index f98e255..e72e4be 100644 --- a/ebpf-run.sh +++ b/ebpf-run.sh @@ -83,6 +83,10 @@ fi echo "Using container memory limit: ${MEM_LIMIT_MB} MB" +# Set GOMEMLIMIT for the Go process +export GOMEMLIMIT="${MEM_LIMIT_MB}MiB" +echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT}" + # Start memory monitoring in the background while true; do check_memory_and_kill From 9c7b15cff9d02b25de70f75112dec4b5c131f9c9 Mon Sep 17 00:00:00 2001 From: ayushaga14 Date: Sun, 5 Oct 2025 12:49:49 +0530 Subject: [PATCH 2/3] set go mem limit as 50% of mem threshold --- ebpf-run.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ebpf-run.sh b/ebpf-run.sh index e72e4be..750ab64 100644 --- a/ebpf-run.sh +++ b/ebpf-run.sh @@ -83,15 +83,12 @@ fi echo "Using container memory limit: ${MEM_LIMIT_MB} MB" -# Set GOMEMLIMIT for the Go process -export GOMEMLIMIT="${MEM_LIMIT_MB}MiB" -echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT}" +# Set GOMEMLIMIT for the Go process (60% of container limit) +GOMEMLIMIT_MB=$((MEM_LIMIT_MB * 50 / 100)) +export GOMEMLIMIT="${GOMEMLIMIT_MB}MiB" +echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT} (60% of ${MEM_LIMIT_MB} MB)" # Start memory monitoring in the background -while true; do - check_memory_and_kill - sleep "$CHECK_INTERVAL_MEM" -done & while : do From e63a15ccb4b488be38e42eb975611172ff002899 Mon Sep 17 00:00:00 2001 From: ayushaga14 Date: Sun, 5 Oct 2025 12:50:57 +0530 Subject: [PATCH 3/3] set go mem limit as 50% of mem threshold --- ebpf-run.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ebpf-run.sh b/ebpf-run.sh index 750ab64..2042dc4 100644 --- a/ebpf-run.sh +++ b/ebpf-run.sh @@ -5,6 +5,7 @@ MAX_LOG_SIZE=${MAX_LOG_SIZE:-10485760} # Default to 10 MB if not set (10 MB = 1 CHECK_INTERVAL=${CHECK_INTERVAL:-60} CHECK_INTERVAL_MEM=${CHECK_INTERVAL_MEM:-10} # Check interval in seconds (configurable via env) MEMORY_THRESHOLD=${MEMORY_THRESHOLD:-80} # Kill process at this % memory usage (configurable via env) +GOMEMLIMIT_PERCENT=${GOMEMLIMIT_PERCENT:-60} # GOMEMLIMIT as % of container memory limit (configurable via env) # Function to rotate the log file rotate_log() { @@ -83,10 +84,10 @@ fi echo "Using container memory limit: ${MEM_LIMIT_MB} MB" -# Set GOMEMLIMIT for the Go process (60% of container limit) -GOMEMLIMIT_MB=$((MEM_LIMIT_MB * 50 / 100)) +# Set GOMEMLIMIT for the Go process +GOMEMLIMIT_MB=$((MEM_LIMIT_MB * GOMEMLIMIT_PERCENT / 100)) export GOMEMLIMIT="${GOMEMLIMIT_MB}MiB" -echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT} (60% of ${MEM_LIMIT_MB} MB)" +echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT} (${GOMEMLIMIT_PERCENT}% of ${MEM_LIMIT_MB} MB)" # Start memory monitoring in the background