3

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

Community
  • 1
  • 1
Marco Lamina
  • 3,326
  • 4
  • 22
  • 22

1 Answers1

3

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.

futurechimp
  • 554
  • 4
  • 6
  • Indeed, I was using Scalate! I removed it and the memory footprint went down about 200MB for the worker and the web dyno. Unfortunately, they are still using about 350MB of memory each: https://gist.github.com/mlamina/5363755 – Marco Lamina Apr 11 '13 at 14:20
  • Running the web app locally, it only needs bout 80MB of memory – Marco Lamina Apr 11 '13 at 14:21
  • Allthough having hosted a pure web app on Heroku, my setup is quite similar. I am using Scalate for the templating and also tried New Relic. Testing the setup locally (by using target/start with the same params as on Heroku) I found out, that the New Relic agent was responsible for most of the memory overhead. – jan Aug 14 '13 at 10:25