Skip to content

Commit

Permalink
java_opts adjust xmx according to the machines memory
Browse files Browse the repository at this point in the history
  • Loading branch information
oriy committed Apr 22, 2019
1 parent 50e9378 commit 1d331d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Bash/java_opts_adjust_xmx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

JAVA_OPTS_XMX_MB=$(echo "Xmx: ${JAVA_OPTS}" | sed -e 's/.*\-Xmx\([0-9]\+\)m.*/\1/g' -e 's/.*\-Xmx\([0-9]\+\)g.*/\1*1024/g' | bc)
MEMTOTAL_MB=$(awk '/MemTotal:/ { print $2/1024 }' /proc/meminfo | cut -d. -f1)
echo "Setting jvm memory::: Memory Total: ${MEMTOTAL_MB}MB, Requested Xmx: ${JAVA_ARG_XMX_MB} "

# setting minimal between requested xmx, leaving at least 15% or 1GB
XMX_MB=$(echo " \
${JAVA_OPTS_XMX_MB}
$(echo "$MEMTOTAL_MB - 1024" | bc)
$(echo "$MEMTOTAL_MB * 0.85" | bc)" \
| sort -n | head -1 | sed -e 's/\..*//g' -e 's/\ //g')

echo "Memory Total: ${MEMTOTAL_MB}MB, Xms: ${XMX_MB}MB, Xmx: ${XMX_MB}MB"

#replacing xms and xmx with the available xmx possible
JAVA_OPTS=$(echo ${JAVA_OPTS} | sed -e 's/\"-Xm[xs][0-9]\+[mg]\"//g')
JAVA_OPTS=`eval echo -Xmx${XMX_MB}m -Xms${XMX_MB}m ${JAVA_OPTS}`
2 changes: 1 addition & 1 deletion Bash/read_server_ip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo -n "Type the IP address of the server and press [ENTER]:"
read ip_server
while [ $(echo ${ip_server} | egrep -c "10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") -lt 1 ]
while [[ $(echo ${ip_server} | egrep -c "10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") -lt 1 ]]
do
read -p "Retype the PRIVATE IP address of the server and press [ENTER]:" ip_server
done

0 comments on commit 1d331d6

Please sign in to comment.