Skip to content

Commit

Permalink
[INLONG-10889][Agent] When the oom is detected, the process exits
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwwhuang committed Aug 27, 2024
1 parent e9ebde1 commit 0cd1955
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class AgentConstants {
public static final String DEFAULT_AGENT_HISTORY_PATH = ".history";

public static final String AGENT_ENABLE_OOM_EXIT = "agent.enable.oom.exit";
public static final boolean DEFAULT_ENABLE_OOM_EXIT = true;
public static final boolean DEFAULT_ENABLE_OOM_EXIT = false;

// pulsar sink config
public static final String PULSAR_CLIENT_IO_TREHAD_NUM = "agent.sink.pulsar.client.io.thread.num";
Expand Down
13 changes: 8 additions & 5 deletions inlong-agent/bin/agent-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export OTEL_LOGS_EXPORTER=otlp
export ENABLE_OBSERVABILITY=false
# OTEL_EXPORTER_OTLP_ENDPOINT must be configured as a URL when ENABLE_OBSERVABILITY=true.
export OTEL_EXPORTER_OTLP_ENDPOINT=
export TDW_SECURITY_URL_NULL

#project directory
BASE_DIR=$(cd "$(dirname "$0")"/../;pwd)
Expand All @@ -45,17 +46,19 @@ else
fi

if [ -z "$AGENT_JVM_HEAP_OPTS" ]; then
HEAP_OPTS="-Xmx512m -Xss512k"
HEAP_OPTS=" -Xmx2048m -Xms512m -Xss512k "
else
HEAP_OPTS="$AGENT_JVM_HEAP_OPTS"
fi
GC_OPTS="-XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=60 -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -XX:+ExitOnOutOfMemoryError"
LOG_OPTS="-Xloggc:$BASE_DIR/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=20M"

GVM_OPTS=" -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 "
OOM_HANDLER=" -XX:OnOutOfMemoryError=$BASE_DIR/bin/oom.sh"
GC_OPTS=" -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+TraceClassLoading -XX:InitiatingHeapOccupancyPercent=45 -XX:G1HeapRegionSize=16m -XX:G1MixedGCCountTarget=16 -XX:G1HeapWastePercent=10"
LOG_OPTS=" -Xloggc:$BASE_DIR/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=20M"
if [ -n "$NEED_TRACK_NATIVE_MEMORY" ] && [ "$NEED_TRACK_NATIVE_MEMORY" = "true" ]; then
GC_OPTS="$GC_OPTS -XX:NativeMemoryTracking"
fi
AGENT_JVM_ARGS="$HEAP_OPTS $GC_OPTS $LOG_OPTS"

AGENT_JVM_ARGS="$HEAP_OPTS $GVM_OPTS $GC_OPTS $LOG_OPTS $OOM_HANDLER"
# Add Agent Rmi Args when necessary
AGENT_RMI_ARGS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=18080 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
Expand Down
45 changes: 45 additions & 0 deletions inlong-agent/bin/oom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

BASE_DIR=$(dirname $0)/..

AGENT_CONF="${BASE_DIR}"/conf/agent.properties
source "${BASE_DIR}"/bin/agent-env.sh
CONSOLE_OUTPUT_FILE="${LOG_DIR}/oom.log"

function running() {
agent_uniq=`cat ${AGENT_CONF}|grep -Ev '^[[:space:]].*|^#' |grep -E 'agent.uniq.id'`
check_agent_uniq="${agent_uniq:-"agent.uniq.id=1"}"
arg_uniq="-D${check_agent_uniq}"
process=$(ps -aux | grep 'java' | grep 'inlong-agent' | grep "$check_agent_uniq" | awk '{print $2}')
if [ "${process}" = "" ]; then
return 1;
else
return 0;
fi
}

time=$(date "+%Y%m%d-%H%M%S")
if ! running; then
echo "$time oom agent is not running." >> $CONSOLE_OUTPUT_FILE
exit 1
fi
pid=$(ps -aux | grep 'java' | grep 'inlong-agent' | grep "$check_agent_uniq" | awk '{print $2}')
kill -9 "${pid}"
echo "$time oom stop agent successfully." >> $CONSOLE_OUTPUT_FILE

0 comments on commit 0cd1955

Please sign in to comment.