Can't set memory settings for `sbt start`
Asked Answered
H

2

9

I'm trying to run sbt start in a Play Framework application written in Scala, on a machine that is an ec2 t2.micro instance on AWS. But i can't because There is insufficient memory for the Java Runtime Environment to continue.

The machine has 1GB of memory, but in practice 930MB of free memory to use while running the remaining of OS processes. It is Ubuntu Server 14.04 LTS. The app is small, cute.

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000d5550000, 715849728, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 715849728 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /app/incoming/hs_err_pid9709.log

Here is the link to the log file for more info.

Inside i see jvm_args: -Xms1024m -Xmx1024m -XX:ReservedCodeCacheSize=128m ... despite i set my JVM args in so many different ways to something else but no effect.

With these arguments -Xss1m -Xms256m -Xmx512m -XX:+CMSClassUnloadingEnabled I tried everything:

  • setting JVM args in /usr/share/sbt-launcher-packaging/conf/sbtopts
  • same in /usr/share/sbt-launcher-packaging/conf/sbtconfig.txt
  • supplying the args directly when running: sbt -J-Xss1m -J-Xms256m -J-Xmx512m -J-XX:+CMSClassUnloadingEnabled start
  • already set fork in run := true in build.sbt
  • javaOptions in run += "-Xmx512m -XX:+CMSClassUnloadingEnabled" in build.sbt

Neither of them helps. The same lame 1024 things appear in the logs every time i run the app. Please help.

Hosea answered 16/9, 2014 at 19:47 Comment(2)
Bump. Still no clue.Crossfertilize
I've misinterpreted your question and thought you whanted to increase memory allocated to jvm when you actually wanted to decrease it. You still should be able to use my suggestion to do it, but with different memory amount. I've updated my answer, let me know whether it worked for you or not.Ferris
F
14

Also struggled with setting jvm memory args for sbt on Linux in the past (on Windows you can tweak sbtconfig.txt but this and all other places where you can specify SBT_OPTS I could find doesn't work on Linux for some reason).

Last time I've solved this by using -mem <amount> option of sbt itself.

So, in your case you should try something like this:

$ sbt -mem 512 start
Ferris answered 18/9, 2014 at 10:38 Comment(0)
W
1

I had the same problem today with EC2 nano-instance. Solved it this way:

cd /etc/sbt-launcher-packaging/ 
sudo nano sbtopts

Then uncomment -mem option. I've set it to 256 and after that I can normally run sbt on nano-instance. A sample piece of this config file after edited:

# Path to local Ivy repository (default: ~/.ivy2)
#
#-ivy ~/.ivy2

# set memory options
#
-mem   256

# Use local caches for projects, no sharing.
#
#-no-share
Warmedover answered 7/6, 2016 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.