Created
September 5, 2014 15:14
-
-
Save qrtt1/326afdc3d6f09ac31fca to your computer and use it in GitHub Desktop.
tomcat's setenv.sh for dynamic set max-memory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memory_estimate_script=$(mktemp /tmp/tmp.XXXXXXXXXX) | |
cat << EOF > $memory_estimate_script | |
import re | |
import os.path | |
if not os.path.exists("/proc/meminfo"): print 1024 | |
with open("/proc/meminfo") as fh: | |
line = fh.readline() | |
if "MemTotal" in line and "kB" in line: | |
m = re.search("\d+", line) | |
if m: | |
memory_kb = float(m.group()) * 0.7 | |
memory_mb = int(memory_kb / 1024) | |
print memory_mb | |
else: | |
print 1024 | |
EOF | |
memory_max_mb=$(python $memory_estimate_script) | |
export JAVA_HOME=/opt/java | |
export JAVA_OPTS="-Xms512m -Xmx"$memory_max_mb"m -XX:+UseParallelGC -Duser.timezone=Asia/Taipei -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true " | |
echo "JAVA_OPTS "$JAVA_OPTS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment