Skip to content

Commit

Permalink
Configuration file and Memory size can be specified before startup
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyekanren committed Aug 10, 2023
1 parent ea5c80f commit b6981de
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
9 changes: 6 additions & 3 deletions configuration/benchmark.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh
#!/bin/bash

if [ -z "${BENCHMARK_HOME}" ]; then
export BENCHMARK_HOME="$(cd "`dirname "$0"`"; pwd)"
fi

exec $BENCHMARK_HOME/bin/startup.sh -cf $BENCHMARK_HOME/conf/config.properties

if [ -n "$1" ]; then
exec $BENCHMARK_HOME/bin/startup.sh -cf "$1"
else
exec $BENCHMARK_HOME/bin/startup.sh -cf $BENCHMARK_HOME/conf/config.properties
fi
exit $?
48 changes: 42 additions & 6 deletions configuration/bin/startup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
Expand All @@ -20,10 +20,10 @@


if [ -z "${BENCHMARK_HOME}" ]; then
export BENCHMARK_HOME="$(cd "`dirname "$0"`"/..; pwd)"
export BENCHMARK_HOME="$(cd "`dirname "$0"`"/.. && pwd)"
fi

echo $BENCHMARK_HOME
echo Set BENCHMARK_HOME=$BENCHMARK_HOME

MAIN_CLASS=cn.edu.tsinghua.iot.benchmark.App

Expand All @@ -32,9 +32,8 @@ for f in ${BENCHMARK_HOME}/lib/*.jar; do
CLASSPATH=${CLASSPATH}":"$f
done


if [ -n "$JAVA_HOME" ]; then
for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
for java in "$JAVA_HOME"/bin/java "$JAVA_HOME"/bin/amd64/java; do
if [ -x "$java" ]; then
JAVA="$java"
break
Expand All @@ -44,7 +43,44 @@ else
JAVA=java
fi

if [ -z $JAVA ] ; then
echo Unable to find java executable. Check JAVA_HOME and PATH environment variables. > /dev/stderr
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

if [ -z $benchmark_conf ] ; then
benchmark_conf=${BENCHMARK_HOME}/conf/config.properties
else
benchmark_conf="$(cd "$(dirname "$benchmark_conf")" && pwd)/$(basename "$benchmark_conf")"
fi
echo Using configuration file: $benchmark_conf

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
echo Using default memory configuration to startup.

fi

exec "$JAVA" -Duser.timezone=GMT+8 -Dlogback.configurationFile=${BENCHMARK_HOME}/conf/logback.xml -cp "$CLASSPATH" "$MAIN_CLASS" "$@"
exec "$JAVA" $benchmark_parms -cp "$CLASSPATH" "$MAIN_CLASS" -cf "$benchmark_conf"

exit $?
9 changes: 9 additions & 0 deletions core/src/main/java/cn/edu/tsinghua/iot/benchmark/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@
import cn.edu.tsinghua.iot.benchmark.mode.TestWithDefaultPathMode;
import cn.edu.tsinghua.iot.benchmark.mode.VerificationQueryMode;
import cn.edu.tsinghua.iot.benchmark.mode.VerificationWriteMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;

public class App {
private static Logger LOGGER = LoggerFactory.getLogger(Config.class);

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));

if (args == null || args.length == 0) {
args = new String[] {"-cf", "configuration/conf/config.properties"};
}
Expand Down

0 comments on commit b6981de

Please sign in to comment.