Skip to content

Commit bb29f9a

Browse files
Cam Saulcamsaul
Cam Saul
authored andcommitted
Fix deploying to Heroku (OOM issues) [ci skip]
1 parent 7bcbbe7 commit bb29f9a

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Procfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: ./bin/start
1+
web: HEROKU=true ./bin/start

app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"business intelligence",
66
"analytics",
77
"dashboard",
8-
"charting"
8+
"charting",
9+
"metabase"
910
],
1011
"website": "http://www.metabase.com/",
1112
"repository": "https://github.com/metabase/metabase",

bin/start

+24-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,29 @@ if [ ! -z "$RDS_HOSTNAME" ]; then
8282
export MB_DB_PORT=$RDS_PORT
8383
fi
8484

85-
JAVA_OPTS="${JAVA_OPTS} -XX:+IgnoreUnrecognizedVMOptions"
86-
JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
87-
JAVA_OPTS="${JAVA_OPTS} --add-opens=java.base/java.net=ALL-UNNAMED"
88-
JAVA_OPTS="${JAVA_OPTS} --add-modules=java.xml.bind"
85+
# Determine whether we're on Heroku on a free, hobby, or 1x dyno.
86+
#
87+
# We set $HEROKU in the Procfile; we know we're on a baby dyno if the process limit is 256 per user.
88+
#
89+
# On a baby dyno we need to override the $JAVA_OPTS and give it a slightly lower memory limit because Heroku tends to think
90+
# we can use more memory than we actually can. It defaults to giving us 300m but that still ends up going over the 512MB
91+
# limit for the dyno. Set a few other additional options to minimize memory usage as well.
92+
if [ -n "$HEROKU" ] && [ `ulimit -u` = 256 ]; then
93+
JAVA_OPTS="$JAVA_OPTS -Xmx248m" # This seems to be the right amount that prevents the dyno from going over the quota
94+
JAVA_OPTS="$JAVA_OPTS -XX:-UseGCOverheadLimit" # Disable limit to amount of time spent in GC. Better slow than not working at all
95+
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC" # ConcMarkSweepGC seems to cause less OOM issues in my testing on low-mem Heroku envs
96+
JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled" # Not 100% sure this does anything in Java 8 but if it does, we want to enable it
97+
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops" # Use 32-bit pointers. Reduces memory usage and GC events
98+
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedClassPointers" # Same as above. See also http://blog.leneghan.com/2012/03/reducing-java-memory-usage-and-garbage.html
99+
fi
100+
101+
# Other Java options
102+
JAVA_OPTS="$JAVA_OPTS -XX:+IgnoreUnrecognizedVMOptions" # Don't barf if we see an option we don't understand (e.g. Java 9 option on Java 7/8)
103+
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true" # don't try to start AWT. Not sure this does anything but better safe than wasting memory
104+
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8" # Use UTF-8
105+
JAVA_OPTS="$JAVA_OPTS --add-opens=java.base/java.net=ALL-UNNAMED" # Allow dynamically adding JARs to classpath (Java 9)
106+
JAVA_OPTS="$JAVA_OPTS --add-modules=java.xml.bind" # Enable access to java.xml.bind module (Java 9)
107+
108+
echo "Using these JAVA_OPTS: ${JAVA_OPTS}"
89109

90110
exec java $JAVA_OPTS -jar ./target/uberjar/metabase.jar

0 commit comments

Comments
 (0)