如何指定JVM最大堆大小“-Xmx”用于使用“run”运行应用程序SBT 中的行动?

发布于 2024-09-26 05:52:53 字数 109 浏览 8 评论 0原文

我的应用程序进行大型数据数组处理,并且需要比 JVM 默认提供的内存更多的内存。我知道在Java中它是由“-Xmx”选项指定的。如何设置 SBT 以使用特定的“-Xmx”值来通过“运行”操作运行应用程序?

My application does large data arrays processing and needs more memory than JVM gives by default. I know in Java it's specified by "-Xmx" option. How do I set SBT up to use particular "-Xmx" value to run an application with "run" action?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

却一份温柔 2024-10-03 05:52:53

对于分叉进程,您应该查看 Build.scala

要修改分叉进程的 java 选项,您需要在 Build.scala(或您为构建命名的任何名称)中指定它们,如下所示

val buildSettings = Defaults.defaultSettings ++ Seq(
   //…
   javaOptions += "-Xmx1G",
   //…
)

:为您提供正确的选项,而无需全局修改 JAVA_OPTS, 它将把自定义 JAVA_OPTS 放入 sbt 生成的启动脚本

对于非分叉进程,最方便的是通过 sbtoptssbtconfig 设置配置,具体取决于在你的 sbt 版本上。

自 sbt 0.13.6 起 .sbtconfig 已弃用 。按照以下方式修改 /usr/local/etc/sbtopts

-J-Xms512M
-J-Xmx3536M
-J-Xss1M
-J-XX:+CMSClassUnloadingEnabled
-J-XX:+UseConcMarkSweepGC
-J-XX:MaxPermSize=724M
-J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

您还可以在 SBT 项目的根目录中创建一个 .sbtopts 文件,使用与 /usr/local/etc/sbtopts 文件中的语法相同。这使得该项目是独立的。

在 sbt 0.13.6 之前,您可以在 .sbtconfig 中为非分叉进程设置选项:

  1. 检查 sbt 在哪里:

    $ 其中 sbt
    /usr/local/bin/sbt
    
  2. 查看内容:

    $ cat /usr/local/bin/sbt
    #!/bin/sh
    测试-f ~/.sbtconfig && 。 〜/ .sbtconfig
    exec java ${SBT_OPTS} -jar /usr/local/Cellar/sbt/0.12.1/libexec/sbt-launch.jar "$@"
    
  3. 设置正确的jvm选项以防止OOM(常规和PermGen):

    <前><代码>$ cat ~/.sbtconfig
    SBT_OPTS =“-Xms512M -Xmx3536M -Xss1M
    -XX:+CMSClassUnloading启用
    -XX:+UseConcMarkSweepGC -XX:MaxPermSize=724M"

如果您只想为当前运行的 sbt 设置 SBT_OPTS,您可以使用 env SBT_OPTS=".." sbt 正如 Googol Shan 所建议的。或者您可以使用 Sbt 12 中添加的选项:sbt -mem 2048。对于较长的选项列表来说,这会变得很笨拙,但如果您有不同的项目和不同的需求,这可能会有所帮助。

请注意,CMSClassUnloadingEnabled 与 UseConcMarkSweepGC 配合使用有助于保持 PermGen 空间清洁,但根据您使用的框架,您可能会在 PermGen 上发生实际泄漏,这最终会强制重新启动。

For forked processes you should look at Build.scala

To modify the java options for forked processes you need to specify them in the Build.scala (or whatever you've named your build) like this:

val buildSettings = Defaults.defaultSettings ++ Seq(
   //…
   javaOptions += "-Xmx1G",
   //…
)

This will give you the proper options without modifying JAVA_OPTS globally, and it will put custom JAVA_OPTS in an sbt generated start-script

For non forked processes it's most convenient to set the config via sbtopts or sbtconfig depending on your sbt version.

Since sbt 0.13.6 .sbtconfig is deprecated. Modify /usr/local/etc/sbtopts along these lines:

-J-Xms512M
-J-Xmx3536M
-J-Xss1M
-J-XX:+CMSClassUnloadingEnabled
-J-XX:+UseConcMarkSweepGC
-J-XX:MaxPermSize=724M
-J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

You can also create an .sbtopts file in the root of your SBT project using the same syntax as in the /usr/local/etc/sbtopts file. This makes the project self-contained.

Before sbt 0.13.6 you could set the options in .sbtconfig for non forked processes:

  1. Check where sbt is:

    $ which sbt
    /usr/local/bin/sbt
    
  2. Look at the contents:

    $ cat /usr/local/bin/sbt
    #!/bin/sh
    test -f ~/.sbtconfig && . ~/.sbtconfig
    exec java ${SBT_OPTS} -jar /usr/local/Cellar/sbt/0.12.1/libexec/sbt-launch.jar "$@"
    
  3. Set the correct jvm options to prevent OOM (both regular and PermGen):

    $ cat ~/.sbtconfig
    SBT_OPTS="-Xms512M -Xmx3536M -Xss1M 
     -XX:+CMSClassUnloadingEnabled 
     -XX:+UseConcMarkSweepGC -XX:MaxPermSize=724M"
    

If you want to set SBT_OPTS only for the current run of sbt you can use env SBT_OPTS=".." sbt as suggested by Googol Shan. Or you can use the option added in Sbt 12: sbt -mem 2048. This gets unwieldy for longer lists of options, but it might help if you have different projects with different needs.

Note that CMSClassUnloadingEnabled in concert with UseConcMarkSweepGC helps keep the PermGen space clean, but depending on what frameworks you use you might have an actual leak on PermGen, which eventually forces a restart.

偏闹i 2024-10-03 05:52:53

在 sbt 版本 12 中,有一个选项可以实现此目的:

$sbt -mem 2048 

In sbt version 12 onwards there is an option for this:

$sbt -mem 2048 
为人所爱 2024-10-03 05:52:53

如果你在linux shell上运行sbt,你可以使用:

env JAVA_OPTS="-Xmx512m" sbt run

这是我通常使用的命令来运行我的sbt项目。

If you run sbt on linux shell, you can use:

env JAVA_OPTS="-Xmx512m" sbt run

This is my usually used command to run my sbt project.

短叹 2024-10-03 05:52:53

从 SBT 0.13.6 开始,.sbtconfig 已弃用。相反,我通过以下方式在 /usr/local/etc/sbtopts 中配置了这些选项:

-J-Xms512M
-J-Xmx3536M
-J-Xss1M
-J-XX:+CMSClassUnloadingEnabled
-J-XX:+UseConcMarkSweepGC
-J-XX:MaxPermSize=724M
-J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

.sbtconfig is deprecated starting with SBT 0.13.6. Instead, I configured these options in /usr/local/etc/sbtopts in the following way:

-J-Xms512M
-J-Xmx3536M
-J-Xss1M
-J-XX:+CMSClassUnloadingEnabled
-J-XX:+UseConcMarkSweepGC
-J-XX:MaxPermSize=724M
-J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
摘星┃星的人 2024-10-03 05:52:53

试试这个:

class ForkRun(info: ProjectInfo) extends DefaultProject(info) {
    override def fork = Some(new ForkScalaRun {
        override def runJVMOptions = super.runJVMOptions ++ Seq("-Xmx512m")
        override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile)
    })
}

