Skip to content

Commit

Permalink
add -cf for config_file, -maxheapsize for MAXHEAPSIZE, -heapsize for …
Browse files Browse the repository at this point in the history
…HEAPSIZE
  • Loading branch information
xiaoyekanren committed Aug 11, 2023
1 parent b6981de commit 8a8a8d3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 35 deletions.
6 changes: 3 additions & 3 deletions configuration/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
98 changes: 68 additions & 30 deletions configuration/bin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $?
7 changes: 5 additions & 2 deletions core/src/main/java/cn/edu/tsinghua/iot/benchmark/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down

0 comments on commit 8a8a8d3

Please sign in to comment.