Search code examples
scalasbtxsbt-web-pluginspray

How can I set the heap size of spray-can in Sbt's Build.scala?


I've got a running sbt project that can start my server using re-start. The setup was done using the xsbt-web-plugin.

Now I noticed that the server process runs with a heap of 128M which is a little short. I know how to configure the heap size for the sbt process, but apparently spray is running a different jvm.

How do I configure a larger heap for spray-can in this kind of setup?

Details

I've configured my sbt like I answered here: How to specify JVM maximum heap size "-Xmx" for running an application with "run" action in SBT?

BUT when I look at the running processes with jconsole I can see that the server process is running in a different jvm:

jconsole shows different process for server next to sbt-launch.jar

And I can see that this process has a heap of only 128M instead of the 3.5G I configured in .sbtconfig.

jconsole shows this process has only 128M memory


Solution

  • It is possible to fix this by setting the javaOptions for forked JVMs

    object BuildSettings {
       ....
       val buildSettings = Defaults.defaultSettings ++ Seq(
         ....
         javaOptions += "-Xmx1G"
         ....
      )
    }
    

    If you want to be more particular about different processes you can use something like

    javaOptions in run +="-Xmx1G"
    

    But I haven't found which value you should pass to in yet.