Try this:

class ForkRun(info: ProjectInfo) extends DefaultProject(info) {
    override def fork = Some(new ForkScalaRun {
        override def runJVMOptions = super.runJVMOptions ++ Seq("-Xmx512m")
        override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile)
    })
}
把回忆走一遍 2024-10-03 05:52:53

我知道有一种方法。设置环境变量JAVA_OPTS。

JAVA_OPTS='-Xmx512m'

我还没有找到一种方法可以将其作为命令参数来执行此操作。

There's one way I know of. Set the environment variable JAVA_OPTS.

JAVA_OPTS='-Xmx512m'

I have not found a way to do this as a command parameter.

时光是把杀猪刀 2024-10-03 05:52:53

使用 JAVA_OPTS 来设置环境变量。

对 sbt 使用 -JX 选项作为单个选项,例如 -J-Xmx2048 -J-XX:MaxPermSize=512

较新版本的 sbt 有一个“-mem”选项。

Use JAVA_OPTS for setting with environment variable.

Use -J-X options to sbt for individual options, e.g. -J-Xmx2048 -J-XX:MaxPermSize=512

Newer versions of sbt have a "-mem" option.

撩起发的微风 2024-10-03 05:52:53

当我们在通过 sbt 运行 Specs2 测试时看到抛出 java.lang.OutOfMemoryError 时,上面 @iwein 引用的 build.sbt 中的 javaOptions += "-XX:MaxPermSize=1024" 对我们有用。

The javaOptions += "-XX:MaxPermSize=1024" in our build.sbt as referenced by @iwein above worked for us when we were seeing a java.lang.OutOfMemoryError thrown while running Specs2 tests through sbt.

も让我眼熟你 2024-10-03 05:52:53

环境变量是_JAVA_OPTIONS,需要设置。
设置 _JAVA_OPTIONS 后,当您进行 sbt 时,sbt 将使用 JAVA_OPTIONS 和值显示消息。

或者,您可以在 sbt 或 .scala 文件中设置 javaOption
例如,

javaOptions += "-Xmx1G"

从 sbt shell 中,您可以运行 show javaOptions 来查看设置的值。

The environment variable is _JAVA_OPTIONS, which needs to be set.
Once you set _JAVA_OPTIONS, and when you sbt, sbt will show the message using JAVA_OPTIONS and the values.

Alternatively you could set javaOption in the sbt or .scala file
e.g

javaOptions += "-Xmx1G"

From sbt shell you could run show javaOptions to see the values that are set.

新人笑 2024-10-03 05:52:53

的文件中列出运行项目所需的 JVM 选项

名为.jvmopts

sbt 允许您在项目根目录中 。
java 选项

cat .jvmopts
-Xms512M
-Xmx4096M
-Xss2M
-XX:MaxMetaspaceSize=1024M

然后添加您希望它经过测试并在 Windows 10 中运行的
https://www.lagomframework.com/documentation/1.4.x/ scala/JVMMemoryOnDev.html

sbt lets you list the JVM options you need to run your project on a file named

.jvmopts

in the root of your project.
then add the java options that you want

cat .jvmopts
-Xms512M
-Xmx4096M
-Xss2M
-XX:MaxMetaspaceSize=1024M

it is tested and works in windows 10
https://www.lagomframework.com/documentation/1.4.x/scala/JVMMemoryOnDev.html

懷念過去 2024-10-03 05:52:53
    javaOptions in Test += "-Xmx1G"

这将设置用于测试的 JVM 选项。也适用于 jvm 分叉(fork in Test := true)。

    javaOptions in Test += "-Xmx1G"

This sets the JVM options for tests. Works also with jvm forking (fork in Test := true).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文