Commit 306d2dee authored by Jeremy Morrell's avatar Jeremy Morrell Committed by Jeremy Morrell

Detect when WEB_CONCURRENCY is way too high

parent 2403875f
...@@ -4,6 +4,9 @@ calculate_concurrency() { ...@@ -4,6 +4,9 @@ calculate_concurrency() {
WEB_CONCURRENCY=${WEB_CONCURRENCY-$((MEMORY_AVAILABLE/WEB_MEMORY))} WEB_CONCURRENCY=${WEB_CONCURRENCY-$((MEMORY_AVAILABLE/WEB_MEMORY))}
if (( WEB_CONCURRENCY < 1 )); then if (( WEB_CONCURRENCY < 1 )); then
WEB_CONCURRENCY=1 WEB_CONCURRENCY=1
elif (( WEB_CONCURRENCY > 100 )); then
# Ex: This will happen on Dokku on DO
WEB_CONCURRENCY=1
fi fi
echo $WEB_CONCURRENCY echo $WEB_CONCURRENCY
} }
...@@ -23,6 +26,22 @@ detect_memory() { ...@@ -23,6 +26,22 @@ detect_memory() {
fi fi
} }
warn_bad_web_concurrency() {
local memory=${MEMORY_AVAILABLE-$(detect_memory 512)}
# No webserver will have 10000GB of RAM
if [ $memory -gt "10000000" ]; then
echo "Could not determine a reasonable value for WEB_CONCCURENCY.
This is likely due to running the Heroku NodeJS buildpack on a non-Heroku
platform.
WEB_CONCURRENCY has been set to 1. Please review whether this value is
appropriate for your application."
fi
}
warn_bad_web_concurrency
export MEMORY_AVAILABLE=${MEMORY_AVAILABLE-$(detect_memory 512)} export MEMORY_AVAILABLE=${MEMORY_AVAILABLE-$(detect_memory 512)}
export WEB_MEMORY=${WEB_MEMORY-512} export WEB_MEMORY=${WEB_MEMORY-512}
export WEB_CONCURRENCY=$(calculate_concurrency) export WEB_CONCURRENCY=$(calculate_concurrency)
......
...@@ -386,6 +386,15 @@ testConcurrencyCustomLimit() { ...@@ -386,6 +386,15 @@ testConcurrencyCustomLimit() {
assertCapturedSuccess assertCapturedSuccess
} }
# When /sys/fs/cgroup/memory/memory.limit_in_bytes lies and gives a ridiculous value
# This happens on Dokku for example
testConcurrencyTooHigh() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=10000000000 capture $(pwd)/profile/WEB_CONCURRENCY.sh
assertCaptured "Could not determine a reasonable value for WEB_CONCCURENCY"
assertCaptured "Recommending WEB_CONCURRENCY=1"
assertCapturedSuccess
}
testInvalidNode() { testInvalidNode() {
compile "invalid-node" compile "invalid-node"
assertCaptured "Resolving node version 0.11.333" assertCaptured "Resolving node version 0.11.333"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment