You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by le...@apache.org on 2020/01/13 08:05:55 UTC

[incubator-iotdb] 01/03: fix gc log collection in start-server.sh scripts

This is an automated email from the ASF dual-hosted git repository.

leirui pushed a commit to branch fixEnvBat
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit d4582e13cf83b0d635806c90551dd0bad817fbed
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Tue Dec 31 19:43:45 2019 +0800

    fix gc log collection in start-server.sh scripts
    
    (cherry picked from commit b7a30552d62abd3e9a80ac983f9269b0a3364c5f)
---
 .../UserGuide/3-Server/4-Config Manual.md          | 19 ++++++++++++-
 .../UserGuide/3-Server/4-Config Manual.md          | 20 +++++++++++++-
 server/src/assembly/resources/conf/iotdb-env.bat   | 29 +++++++++++---------
 server/src/assembly/resources/conf/iotdb-env.sh    | 31 +++++++++++++++++-----
 .../src/assembly/resources/sbin/start-server.bat   |  2 +-
 server/src/assembly/resources/sbin/start-server.sh |  6 ++++-
 6 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/docs/Documentation-CHN/UserGuide/3-Server/4-Config Manual.md b/docs/Documentation-CHN/UserGuide/3-Server/4-Config Manual.md
index 2310c17..e99c288 100644
--- a/docs/Documentation-CHN/UserGuide/3-Server/4-Config Manual.md	
+++ b/docs/Documentation-CHN/UserGuide/3-Server/4-Config Manual.md	
@@ -404,4 +404,21 @@
 |描述| Kerberos 认证原则|
 |类型| String |
 |默认值|your principal |
-|改后生效方式|重启服务器生效|
\ No newline at end of file
+|改后生效方式|重启服务器生效|
+
+
+## 开启GC日志
+GC日志默认是关闭的。为了性能调优,用户可能会需要手机GC信息。
+若要打开GC日志,则需要在启动IoTDB Server的时候加上"printgc"参数:
+
+```bash
+sbin/start-server.sh printgc
+```
+或者
+
+```bash
+sbin\start-server.bat printgc
+```
+
+GC日志会被存储在`IOTDB_HOME/logs/gc.log`. 至多会存储10个gc.log文件,每个文件最多10MB。
+
diff --git a/docs/Documentation/UserGuide/3-Server/4-Config Manual.md b/docs/Documentation/UserGuide/3-Server/4-Config Manual.md
index c95490b..a16cdcd 100644
--- a/docs/Documentation/UserGuide/3-Server/4-Config Manual.md	
+++ b/docs/Documentation/UserGuide/3-Server/4-Config Manual.md	
@@ -442,4 +442,22 @@ The detail of each variables are as follows:
 |Description| Kerberos pricipal|
 |Type| String |
 |Default|your principal |
-|Effective|After restart system|
\ No newline at end of file
+|Effective|After restart system|
+
+## Enable GC log
+GC log is off by default.
+For performance tuning, you may want to collect the GC info. 
+
+To enable GC log, just add a paramenter "printgc" when you start the server.
+
+```bash
+sbin/start-server.sh printgc
+```
+Or
+```bash
+sbin\start-server.bat printgc
+```
+
+GC log is stored at `IOTDB_HOME/logs/gc.log`.
+There will be at most 10 gc.log.* files and each one can reach to 10MB.
+
diff --git a/server/src/assembly/resources/conf/iotdb-env.bat b/server/src/assembly/resources/conf/iotdb-env.bat
index e04a409..fcf9fba 100644
--- a/server/src/assembly/resources/conf/iotdb-env.bat
+++ b/server/src/assembly/resources/conf/iotdb-env.bat
@@ -54,24 +54,27 @@ for /f "tokens=1-3" %%j in ('java -version 2^>^&1') do (
 	set BIT_VERSION=%%l
 )
 IF "%BIT_VERSION%" == "64-Bit" (
-  rem 64bit, Maximum heap size
-  set MAX_HEAP_SIZE="2G"
-  rem 64bit, Minimum heap size
-  set HEAP_NEWSIZE="2G"
+	rem 64-bit Java
+	echo Detect 64-bit Java, maximum memory allocation pool = 2GB, initial memory allocation pool = 2GB
+	set IOTDB_HEAP_OPTS=-Xmx2G -Xms2G
 ) ELSE (
-  rem 32bit, Maximum heap size
-  set MAX_HEAP_SIZE="512M"
-  rem 32bit, Minimum heap size
-  set HEAP_NEWSIZE="512M"
+	rem 32-bit Java
+	echo Detect 32-bit Java, maximum memory allocation pool = 512MB, initial memory allocation pool = 512MB
+	set IOTDB_HEAP_OPTS=-Xmx512M -Xms512M
 )
 
-@REM MAX_HEAP_SIZE="2G"
-@REM HEAP_NEWSIZE="2G"
-
-set IOTDB_HEAP_OPTS=-Xmx%MAX_HEAP_SIZE% -Xms%HEAP_NEWSIZE%
-
 @REM You can put your env variable here
 @REM set JAVA_HOME=%JAVA_HOME%
 
 :end_config_setting
