2

I'm using JRuby to run some Ruby scripts from Java and collect the results. Everything works fine, but performance is unacceptably slow - while executing script.rb from terminal takes about 0.3 seconds, executing it via JRuby from Java takes over 10 seconds. The code I'm using is:

ScriptingContainer jruby = new ScriptingContainer(LocalContextScope.THREADSAFE);
String script = readScript("script.rb");
Object receiver = jruby.runScriptlet(script);   // takes ~10 seconds
Map<String, String> executionResult = (Map<String, String>) jruby.callMethod(receiver, ...);

The bottleneck is the runScriptlet() method, which takes 8-10 seconds on an otherwise normally performant Linux machine. I'm using JRuby 9.1.6.0 with Java 8 (openjdk 1.8).

Am I doing something wrong - perhaps missing some essential settings - or is this just how slow JRuby really is? Has anybody else encountered this?

w128
  • 4,680
  • 7
  • 42
  • 65
  • Can you post the scripts code? That might be the problem - JRuby is *apparently* faster than the C compiler – Luke Melaia Jan 04 '17 at 10:25
  • @LukeMelaia I'm using the script that is mostly the same as the one in the example [here](https://github.com/WinRb/WinRM). Even if the script is a single-line "puts 'Hi!'", the `runScriptlet` takes ~5 seconds. – w128 Jan 04 '17 at 10:30
  • How fast does the script run if you run it a second time? Likely the performance hit is in reading and processing everything necessary to actually run the script, so if there's a way, only do that once and run the script over and over. – Andrew Henle Jan 04 '17 at 11:30
  • @AndrewHenle subsequent calls to `runScriptlet` are faster, but still rather slow (i.e. multiple seconds). However, this is not good enough: I need the initial delay to be must shorter. – w128 Jan 04 '17 at 12:57
  • there must be smt blocking in that case -> usual candidate is low entropy on the system. try an advice from [here](http://stackoverflow.com/a/2325109/454312) to confirm. – kares Jan 10 '17 at 11:47
  • @kares I ran the program with the `-Djava.security.egd=file:/dev/./urandom` parameter, without any noticeable difference in performance. – w128 Jan 10 '17 at 14:28
  • sorry, in that case its all about finding out the bottlenecks using JVM tools – kares Jan 23 '17 at 08:57

0 Answers0