This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new c889776 [IOTDB-845]Enable to stop iotdb server by iotdb.IoTDB (#1633)
c889776 is described below
commit c889776653a4d327618e6908874ed82e14ce1910
Author: yanhong wang <[email protected]>
AuthorDate: Wed Oct 21 03:46:10 2020 +0800
[IOTDB-845]Enable to stop iotdb server by iotdb.IoTDB (#1633)
---
server/src/assembly/resources/conf/iotdb-env.bat | 70 +++++++++++++++-------
.../src/assembly/resources/sbin/start-server.bat | 2 +-
server/src/assembly/resources/sbin/stop-server.bat | 17 +++++-
server/src/assembly/resources/sbin/stop-server.sh | 11 ++--
4 files changed, 70 insertions(+), 30 deletions(-)
diff --git a/server/src/assembly/resources/conf/iotdb-env.bat
b/server/src/assembly/resources/conf/iotdb-env.bat
index 74a5986..dcd93b3 100644
--- a/server/src/assembly/resources/conf/iotdb-env.bat
+++ b/server/src/assembly/resources/conf/iotdb-env.bat
@@ -18,6 +18,7 @@
@REM
@echo off
+setlocal enabledelayedexpansion
@REM true or false
@REM DO NOT FORGET TO MODIFY THE PASSWORD FOR SECURITY
(%IOTDB_CONF%\jmx.password and %{IOTDB_CONF%\jmx.access)
set JMX_LOCAL="true"
@@ -44,24 +45,51 @@ if %JMX_LOCAL% == "false" (
echo "setting local JMX..."
)
-@REM Maximum heap size
-set MAX_HEAP_SIZE=2G
-@REM Minimum heap size
-set HEAP_NEWSIZE=2G
+set line=0
+for /f %%a in ('wmic cpu get numberofcores') do (
+ set /a line+=1
+ if !line!==2 set system_cpu_cores=%%a
+)
+set as=%system_cpu_cores%
+
+if ["%system_cpu_cores%"] LSS ["1"] set system_cpu_cores="1"
+
+set liner=0
+for /f %%b in ('wmic memorychip get capacity') do (
+ set /a liner+=1
+ if !liner!==2 set system_memory=%%b
+)
+
+echo wsh.echo FormatNumber(cdbl(%system_memory%)/(1024*1024), 0) >
%temp%\tmp.vbs
+for /f "tokens=*" %%a in ('cscript //nologo %temp%\tmp.vbs') do set
system_memory_in_mb=%%a
+del %temp%\tmp.vbs
+set system_memory_in_mb=%system_memory_in_mb:,=%
+
+set /a half_=%system_memory_in_mb%/2
+set /a quarter_=%half_%/2
+
+if ["%half_%"] GTR ["1024"] set half_=1024
+if ["%quarter_%"] GTR ["8192"] set quarter_=8192
+
+if ["%half_%"] GTR ["quarter_"] (
+ set max_heap_size_in_mb=%half_%
+) else set max_heap_size_in_mb=%quarter_%
+
+set MAX_HEAP_SIZE=%max_heap_size_in_mb%M
+set max_sensible_yg_per_core_in_mb=100
+set /a
max_sensible_yg_in_mb=%max_sensible_yg_per_core_in_mb%*%system_cpu_cores%
+set /a desired_yg_in_mb=%max_heap_size_in_mb%/4
+
+if ["%desired_yg_in_mb%"] GTR ["%max_sensible_yg_in_mb%"] (
+ set HEAP_NEWSIZE=%max_sensible_yg_in_mb%M
+) else set HEAP_NEWSIZE=%desired_yg_in_mb%M
IF ["%IOTDB_HEAP_OPTS%"] EQU [""] (
rem detect Java 8 or 11
IF "%JAVA_VERSION%" == "8" (
java -d64 -version >nul 2>&1
- IF NOT ERRORLEVEL 1 (
- rem 64-bit Java
- echo Detect 64-bit Java, maximum memory allocation pool
= %MAX_HEAP_SIZE%B, initial memory allocation pool = %HEAP_NEWSIZE%B
- set IOTDB_HEAP_OPTS=-Xmx%MAX_HEAP_SIZE%
-Xms%HEAP_NEWSIZE% -Xloggc:"%IOTDB_HOME%\gc.log" -XX:+PrintGCDateStamps
-XX:+PrintGCDetails
- ) ELSE (
- 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
-Xloggc:"%IOTDB_HOME%\gc.log" -XX:+PrintGCDateStamps -XX:+PrintGCDetails
- )
+ echo Maximum memory allocation pool = %MAX_HEAP_SIZE%, initial
memory allocation pool = %HEAP_NEWSIZE%
+ set IOTDB_HEAP_OPTS=-Xmx%MAX_HEAP_SIZE% -Xms%HEAP_NEWSIZE%
-Xloggc:"%IOTDB_HOME%\gc.log" -XX:+PrintGCDateStamps -XX:+PrintGCDetails
goto end_config_setting
) ELSE (
goto detect_jdk11_bit_version
@@ -75,15 +103,8 @@ for /f "tokens=1-3" %%j in ('java -version 2^>^&1') do (
@rem echo %%l
set BIT_VERSION=%%l
)
-IF "%BIT_VERSION%" == "64-Bit" (
- rem 64-bit Java
- echo Detect 64-bit Java, maximum memory allocation pool =
%MAX_HEAP_SIZE%B, initial memory allocation pool = %HEAP_NEWSIZE%B
- set IOTDB_HEAP_OPTS=-Xmx%MAX_HEAP_SIZE% -Xms%HEAP_NEWSIZE%
-) ELSE (
- 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
-)
+echo Maximum memory allocation pool = %MAX_HEAP_SIZE%, initial memory
allocation pool = %HEAP_NEWSIZE%
+set IOTDB_HEAP_OPTS=-Xmx%MAX_HEAP_SIZE% -Xms%HEAP_NEWSIZE%
-Xloggc:"%IOTDB_HOME%\gc.log" -XX:+PrintGCDateStamps -XX:+PrintGCDetails
@REM You can put your env variable here
@REM set JAVA_HOME=%JAVA_HOME%
@@ -99,4 +120,7 @@ IF "%1" equ "printgc" (
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
+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).
+
+@REM Maximum heap size
+@REM set MAX_HEAP_SIZE=2G
\ No newline at end of file
diff --git a/server/src/assembly/resources/sbin/start-server.bat
b/server/src/assembly/resources/sbin/start-server.bat
index 0cf8a07..cc65068 100755
--- a/server/src/assembly/resources/sbin/start-server.bat
+++ b/server/src/assembly/resources/sbin/start-server.bat
@@ -95,7 +95,7 @@ set JAVA_OPTS=-ea^
@REM ***** CLASSPATH library setting *****
@REM Ensure that any user defined CLASSPATH variables are not used on startup
set CLASSPATH="%IOTDB_HOME%\lib\*"
-
+set CLASSPATH=%CLASSPATH%;iotdb.IoTDB
goto okClasspath
:append
diff --git a/server/src/assembly/resources/sbin/stop-server.bat
b/server/src/assembly/resources/sbin/stop-server.bat
index 0cfdbdc..b1dbf7c 100755
--- a/server/src/assembly/resources/sbin/stop-server.bat
+++ b/server/src/assembly/resources/sbin/stop-server.bat
@@ -19,5 +19,20 @@
@echo off
-wmic process where (commandline like "%%iotdb.IoTDB%%" and not
name="wmic.exe") delete
+set current_dir=%~dp0
+set superior_dir=%current_dir%\..\
+
+for /f "eol=; tokens=2,2 delims==" %%i in ('findstr /i "rpc_port"
+%superior_dir%\conf\iotdb-engine.properties') do (
+ set rpc_port=%%i
+)
+
+for /f "eol=; tokens=2,2 delims==" %%i in ('findstr /i "rpc_address"
+%superior_dir%\conf\iotdb-engine.properties') do (
+ set rpc_address=%%i
+)
+
+for /f "tokens=5" %%a in ('netstat /ano ^| findstr %rpc_address%:%rpc_port%')
do (
+ taskkill /f /pid %%a
+)
rem ps ax | grep -i 'iotdb.IoTDB' | grep -v grep | awk '{print $1}' | xargs
kill -SIGTERM
diff --git a/server/src/assembly/resources/sbin/stop-server.sh
b/server/src/assembly/resources/sbin/stop-server.sh
index cc94639..d353833 100755
--- a/server/src/assembly/resources/sbin/stop-server.sh
+++ b/server/src/assembly/resources/sbin/stop-server.sh
@@ -19,12 +19,13 @@
#
-PIDS=$(ps ax | grep -i 'IoTDB' | grep java | grep -v grep | awk '{print $1}')
+IOTDB_CONF="`dirname "$0"`/../conf"
+rpc_port=`sed '/^rpc_port=/!d;s/.*=//' ${IOTDB_CONF}/iotdb-engine.properties`
+PID=$(lsof -t -i:${rpc_port})
-if [ -z "$PIDS" ]; then
+if [ "$PID" = "" ]; then
echo "No IoTDB server to stop"
- exit 1
-else
- kill -s TERM $PIDS
+else
+ kill -s TERM $PID
echo "close IoTDB"
fi