+@REM set gc log.
+IF "%1" equ "printgc" (
+	IF %JAVA_VERSION% == 8 (
+	    md %IOTDB_HOME%\logs
+		set IOTDB_HEAP_OPTS=%IOTDB_HEAP_OPTS% -Xloggc:"%IOTDB_HOME%\logs\gc.log" -XX:+PrintGCDateStamps -XX:+PrintGCDetails  -XX:+PrintGCApplicationStoppedTime -XX:+PrintPromotionFailure -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M
+	) ELSE (
+		md %IOTDB_HOME%\logs
+		set IOTDB_HEAP_OPTS=%IOTDB_HEAP_OPTS%  -Xlog:gc=info,heap*=trace,age*=debug,safepoint=info,promotion*=trace:file="%IOTDB_HOME%\logs\gc.log":time,uptime,pid,tid,level:filecount=10,filesize=10485760
+	)
+)
 echo If you want to change this configuration, please check conf/iotdb-env.sh(Unix or OS X, if you use Windows, check conf/iotdb-env.bat).
\ No newline at end of file
diff --git a/server/src/assembly/resources/conf/iotdb-env.sh b/server/src/assembly/resources/conf/iotdb-env.sh
index 3d8e39b..0e06de1 100755
--- a/server/src/assembly/resources/conf/iotdb-env.sh
+++ b/server/src/assembly/resources/conf/iotdb-env.sh
@@ -128,12 +128,31 @@ fi
 
 version_arr=(${JVM_VERSION//./ })
 
+#GC log path has to be defined here because it needs to access CASSANDRA_HOME
 if [ "${version_arr[0]}" = "1" ] ; then
-  MAJOR_VERSION=${version_arr[1]}
-  IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xloggc:${IOTDB_HOME}/gc.log -XX:+PrintGCDateStamps -XX:+PrintGCDetails"
+    # Java 8
+    MAJOR_VERSION=${version_arr[1]}
+    echo "$IOTDB_JMX_OPTS" | grep -q "^-[X]loggc"
+    if [ "$?" = "1" ] ; then # [X] to prevent ccm from replacing this line
+        # only add -Xlog:gc if it's not mentioned in jvm-server.options file
+        mkdir -p ${IOTDB_HOME}/logs
+        if [ "$#" -ge "1" -a "$1" == "printgc" ]; then
+            IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xloggc:${IOTDB_HOME}/logs/gc.log  -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintPromotionFailure -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M"
+        fi
+    fi
 else
-  MAJOR_VERSION=${version_arr[0]}
-  IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xloggc:${IOTDB_HOME}/gc.log"
+    #JDK 11 and others
+    MAJOR_VERSION=${version_arr[0]}
+    # See description of https://bugs.openjdk.java.net/browse/JDK-8046148 for details about the syntax
+    # The following is the equivalent to -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M
+    echo "$IOTDB_JMX_OPTS" | grep -q "^-[X]log:gc"
+    if [ "$?" = "1" ] ; then # [X] to prevent ccm from replacing this line
+        # only add -Xlog:gc if it's not mentioned in jvm-server.options file
+        mkdir -p ${IOTDB_HOME}/logs
+        if [ "$#" -ge "1" -a "$1" == "printgc" ]; then
+            IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xlog:gc=info,heap*=trace,age*=debug,safepoint=info,promotion*=trace:file=${IOTDB_HOME}/logs/gc.log:time,uptime,pid,tid,level:filecount=10,filesize=10485760"
+        fi
+    fi
 fi
 
 
@@ -150,10 +169,10 @@ JMX_LOCAL=no
 JMX_PORT="31999"
 
 if [ "JMX_LOCAL" = "yes" ]; then
-	IOTDB_JMX_OPTS="-Diotdb.jmx.local.port=$JMX_PORT"
+	IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Diotdb.jmx.local.port=$JMX_PORT"
 	IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
 else
-	IOTDB_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false"
+	IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false"
 	IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT "
 fi
 
diff --git a/server/src/assembly/resources/sbin/start-server.bat b/server/src/assembly/resources/sbin/start-server.bat
index 57ba10d..823df0e 100755
--- a/server/src/assembly/resources/sbin/start-server.bat
+++ b/server/src/assembly/resources/sbin/start-server.bat
@@ -59,7 +59,7 @@ set IOTDB_CONF=%IOTDB_HOME%\conf
 set IOTDB_LOGS=%IOTDB_HOME%\logs
 
 IF EXIST "%IOTDB_CONF%\iotdb-env.bat" (
-    CALL "%IOTDB_CONF%\iotdb-env.bat"
+    CALL "%IOTDB_CONF%\iotdb-env.bat" %1
     ) ELSE (
     echo "can't find %IOTDB_CONF%\iotdb-env.bat"
     )
diff --git a/server/src/assembly/resources/sbin/start-server.sh b/server/src/assembly/resources/sbin/start-server.sh
index ed5e826..009e65a 100755
--- a/server/src/assembly/resources/sbin/start-server.sh
+++ b/server/src/assembly/resources/sbin/start-server.sh
@@ -31,7 +31,11 @@ IOTDB_CONF=${IOTDB_HOME}/conf
 # IOTDB_LOGS=${IOTDB_HOME}/logs
 
 if [ -f "$IOTDB_CONF/iotdb-env.sh" ]; then
-    . "$IOTDB_CONF/iotdb-env.sh"
+    if [ "$#" -ge "1" -a "$1" == "printgc" ]; then
+      . "$IOTDB_CONF/iotdb-env.sh" "printgc"
+    else
+        . "$IOTDB_CONF/iotdb-env.sh"
+    fi
 else
     echo "can't find $IOTDB_CONF/iotdb-env.sh"
 fi