Skip to content

Commit d4eae05

Browse files
authored
Merge pull request #127 from akto-api-security/feature/mem_check
Feature/mem check
2 parents cdce6c0 + e63a15c commit d4eae05

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ebpf-run.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ MAX_LOG_SIZE=${MAX_LOG_SIZE:-10485760} # Default to 10 MB if not set (10 MB = 1
55
CHECK_INTERVAL=${CHECK_INTERVAL:-60}
66
CHECK_INTERVAL_MEM=${CHECK_INTERVAL_MEM:-10} # Check interval in seconds (configurable via env)
77
MEMORY_THRESHOLD=${MEMORY_THRESHOLD:-80} # Kill process at this % memory usage (configurable via env)
8+
GOMEMLIMIT_PERCENT=${GOMEMLIMIT_PERCENT:-60} # GOMEMLIMIT as % of container memory limit (configurable via env)
89

910
# Function to rotate the log file
1011
rotate_log() {
@@ -83,11 +84,12 @@ fi
8384

8485
echo "Using container memory limit: ${MEM_LIMIT_MB} MB"
8586

87+
# Set GOMEMLIMIT for the Go process
88+
GOMEMLIMIT_MB=$((MEM_LIMIT_MB * GOMEMLIMIT_PERCENT / 100))
89+
export GOMEMLIMIT="${GOMEMLIMIT_MB}MiB"
90+
echo "Setting GOMEMLIMIT to: ${GOMEMLIMIT} (${GOMEMLIMIT_PERCENT}% of ${MEM_LIMIT_MB} MB)"
91+
8692
# Start memory monitoring in the background
87-
while true; do
88-
check_memory_and_kill
89-
sleep "$CHECK_INTERVAL_MEM"
90-
done &
9193

9294
while :
9395
do

0 commit comments

Comments
 (0)