【发布时间】:2019-07-08 00:53:54
【问题描述】:
我是 scala 编程新手,当我在一个大型 scala 项目中执行 sbt test 命令时遇到 GC overhead limit exceeded 错误。有谁知道我该如何解决这个问题?
【问题讨论】:
标签: scala configuration garbage-collection sbt
我是 scala 编程新手,当我在一个大型 scala 项目中执行 sbt test 命令时遇到 GC overhead limit exceeded 错误。有谁知道我该如何解决这个问题?
【问题讨论】:
标签: scala configuration garbage-collection sbt
我得到了朋友的帮助:)
例如通过执行 -mem 选项来增加内存选项:
sbt -mem 2048 test
其他选项:
对于 Mac 和 Linux 用户:
如果我们需要经常执行此操作。我们可以更新.bash_profile 文件并添加以下命令:
export SBT_OPTS="-Xmx2G"
其他解决方案(也适用于 Windows):
还有一个特定的sbtopts 文件,您可以在其中保留此内存设置:
在 Mac/Linux 中查找文件:
/usr/local/etc/sbtopts
或者在 Windows 中
C:\Program Files (x86)\sbt\conf
并添加以下配置:
# set memory options
#
-mem 2048
希望这些提示中的任何一个都可以帮助解决此问题的人。
编辑:
如果有人像我一样使用 IntelliJ IDEA,您可以使用 VM 参数增加 sbt 内存使用量,如下图所示。
【讨论】:
查看launcher script for running sbt,它在我的系统上位于/usr/share/sbt/bin/sbt,我们看到以下内容:
declare -r sbt_opts_file=".sbtopts"
declare -r etc_sbt_opts_file="/etc/sbt/sbtopts"
declare -r dist_sbt_opts_file="${sbt_home}/conf/sbtopts"
...
# Here we pull in the default settings configuration.
[[ -f "$dist_sbt_opts_file" ]] && set -- $(loadConfigFile "$dist_sbt_opts_file") "$@"
# Here we pull in the global settings configuration.
[[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$@"
# Pull in the project-level config file, if it exists.
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"
# Pull in the project-level java config, if it exists.
[[ -f ".jvmopts" ]] && export JAVA_OPTS="$JAVA_OPTS $(loadConfigFile .jvmopts)"
run "$@"
因此我们可以将配置设置放入:
.jvmopts
.sbtopts
/etc/sbt/sbtopts
${sbt_home}/conf/sbtopts
例如typelevel/cats项目使用.jvmopts来设置-Xmx3G。或者我们可以这样做
echo "-mem 2048" >> .sbtopts
关于环境变量sbt -h文件说明
JAVA_OPTS environment variable, if unset uses "$java_opts"
.jvmopts if this file exists in the current directory, its contents
are appended to JAVA_OPTS
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
.sbtopts if this file exists in the current directory, its contents
are prepended to the runner args
例如,
export JAVA_OPTS=-Xmx2G
sbt
应该以 2G 内存运行 sbt。
请注意,如果您在forked JVM 中运行测试,那么您可以通过build.sbt 中的javaOptions 设置来增加内存,如下所示:
Test / fork := true
Test / javaOptions ++= Seq("-Xmx4G")
VisualVM 是一个有用的工具,用于查看在尝试配置 SBT 的不同方式时将哪些设置传递给 JVM 进程。
【讨论】: