scala nsc IMain bind() 速度和内存问题

发布于 2025-01-05 08:08:41 字数 2397 浏览 2 评论 0原文

我们使用tools.nsc.interpreter.IMain 的bind() 和interpret() 方法在服务器上执行scala 脚本。这是在 scala 2.9.1 和 Java 7u2 上运行的。

重复使用同一个 IMain 实例后,bind() 方法突然开始花费很长时间(5-6 秒甚至更长)。我尝试过 close() reset() 但没有任何帮助。奇怪的是,使用几次后突然变慢。

在此处输入图像描述

代码片段(一遍又一遍地执行):

main.bind("status", status)
try {
    main.interpret(prepare(restriction, input))
} catch {
    case e: Exception =>
        status.setCode("ERR6")
        status.setSummary("Error Interpreting Restriction")
        status.setType(MetaFileElements.ERROR_VALUE)
        status.setValue("Restriction: \"" + restriction + "\", Input: \"" + input + "\"")
}

另一个问题是最终进程因此错误而崩溃:

Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.findBootstrapClass(Native Method)
    at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1061)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at scala.tools.nsc.util.Exceptional$.unwrap(Exceptional.scala:140)
    at scala.tools.nsc.interpreter.IMain$Request$$anonfun$handleException$1$1.apply(IMain.scala:821)
    at scala.tools.nsc.interpreter.IMain$Request$$anonfun$handleException$1$1.apply(IMain.scala:818)
    at scala.tools.nsc.interpreter.IMain$$anonfun$withoutBindingLastException$2.apply(IMain.scala:228)
    at scala.util.control.Exception$Catch.apply(Exception.scala:88)
    at scala.tools.nsc.interpreter.IMain.withoutBindingLastException(IMain.scala:226)
    at scala.tools.nsc.interpreter.IMain$Request.handleException$1(IMain.scala:818)
    at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:838)
    at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:471)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:503)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:468)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:525)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:544)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:545)
    at com.nomura.fi.spg.kozo.meta.client.helper.RestrictionsHelper$.execute(RestrictionsHelper.scala:22)

We are using tools.nsc.interpreter.IMain's bind() and interpret() method to execute scala scripts on a server. This is on on scala 2.9.1 and Java 7u2.

After repeatedly using the same IMain instance, the bind() methods suddenly starts to take very long time (5-6 seconds and even longer). I have tried close() reset() but nothing helps. Weird thing is that the sudden slowness occurs after several uses.

enter image description here

Code snippet (that is executed over and over again):

main.bind("status", status)
try {
    main.interpret(prepare(restriction, input))
} catch {
    case e: Exception =>
        status.setCode("ERR6")
        status.setSummary("Error Interpreting Restriction")
        status.setType(MetaFileElements.ERROR_VALUE)
        status.setValue("Restriction: \"" + restriction + "\", Input: \"" + input + "\"")
}

Another Issue is evetually the process crashes with this error:

Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.findBootstrapClass(Native Method)
    at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1061)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at scala.tools.nsc.util.Exceptional$.unwrap(Exceptional.scala:140)
    at scala.tools.nsc.interpreter.IMain$Request$anonfun$handleException$1$1.apply(IMain.scala:821)
    at scala.tools.nsc.interpreter.IMain$Request$anonfun$handleException$1$1.apply(IMain.scala:818)
    at scala.tools.nsc.interpreter.IMain$anonfun$withoutBindingLastException$2.apply(IMain.scala:228)
    at scala.util.control.Exception$Catch.apply(Exception.scala:88)
    at scala.tools.nsc.interpreter.IMain.withoutBindingLastException(IMain.scala:226)
    at scala.tools.nsc.interpreter.IMain$Request.handleException$1(IMain.scala:818)
    at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:838)
    at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:471)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:503)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:468)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:525)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:544)
    at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:545)
    at com.nomura.fi.spg.kozo.meta.client.helper.RestrictionsHelper$.execute(RestrictionsHelper.scala:22)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文