Skip to content

Commit

Permalink
CLOUD-2842 - Xms and Xms are different when limits are higher than 5G…
Browse files Browse the repository at this point in the history
…i using JAVA_MAX_MEM_RATIO and JAVA_INITIAL_MEM_RATIO
  • Loading branch information
luck3y committed Sep 9, 2019
1 parent be123a8 commit 990bc15
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ container_memory() {
local max_mem_unbounded="$(max_unbounded)"
if [ -r "${mem_file}" ]; then
local max_mem="$(cat ${mem_file})"
# note that this may return a value that is the maximum 64-bit signed integer, rounded to the nearest page (by dropping the last bits).
# When this occurs, the comparision with MemTotal in /proc/meminfo will result it no value being returned.
if [ ${max_mem} -lt ${max_mem_unbounded} ]; then
echo "${max_mem}"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ max_memory() {
return
fi

# Check for the 'real memory size' and caluclate mx from a ratio
# Check for the 'real memory size' and calculate mx from a ratio
# given (default is 50%)
if [ "x$CONTAINER_MAX_MEMORY" != x ]; then
local max_mem="${CONTAINER_MAX_MEMORY}"
Expand Down Expand Up @@ -98,13 +98,18 @@ initial_memory() {
local max_ratio=${JAVA_MAX_MEM_RATIO:-${__DEFAULT_JAVA_MAX_MEM_RATIO}}
local initial_ratio=${JAVA_INITIAL_MEM_RATIO:-${__DEFAULT_JAVA_INITIAL_MEM_RATIO}}
local ms=$(echo "${max_mem} ${max_ratio} ${initial_ratio} 1048576" | awk '{printf "%d\n" , ($1*(($2*$3)/10000))/$4 + 0.5}')
local max_initial_memory=${JAVA_MAX_INITIAL_MEM:-${__DEFAULT_JAVA_MAX_INITIAL_MEM}}

# since CONTAINER_MAX_MEMORY is available (set by cgroups /sys/fs/cgroup/memory/memory.limit_in_bytes) then use that as the default)
local cmm=$(echo "${CONTAINER_MAX_MEMORY} 1048576" | awk '{printf "%d\n" , ($1/$2) + 0.5}')
local max_initial_memory=${JAVA_MAX_INITIAL_MEM:-${cmm}}

if [ "${ms}" -lt "${max_initial_memory}" ] ; then
echo "-Xms${ms}m"
else
echo "-Xms${max_initial_memory}m"
fi
fi
# otherwise no default value is returned
}

# Switch on diagnostics except when switched off
Expand Down
139 changes: 139 additions & 0 deletions jboss/container/java/jvm/bash/tests/bats/java-default-options.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
export JBOSS_CONTAINER_JAVA_JVM_MODULE=${BATS_TEST_DIRNAME}/../../../bash/artifacts/opt/jboss/container/java/jvm/
load $BATS_TEST_DIRNAME/../../../bash/artifacts/opt/jboss/container/java/jvm/java-default-options

@test "Test default initial memory value" {
expected="" # expect nothing
run initial_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test default initial memory values with valid CONTAINER_MAX_MEMORY" {
expected="-Xms64m"
CONTAINER_MAX_MEMORY=536870912
run initial_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test 6g initial memory values" {
expected="-Xms768m"
CONTAINER_MAX_MEMORY=6442450944
JAVA_MAX_INITIAL_MEM=6144
run initial_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test 6g initial memory values no CMM" {
expected="" # nothing, no CMM available
JAVA_MAX_INITIAL_MEM=6144
run initial_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test default max memory values" {
expected="" # expect nothing
run max_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test default max memory values with valid CONTAINER_MAX_MEMORY" {
expected="-Xmx256m"
CONTAINER_MAX_MEMORY=536870912
run max_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test default max memory values with CONTAINER_MAX_MEMORY=512mb" {
expected="-Xmx256m"
CONTAINER_MAX_MEMORY=536870912
run max_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test 6g max memory values with CONTAINER_MAX_MEMORY set to 6g" {
expected="-Xmx3072m"
CONTAINER_MAX_MEMORY=6442450944
run max_memory
echo "Result: ${output}"
echo "Expected: ${expected}"
[ "${expected}" = "${output}" ]
}

@test "Test default 0.9 max 1.0 initial " {
min_expected="" # should be empty
max_expected=""
JAVA_MAX_MEM_RATIO=90
JAVA_INITIAL_MEM_RATIO=100
run initial_memory
min=${output}
echo "Min Result: ${output}"
echo "Min Expected: ${min_expected}"
[ "${min_expected}" = "${min}" ]
run max_memory
max=${output}
echo "Max Result: ${output}"
echo "Max Expected: ${max_expected}"
}

@test "Test 6g 0.9 max 1.0 initial " {
min_expected="-Xms5530m"
max_expected="-Xmx5530m"
CONTAINER_MAX_MEMORY=6442450944
JAVA_MAX_MEM_RATIO=90
JAVA_INITIAL_MEM_RATIO=100
run initial_memory
min=${output}
echo "Min Result: ${output}"
echo "Min Expected: ${min_expected}"
[ "${min_expected}" = "${min}" ]
run max_memory
max=${output}
echo "Max Result: ${output}"
echo "Max Expected: ${max_expected}"
[ "${max_expected}" = "${max}" ]
}

@test "Test default 4g 0.9 max 1.0 max only " {
min_expected="" # should be unset, no CMM available
max_expected="-Xmx3686m"
JAVA_MAX_MEM_RATIO=90
JAVA_INITIAL_MEM_RATIO=100
run initial_memory
min=${output}
echo "Min Result: ${output}"
echo "Min Expected: ${min_expected}"
[ "${min_expected}" = "${min}" ]
run max_memory
max=${output}
echo "Max Result: ${output}"
echo "Max Expected: ${max_expected}"
}

@test "Test default 4g 1.0 max 1.0 max only " {
min_expected="" # CMM not available, expect nothing
max_expected="-Xmx4096m"
JAVA_MAX_MEM_RATIO=100
JAVA_INITIAL_MEM_RATIO=100
run initial_memory
min=${output}
echo "Min Result: ${output}"
echo "Min Expected: ${min_expected}"
[ "${min_expected}" = "${min}" ]
run max_memory
max=${output}
echo "Max Result: ${output}"
echo "Max Expected: ${max_expected}"
}

0 comments on commit 990bc15

Please sign in to comment.