3
votes

I am hosting the backend for my mobile application on Heroku. It's written in Scala using Scalatra to expose the REST API. In addition to that, I'm running a worker that fetches data and pushes it to the database at MongoHQ (using casbah). For both of them I keep getting R14 (Memory quota exceeded) errors. On my local machine, the worker is consuming not more than about 200 - 250 MB of memory and according to New Relic monitoring, the Scalatra app is utilizing only 250 MB on Heroku.

Those are the relevant environment variables on my Heroku instance:

JAVA_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops -javaagent:newrelic/newrelic.jar

JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true

SBT_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops

REPO: /app/.sbt_home/.ivy2/cache

The web service is not even receiving any traffic yet, so why could Heroku be complaining about memory consumption?

Marco

1
are you using scalate by any chance?Casual Jim

1 Answers

3
votes

As an experiment, try taking Scalate out of the equation. In theory, you should be able to run a Scalatra REST API and use roughly 64MB in the JVM, if you run without Scalate templating (which you shouldn't need for that sort of application).

It's hard to know definitively without poking at your deployment a bit. But as a guess, the Scalate compiler, which is now bundled by default into Scalatra's default G8 template in order to provide pre-compiled views for extra speed in production, may be putting you over Heroku's limit.

There's probably a way to get template precompilation to work outside of the Heroku deploy process, but I'm not familiar enough with Heroku deployments or Scalate template compilation to know how that'd work. If you deploy using a WAR, the templates will already be precompiled and you don't incur that startup penalty the first time.