spydon
spydon

Reputation: 11542

SBT killed when running out of ram

I am trying to run my scala application in a docker container with 800MB of RAM, (docker run -m=800m mindlevel) but it gets killed before it is done compiling.

[info] Compiling 10 Scala sources to /root/mindlevel-backend/target/scala-2.12/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.12.1. Compiling...
[info]   Compilation completed in 8.631 s
/usr/local/sbt/bin/sbt-launch-lib.bash: line 58:    57 Killed                  "$@"

I have tried to restrict the SBT heap with:

CMD ["sbt", "-mem", "700", "run"]

But it still gets killed at the same place. Without any restrictions on the docker container it runs fine. When running it in an EC2 micro instance (1GB of RAM) it also crashes, with or without restrictions on SBT and Docker.

Is there some restriction that I am missing?

Upvotes: 3

Views: 2417

Answers (1)

spydon
spydon

Reputation: 11542

To get it to run with less than 1GB heap I precompiled the project with sbt assembly which makes a jar packaged with your project and all of your dependencies.

Install it by adding:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")

to project/assembly.sbt

Then generate the jar with sbt assembly which will place the jar in ./target/scala-<VERSION>/<PROJECT>-assembly-1.0.jar

Then simply run your project with:

scala target/scala-<VERSION>/<PROJECT>-assembly-1.0.jar

Since no compilation step is needed on the low memory instance now a lot of projects will be able to run even though it is less memory than recommended.

Upvotes: 5

Related Questions