Skip to content

Instantly share code, notes, and snippets.

@mondain
Created August 27, 2019 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mondain/88ee4bb4c069484cca7e87cce02e5458 to your computer and use it in GitHub Desktop.
Save mondain/88ee4bb4c069484cca7e87cce02e5458 to your computer and use it in GitHub Desktop.
Java GC with Red5

I did some reading and it looks like this particular OOM message simply means to add more memory for the heap; it essentially means one is running too lean. CPU runs hot trying to clear the garbage.

OutOfMemoryError: GC overhead limit exceeded

Excessive GC Time and OutOfMemoryError
The parallel collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

You can turn off the "warning" with the option -XX:-UseGCOverheadLimit

Solutions for only this "issue":

  1. Increase the heap size via -Xmx
  2. Enable the concurrent low-pause collector -XX:+UseConcMarkSweepGC

References: https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/memleaks.html#gbywc https://javarevisited.blogspot.com/2017/05/solution-of-javalangoutofmemoryerror-gc-overhead-limit-exceeded.html

Windows batch file modification for data collection, adding JVM options: -XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit

@echo off

SETLOCAL

if NOT DEFINED RED5_HOME set RED5_HOME=%~dp0

if NOT DEFINED JAVA_HOME goto err

REM JAVA options
REM You can set JVM additional options here if you want
if NOT DEFINED JVM_OPTS set JVM_OPTS=-Xms8g -Xmx8g -Xverify:none -Djava.net.preferIPv4Stack=true -XX:+TieredCompilation -XX:+UseBiasedLocking -XX:InitialCodeCacheSize=8m -XX:ReservedCodeCacheSize=32m -Dorg.terracotta.quartz.skipUpdateCheck=true -XX:MaxMetaspaceSize=128m -XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit
REM Set up logging options
set LOGGING_OPTS=-Dlogback.ContextSelector=org.red5.logging.LoggingContextSelector -Dcatalina.useNaming=true
REM Set up security options
REM set SECURITY_OPTS=-Djava.security.debug=failure -Djava.security.manager -Djava.security.policy="%RED5_HOME%/conf/red5.policy"
set SECURITY_OPTS=-Djava.security.debug=failure
REM Set up tomcat options
set TOMCAT_OPTS=-Dcatalina.home=%RED5_HOME%
REM Native path
REM set NATIVE=-Djava.library.path="%RED5_HOME%\lib\native"
REM Setup python/jython path
set JYTHON_OPTS=-Dpython.home=lib
REM Combined java options
REM set JAVA_OPTS=%LOGGING_OPTS% %SECURITY_OPTS% %JAVA_OPTS% %JVM_OPTS% %TOMCAT_OPTS% %NATIVE% %JYTHON_OPTS%
set JAVA_OPTS=%LOGGING_OPTS% %SECURITY_OPTS% %JAVA_OPTS% %JVM_OPTS% %TOMCAT_OPTS% %JYTHON_OPTS%

set RED5_CLASSPATH=%RED5_HOME%\red5-service.jar;%RED5_HOME%\conf;%CLASSPATH%

if NOT DEFINED RED5_MAINCLASS set RED5_MAINCLASS=org.red5.server.Bootstrap

if NOT DEFINED RED5_OPTS set RED5_OPTS=9999

goto launchRed5

:launchRed5
echo Starting Red5
"%JAVA_HOME%\bin\java" %JAVA_OPTS% -cp "%RED5_CLASSPATH%" %RED5_MAINCLASS% %RED5_OPTS%
goto finally

:err
echo JAVA_HOME environment variable not set! Take a look at the readme.
pause

:finally
ENDLOCAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment