Skip to content
Snippets Groups Projects
Unverified Commit 594c1133 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #7582 from happy-camper/heroku-2x-dyno-config

Add memory constraints for a 2x dyno
parents fdc37629 c1e8642d
Branches
Tags
No related merge requests found
......@@ -82,15 +82,30 @@ if [ ! -z "$RDS_HOSTNAME" ]; then
export MB_DB_PORT=$RDS_PORT
fi
# Determine whether we're on Heroku on a free, hobby, or 1x dyno.
# Determine whether we're on Heroku on a free, hobby, 1x dyno or 2x dyno
#
# We set $HEROKU in the Procfile; we know we're on a baby dyno if the process limit is 256 per user.
# We set $HEROKU in the Procfile, so we know we're on Heroku when started from the
# Procfile.
#
# On a baby dyno we need to override the $JAVA_OPTS and give it a slightly lower memory limit because Heroku tends to think
# we can use more memory than we actually can. It defaults to giving us 300m but that still ends up going over the 512MB
# limit for the dyno. Set a few other additional options to minimize memory usage as well.
if [ -n "$HEROKU" ] && [ `ulimit -u` = 256 ]; then
JAVA_OPTS="$JAVA_OPTS -Xmx248m" # This seems to be the right amount that prevents the dyno from going over the quota
# We need to override the $JAVA_OPTS and give it a slightly lower memory limit
# because Heroku tends to think we can use more memory than we actually can.
if [ -n "$HEROKU" ]; then
echo " -> Heroku detected"
if [ `ulimit -u` = 256 ]; then
# free, hobby or 1x dyno, it defaults to giving us 300m but that still ends
# up going over the 512MB limit for the dyno.
echo " => 1x dyno"
JAVA_OPTS="$JAVA_OPTS -Xmx248m" # This seems to be the right amount that prevents the dyno from going over the quota
fi
if [ `ulimit -u` = 512 ]; then
# 2x dyno, it defaults to giving us 800m but that still ends
# up going over the 1024MB limit for the dyno.
echo " => 2x dyno"
JAVA_OPTS="$JAVA_OPTS -Xmx496m" # This seems to be the right amount that prevents the dyno from going over the quota
fi
# Set a few other additional options to minimize memory usage as well.
JAVA_OPTS="$JAVA_OPTS -XX:-UseGCOverheadLimit" # Disable limit to amount of time spent in GC. Better slow than not working at all
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC" # ConcMarkSweepGC seems to cause less OOM issues in my testing on low-mem Heroku envs
JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled" # Not 100% sure this does anything in Java 8 but if it does, we want to enable it
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment