如何指定JVM最大堆大小“-Xmx”用于使用“run”运行应用程序SBT 中的行动?
我的应用程序进行大型数据数组处理,并且需要比 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
对于分叉进程,您应该查看 Build.scala
要修改分叉进程的 java 选项,您需要在 Build.scala(或您为构建命名的任何名称)中指定它们,如下所示
:为您提供正确的选项,而无需全局修改 JAVA_OPTS, 它将把自定义 JAVA_OPTS 放入 sbt 生成的启动脚本
对于非分叉进程,最方便的是通过
sbtopts
或sbtconfig
设置配置,具体取决于在你的 sbt 版本上。自 sbt 0.13.6 起
.sbtconfig
已弃用 。按照以下方式修改/usr/local/etc/sbtopts
:您还可以在 SBT 项目的根目录中创建一个
.sbtopts
文件,使用与 /usr/local/etc/sbtopts 文件中的语法相同。这使得该项目是独立的。在 sbt 0.13.6 之前,您可以在 .sbtconfig 中为非分叉进程设置选项:
检查 sbt 在哪里:
查看内容:
设置正确的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:
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
orsbtconfig
depending on your sbt version.Since sbt 0.13.6
.sbtconfig
is deprecated. Modify/usr/local/etc/sbtopts
along these lines: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:
Check where sbt is:
Look at the contents:
Set the correct jvm options to prevent OOM (both regular and PermGen):
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.
在 sbt 版本 12 中,有一个选项可以实现此目的:
In sbt version 12 onwards there is an option for this:
如果你在linux shell上运行sbt,你可以使用:
这是我通常使用的命令来运行我的sbt项目。
If you run sbt on linux shell, you can use:
This is my usually used command to run my sbt project.
从 SBT
0.13.6
开始,.sbtconfig
已弃用。相反,我通过以下方式在/usr/local/etc/sbtopts
中配置了这些选项:.sbtconfig
is deprecated starting with SBT0.13.6
. Instead, I configured these options in/usr/local/etc/sbtopts
in the following way:试试这个:
Try this:
我知道有一种方法。设置环境变量JAVA_OPTS。
我还没有找到一种方法可以将其作为命令参数来执行此操作。
There's one way I know of. Set the environment variable JAVA_OPTS.
I have not found a way to do this as a command parameter.
使用 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.
当我们在通过 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.环境变量是_JAVA_OPTIONS,需要设置。
设置 _JAVA_OPTIONS 后,当您进行 sbt 时,sbt 将使用 JAVA_OPTIONS 和值显示消息。
或者,您可以在 sbt 或 .scala 文件中设置 javaOption
例如,
从 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
From sbt shell you could run show javaOptions to see the values that are set.
的文件中列出运行项目所需的 JVM 选项
名为.jvmopts
sbt 允许您在项目根目录中 。
java 选项
然后添加您希望它经过测试并在 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
it is tested and works in windows 10
https://www.lagomframework.com/documentation/1.4.x/scala/JVMMemoryOnDev.html
这将设置用于测试的 JVM 选项。也适用于 jvm 分叉(
fork in Test := true
)。This sets the JVM options for tests. Works also with jvm forking (
fork in Test := true
).