Bug 698 - Confingured controller script to set max memory to 1 GB if not defined 80/5980/3
authordbavery <devin.avery@brocade.com>
Tue, 8 Apr 2014 18:45:14 +0000 (14:45 -0400)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 9 Apr 2014 11:24:05 +0000 (11:24 +0000)
Modified the run.sh and run.bat scripts to configure the java max memory to be
 1 GB if it is not defined on the command line.

NOTE: Java generally sets the memory to be 1/4th the total memory of your system
so it is possible that this will result in LESS memory being allocate (change of
behavior). Once this work item is committed we should encourage a best practice
of defining max memory.

A message will be printed out notifying the users that the max memory was not
specified.

Change-Id: I39225f28c4aed3636a1db0cdb41fbe802f5b5b54
Signed-off-by: dbavery <devin.avery@brocade.com>
opendaylight/distribution/opendaylight/src/main/resources/run.bat
opendaylight/distribution/opendaylight/src/main/resources/run.sh

index 9d6ac8d1deaecdee57ef842335389edb9931e1d3..72ccd02707ba7f5c76f064e5a16767a42f5fd37f 100644 (file)
@@ -10,6 +10,7 @@ SET basedir=%~dp0
 SET debugport=8000
 SET consoleport=2400
 SET jmxport=1088
 SET debugport=8000
 SET consoleport=2400
 SET jmxport=1088
+SET jvmMaxMemory=
 SET extraJVMOpts=
 SET consoleOpts=-console -consoleLog
 SET PID=
 SET extraJVMOpts=
 SET consoleOpts=-console -consoleLog
 SET PID=
@@ -82,6 +83,11 @@ IF "%~1" NEQ "" (
        )
        GOTO :EOF
     )
        )
        GOTO :EOF
     )
+    IF "!CARG:~0,4!"=="-Xmx" (
+       SET jvmMaxMemory=!CARG!
+       SHIFT
+       GOTO :LOOP
+    )
     IF "!CARG:~0,2!"=="-D" (
        SET extraJVMOpts=%extraJVMOpts% !CARG!
        SHIFT
     IF "!CARG:~0,2!"=="-D" (
        SET extraJVMOpts=%extraJVMOpts% !CARG!
        SHIFT
@@ -110,6 +116,19 @@ IF "%debugSuspended%" NEQ "" (
     REM ECHO "DEBUG enabled suspended"
     SET extraJVMOpts=%extraJVMOpts% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%debugport%
 )
     REM ECHO "DEBUG enabled suspended"
     SET extraJVMOpts=%extraJVMOpts% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%debugport%
 )
+
+IF "%jvmMaxMemory%"=="" (
+    SET jvmMaxMemory=-Xmx1G
+    ECHO *****************************************************************
+    ECHO JVM maximum memory was not defined. Setting maximum memory to 1G.
+    ECHO To define the maximum memory, specify the -Xmx setting on the
+    ECHO command line.
+    ECHO                    e.g. run.bat -Xmx1G
+    ECHO *****************************************************************"
+)
+
+SET extraJVMOpts=%extraJVMOpts%  %jvmMaxMemory%
+
 IF "%jmxEnabled%" NEQ "" (
     REM ECHO "JMX enabled "
     SET extraJVMOpts=%extraJVMOpts% -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=%jmxport% -Dcom.sun.management.jmxremote
 IF "%jmxEnabled%" NEQ "" (
     REM ECHO "JMX enabled "
     SET extraJVMOpts=%extraJVMOpts% -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=%jmxport% -Dcom.sun.management.jmxremote
index 64f2c877f7ea60f2e87f13bb9d4b173a11d7a16d..92ddbbd605346095bd4110118ab517e48e625756 100755 (executable)
@@ -82,6 +82,7 @@ stopdaemon=0
 statusdaemon=0
 consolestart=1
 dohelp=0
 statusdaemon=0
 consolestart=1
 dohelp=0
+jvmMaxMemory=""
 extraJVMOpts=""
 agentPath=""
 unknown_option=0
 extraJVMOpts=""
 agentPath=""
 unknown_option=0
@@ -97,6 +98,7 @@ while true ; do
         -status) statusdaemon=1; shift ;;
         -console) shift ;;
         -help) dohelp=1; shift;;
         -status) statusdaemon=1; shift ;;
         -console) shift ;;
         -help) dohelp=1; shift;;
+        -Xmx*) jvmMaxMemory="$1"; shift;;
         -D*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
         -X*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
         -agentpath:*) agentPath="$1"; shift;;
         -D*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
         -X*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
         -agentpath:*) agentPath="$1"; shift;;
@@ -114,6 +116,18 @@ if [ "${dohelp}" -eq 1 ]; then
     usage
 fi
 
     usage
 fi
 
+if [ "${jvmMaxMemory}"=="" ]; then
+    jvmMaxMemory="-Xmx1G"
+    echo "*****************************************************************"
+    echo "JVM maximum memory was not defined. Setting maximum memory to 1G."
+    echo "To define the maximum memory, specify the -Xmx setting on the"
+    echo "command line. "
+    echo "        e.g. ./run.sh -Xmx1G"
+    echo "*****************************************************************"
+fi
+
+extraJVMOpts="${extraJVMOpts} ${jvmMaxMemory}"
+
 # Validate debug port
 if [[ "${debugport}" -lt 1024 ]] || [[ "${debugport}" -gt 65535 ]]; then
     echo "Debug Port not in the range [1024,65535] ${debugport}"
 # Validate debug port
 if [[ "${debugport}" -lt 1024 ]] || [[ "${debugport}" -gt 65535 ]]; then
     echo "Debug Port not in the range [1024,65535] ${debugport}"