Merge pull request #196 from infosiftr/total_memory_available_override_value

Utilize total_memory_available_override_value and duplicate less internal RabbitMQ math
This commit is contained in:
yosifkit 2017-09-25 12:57:31 -07:00 committed by GitHub
commit ed9a656804
2 changed files with 64 additions and 82 deletions

View File

@ -269,12 +269,15 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
}
}' /sys/fs/cgroup/memory/memory.limit_in_bytes)"
fi
if [ -n "$memTotalKb" ] || [ -n "$memLimitB" ]; then
# https://github.com/docker-library/rabbitmq/pull/105#issuecomment-242165822
vmMemoryHighWatermark=
if [ -n "$memLimitB" ]; then
# if we have a cgroup memory limit, let's inform RabbitMQ of what it is (so it can calculate vm_memory_high_watermark properly)
# https://github.com/rabbitmq/rabbitmq-server/pull/1234
rabbitConfig+=( "{ total_memory_available_override_value, $memLimitB }" )
fi
if [ "${RABBITMQ_VM_MEMORY_HIGH_WATERMARK:-}" ]; then
# https://github.com/docker-library/rabbitmq/pull/105#issuecomment-242165822
vmMemoryHighWatermark="$(
awk -v lim="$memLimitB" '
awk '
/^[0-9]*[.][0-9]+$|^[0-9]+([.][0-9]+)?%$/ {
perc = $0;
if (perc ~ /%$/) {
@ -285,11 +288,7 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
printf "error: invalid percentage for vm_memory_high_watermark: %s (must be > 0%%, <= 100%%)\n", $0 > "/dev/stderr";
exit 1;
}
if (lim) {
printf "{ absolute, %d }\n", lim * perc;
} else {
printf "%0.03f\n", perc;
}
next;
}
/^[0-9]+$/ {
@ -306,18 +305,10 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
}
' <(echo "$RABBITMQ_VM_MEMORY_HIGH_WATERMARK")
)"
elif [ -n "$memLimitB" ]; then
# if there is a cgroup limit, default to 40% of _that_ (as recommended by upstream)
vmMemoryHighWatermark="{ absolute, $(awk -v lim="$memLimitB" 'BEGIN { printf "%.0f\n", lim * 0.4; exit }') }"
# otherwise let the default behavior win (40% of the total available)
fi
if [ "$vmMemoryHighWatermark" ]; then
# https://www.rabbitmq.com/memory.html#memsup-usage
rabbitConfig+=( "{ vm_memory_high_watermark, $vmMemoryHighWatermark }" )
fi
elif [ "${RABBITMQ_VM_MEMORY_HIGH_WATERMARK:-}" ]; then
echo >&2 'warning: RABBITMQ_VM_MEMORY_HIGH_WATERMARK was specified, but current system memory or cgroup memory limit cannot be determined'
echo >&2 ' (so "vm_memory_high_watermark" will not be set)'
fi
if [ "$haveSslConfig" ]; then

View File

@ -269,12 +269,15 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
}
}' /sys/fs/cgroup/memory/memory.limit_in_bytes)"
fi
if [ -n "$memTotalKb" ] || [ -n "$memLimitB" ]; then
# https://github.com/docker-library/rabbitmq/pull/105#issuecomment-242165822
vmMemoryHighWatermark=
if [ -n "$memLimitB" ]; then
# if we have a cgroup memory limit, let's inform RabbitMQ of what it is (so it can calculate vm_memory_high_watermark properly)
# https://github.com/rabbitmq/rabbitmq-server/pull/1234
rabbitConfig+=( "{ total_memory_available_override_value, $memLimitB }" )
fi
if [ "${RABBITMQ_VM_MEMORY_HIGH_WATERMARK:-}" ]; then
# https://github.com/docker-library/rabbitmq/pull/105#issuecomment-242165822
vmMemoryHighWatermark="$(
awk -v lim="$memLimitB" '
awk '
/^[0-9]*[.][0-9]+$|^[0-9]+([.][0-9]+)?%$/ {
perc = $0;
if (perc ~ /%$/) {
@ -285,11 +288,7 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
printf "error: invalid percentage for vm_memory_high_watermark: %s (must be > 0%%, <= 100%%)\n", $0 > "/dev/stderr";
exit 1;
}
if (lim) {
printf "{ absolute, %d }\n", lim * perc;
} else {
printf "%0.03f\n", perc;
}
next;
}
/^[0-9]+$/ {
@ -306,18 +305,10 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
}
' <(echo "$RABBITMQ_VM_MEMORY_HIGH_WATERMARK")
)"
elif [ -n "$memLimitB" ]; then
# if there is a cgroup limit, default to 40% of _that_ (as recommended by upstream)
vmMemoryHighWatermark="{ absolute, $(awk -v lim="$memLimitB" 'BEGIN { printf "%.0f\n", lim * 0.4; exit }') }"
# otherwise let the default behavior win (40% of the total available)
fi
if [ "$vmMemoryHighWatermark" ]; then
# https://www.rabbitmq.com/memory.html#memsup-usage
rabbitConfig+=( "{ vm_memory_high_watermark, $vmMemoryHighWatermark }" )
fi
elif [ "${RABBITMQ_VM_MEMORY_HIGH_WATERMARK:-}" ]; then
echo >&2 'warning: RABBITMQ_VM_MEMORY_HIGH_WATERMARK was specified, but current system memory or cgroup memory limit cannot be determined'
echo >&2 ' (so "vm_memory_high_watermark" will not be set)'
fi
if [ "$haveSslConfig" ]; then