2

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)
5
  • 1
    Use a profiler, or at least jstack, to find out what's happening during that time. The JVM isn't a black box. Commented Feb 13, 2012 at 21:24
  • So I ran the process by jvisualvm. Once the slowness occurs the top 3 methods taking longest times are: java.net.SocketInputStream.read(...), java.util.concurrent.locks.LockSupport.parkNanos(...) and java.lang.reflect.Method.invoke(...). 64%, 21% and 12% of the time spent there. Commented Feb 13, 2012 at 22:38
  • 1
    java.net.SocketInputStream.read(...) is blocking on socket IO. You might want to use jstack first (run repeatedly when it's slow) to figure out what's happening on the relevant thread. Commented Feb 13, 2012 at 22:48
  • After stripping off all the other components of the code. The profiler reports following as the hot spots: scala.tools.nsc.interepreter.IMain.bind() 39.2% scala.tools.nsc.interpreter.IMain.interpret() 24.5%. Further drill down indicates most of the time spent inside ReadEvalPrint.compile() and Request.compile() methods taking most of the time. Commented Feb 14, 2012 at 14:39
  • I have had similar problems. Occasionally I would even get java.lang.OutOfMemoryError: PermGen space. I found using -XX:PermSize=128m -XX:MaxPermSize=512m helped. But I would like to find a more efficient way of resolving this myself. Commented Apr 17, 2013 at 9:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.