From 8a8a8d3e04fd8afa71cb0691141c747a146ca387 Mon Sep 17 00:00:00 2001 From: xiaoyekanren <876670773@qq.com> Date: Fri, 11 Aug 2023 19:20:07 +0800 Subject: [PATCH] add -cf for config_file, -maxheapsize for MAXHEAPSIZE, -heapsize for HEAPSIZE --- configuration/benchmark.sh | 6 +- configuration/bin/startup.sh | 98 +++++++++++++------ .../cn/edu/tsinghua/iot/benchmark/App.java | 7 +- 3 files changed, 76 insertions(+), 35 deletions(-) diff --git a/configuration/benchmark.sh b/configuration/benchmark.sh index ec519547e..ecef21e68 100755 --- a/configuration/benchmark.sh +++ b/configuration/benchmark.sh @@ -4,9 +4,9 @@ if [ -z "${BENCHMARK_HOME}" ]; then export BENCHMARK_HOME="$(cd "`dirname "$0"`"; pwd)" fi -if [ -n "$1" ]; then - exec $BENCHMARK_HOME/bin/startup.sh -cf "$1" +if [ $# -gt 0 ]; then + exec $BENCHMARK_HOME/bin/startup.sh "$@" else - exec $BENCHMARK_HOME/bin/startup.sh -cf $BENCHMARK_HOME/conf/config.properties + exec $BENCHMARK_HOME/bin/startup.sh fi exit $? \ No newline at end of file diff --git a/configuration/bin/startup.sh b/configuration/bin/startup.sh index b6df989c5..cbe0c34b8 100755 --- a/configuration/bin/startup.sh +++ b/configuration/bin/startup.sh @@ -18,20 +18,50 @@ # under the License. # +# Maximum heap size +#MAX_HEAP_SIZE="2G" +# Minimum heap size +#HEAP_NEWSIZE="2G" -if [ -z "${BENCHMARK_HOME}" ]; then - export BENCHMARK_HOME="$(cd "`dirname "$0"`"/.. && pwd)" -fi - -echo Set BENCHMARK_HOME=$BENCHMARK_HOME - -MAIN_CLASS=cn.edu.tsinghua.iot.benchmark.App +show_help() { + echo "usage: benchmark.sh [-cf configuration_file] [-heapsize HEAP_SIZE] [-maxheapsize MAX_HEAP_SIZE]" + echo " -h Show help." + echo " -cf Specify configuration file." + echo " -heapsize Specify HEAP_SIZE." + echo " -maxheapsize Specify MAX_HEAP_SIZE." + echo "example: ./benchmark.sh -cf conf/config.properties -heapsize 1G -maxheapsize 2G" +} -CLASSPATH="" -for f in ${BENCHMARK_HOME}/lib/*.jar; do - CLASSPATH=${CLASSPATH}":"$f +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + -h|--help) + show_help + exit 0 + ;; + -cf) + benchmark_conf="$2" + shift + shift + ;; + -maxheapsize) + MAX_HEAP_SIZE="$2" + shift + shift + ;; + -heapsize) + HEAP_NEWSIZE="$2" + shift + shift + ;; + *) + echo "unknown: $key" + exit 1 + ;; + esac done +# check java if [ -n "$JAVA_HOME" ]; then for java in "$JAVA_HOME"/bin/java "$JAVA_HOME"/bin/amd64/java; do if [ -x "$java" ]; then @@ -48,39 +78,47 @@ if [ -z $JAVA ] ; then exit 1; fi -# Maximum heap size -#MAX_HEAP_SIZE="2G" -# Minimum heap size -#HEAP_NEWSIZE="2G" - -while [[ $# -gt 0 ]]; do - key="$1" - case $key in - -cf) - benchmark_conf="$2" - ;; - esac - shift -done +# check BENCHMARK_HOME +if [ -z "${BENCHMARK_HOME}" ]; then + export BENCHMARK_HOME="$(cd "`dirname "$0"`"/.. && pwd)" +fi +# check $benchmark_conf if [ -z $benchmark_conf ] ; then benchmark_conf=${BENCHMARK_HOME}/conf/config.properties else benchmark_conf="$(cd "$(dirname "$benchmark_conf")" && pwd)/$(basename "$benchmark_conf")" + if [ ! -e "$benchmark_conf" ]; then + echo "The file $benchmark_conf does not exist." + exit 1 + fi fi echo Using configuration file: $benchmark_conf +# set MAIN_CLASS +MAIN_CLASS=cn.edu.tsinghua.iot.benchmark.App +# set CLASSPATH +CLASSPATH="" +for f in ${BENCHMARK_HOME}/lib/*.jar; do + CLASSPATH=${CLASSPATH}":"$f +done + +# set benchmark_parms benchmark_parms="$benchmark_parms -Duser.timezone=GMT+8" benchmark_parms="$benchmark_parms -Dlogback.configurationFile=${BENCHMARK_HOME}/conf/logback.xml" - -if [ -n $MAX_HEAP_SIZE ] && [ -n "$HEAP_NEWSIZE" ];then - echo Set MAX_HEAP_SIZE=$MAX_HEAP_SIZE, HEAP_NEWSIZE=$HEAP_NEWSIZE - benchmark_parms="$benchmark_parms -Xms${HEAP_NEWSIZE} -Xmx${MAX_HEAP_SIZE}" -else +if [ -n "$MAX_HEAP_SIZE" ]; then + echo Set MAX_HEAP_SIZE=$MAX_HEAP_SIZE + benchmark_parms="$benchmark_parms -Xmx${MAX_HEAP_SIZE}" +fi +if [ -n "$HEAP_NEWSIZE" ]; then + echo Set HEAP_NEWSIZE=$HEAP_NEWSIZE + benchmark_parms="$benchmark_parms -Xms${HEAP_NEWSIZE}" +fi +if [ -z $MAX_HEAP_SIZE ] && [ -z "$HEAP_NEWSIZE" ]; then echo Using default memory configuration to startup. - fi +# startup exec "$JAVA" $benchmark_parms -cp "$CLASSPATH" "$MAIN_CLASS" -cf "$benchmark_conf" exit $? \ No newline at end of file diff --git a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/App.java b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/App.java index 50d50b0be..8d155d855 100644 --- a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/App.java +++ b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/App.java @@ -39,8 +39,11 @@ public static void main(String[] args) throws SQLException { long initialHeapSize = Runtime.getRuntime().totalMemory(); long maxHeapSize = Runtime.getRuntime().maxMemory(); LOGGER.info( - String.format( - "Initial Heap Size: %d bytes, Max Heap Size: %d bytes.", initialHeapSize, maxHeapSize)); + "Initial Heap Size: " + + initialHeapSize + + "bytes, Max Heap Size: " + + maxHeapSize + + "bytes."); if (args == null || args.length == 0) { args = new String[] {"-cf", "configuration/conf/config.properties"};