1

I am trying to run a program which takes a large amount of memory using the sbt "run" command and I seem to be running into the problem that the jvm seems to be getting a second -Xmx parameter from somewhere that overrides mine.

I am running the program via "sbt run".

Looking at the processes I can find the following:

/usr/bin/java -XX:MaxPermSize=256M -Xmx32G -Xms1024m -Xmx1024m -XX:ReservedCodeCacheSize=128m -jar /usr/local/Cellar/sbt/0.13.6/libexec/sbt-launch.jar run

My sbt file is as follows:

lazy val commonSettings = Seq(
    organization := "edu.university",
    version := "0.1.0",
    scalaVersion := "2.10.2",
    name := "Example",
    javaOptions += "-Xmx32G"
)

If you would like to test it this is a piece of code I created that just fills memory.

package edu.university

import java.lang.Thread
import scala.collection.mutable.ArrayBuffer

object Main {
    val arraySize = 10000
    val nmws = 160000000 // no OOM
    // val nmws = 180000000 // OOM
    val r = scala.util.Random
    def main(args: Array[String]): Unit = {
        println("hi")
        val ab = new ArrayBuffer[Memwaster](nmws)
        ab.transform { a => new Memwaster(r.nextInt) }
        println("done")
        Thread.sleep(20000)
    }
}
class Memwaster(foo: Int)

Running with the larger nmws value will use a little over 1G of memory then throw an out of memory error.

Shawn
  • 402
  • 4
  • 17
  • So, what's your question? – yanana Jul 06 '15 at 17:56
  • How do I remove the second -Xmx parameter. It appears to use the second one given that it is running out of ram around 1G. "... -Xmx32G -Xms1024m -Xmx1024m ... " I should probably mention that I am running it via "sbt run". – Shawn Jul 06 '15 at 18:03
  • I suggest you try the instructions listed at http://stackoverflow.com/questions/3868863/how-to-specify-jvm-maximum-heap-size-xmx-for-running-an-application-with-run - if you're using SBT 0.13.6 or later, check out iwein's answer (not the accepted answer) – childofsoong Jul 06 '15 at 18:18
  • Maybe defined in `$HOME/.sbtrc` or `/.sbtrc`? – yanana Jul 06 '15 at 18:20
  • Neither of those files seem to exist. I have also checked the environment variables and none seem to be relevant. – Shawn Jul 06 '15 at 20:14
  • @FearTheCron Is there `$HOME/.sbtconfig`, `/usr/local/etc/sbtopts`, or `/.sbtopts`? – yanana Jul 07 '15 at 08:39

1 Answers1

0

Turns out one solution is to set the -mem option in sbtopts. I found my sbtopts at /usr/local/etc/sbtopts (under OSx Yosemete). For 32G I set it to "-mem 32000". If this is a bad solution please post another answer I am happy to hear input here.

Sorta figured this out through the following documentation: https://opensource.ncsa.illinois.edu/confluence/display/DFDL/Configure+SBT

Does this seem like a bug that the javaOptions value in my build.sbt doesn't override this? Or is this the desired behavior for some reason?

Shawn
  • 402
  • 4
  • 17