Faster JRuby execution

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Faster JRuby execution

mojavelinux
Administrator
For small tasks, such as converting an AsciiDoc document, there are certain flags you can enable for JRuby and Java that make it startup much, much faster, esp when invoked via Java (like 3x as fast). The trade-off is that you are disabling optimizations that impact long-running processes, but...exactly, we don't need them.

Here's the set of flags I've worked out thus far:

-Djruby.compat.version=RUBY1_9 -Djruby.compile.mode=OFF -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none

Here's an example of making a simple JRuby call without these flags:

time jruby -e 'puts "Hello, World!"'

real 0m1.170s
user 0m1.966s
sys 0m0.078s

Now I'll add these flags,

export JRUBY_OPTS="-Djruby.compat.version=RUBY1_9 -Djruby.compile.mode=OFF -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none"

and call the same script again:

time jruby -e 'puts "Hello, World!"'

real 0m0.090s
user 0m0.070s
sys 0m0.021s

That certainly speeds things up.

Now, I'll execute the generate-resources goal in Maven to invoke the Asciidoctor Maven plugin, first without any flags:

real 0m7.361s
user 0m14.733s
sys 0m0.297s

Now I'll add the flags. The only way I can figure out to pass these flags to JRuby is to set them as Maven options:

real 0m3.310s
user 0m4.537s
sys 0m0.260s

Voila! I think that will certainly save a lot of waiting :)

If anyone knows:

a. Flags that can make it go even faster
b. How to pass flags to JRuby w/o having to apply them to Maven globally

please let us know!

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

LightGuardjp
This should go up on a blog post


On Mon, Apr 15, 2013 at 2:09 PM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:
For small tasks, such as converting an AsciiDoc document, there are certain flags you can enable for JRuby and Java that make it startup much, much faster, esp when invoked via Java (like 3x as fast). The trade-off is that you are disabling optimizations that impact long-running processes, but...exactly, we don't need them.

Here's the set of flags I've worked out thus far:

-Djruby.compat.version=RUBY1_9 -Djruby.compile.mode=OFF -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none

Here's an example of making a simple JRuby call without these flags:

time jruby -e 'puts "Hello, World!"'

real 0m1.170s
user 0m1.966s
sys 0m0.078s

Now I'll add these flags,

export JRUBY_OPTS="-Djruby.compat.version=RUBY1_9 -Djruby.compile.mode=OFF -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none"

and call the same script again:

time jruby -e 'puts "Hello, World!"'

real 0m0.090s
user 0m0.070s
sys 0m0.021s

That certainly speeds things up.

Now, I'll execute the generate-resources goal in Maven to invoke the Asciidoctor Maven plugin, first without any flags:

real 0m7.361s
user 0m14.733s
sys 0m0.297s

Now I'll add the flags. The only way I can figure out to pass these flags to JRuby is to set them as Maven options:

real 0m3.310s
user 0m4.537s
sys 0m0.260s

Voila! I think that will certainly save a lot of waiting :)

If anyone knows:

a. Flags that can make it go even faster
b. How to pass flags to JRuby w/o having to apply them to Maven globally

please let us know!

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Faster-JRuby-execution-tp130.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

mojavelinux
Administrator
That's my plan. Alex, since it's related to the Java integration, I'd like to offer you the first shot at doing a blog post.

-Dan


On Mon, Apr 15, 2013 at 4:06 PM, lightguard.jp [via Asciidoctor :: Discussion] <[hidden email]> wrote:
This should go up on a blog post


On Mon, Apr 15, 2013 at 2:09 PM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:
For small tasks, such as converting an AsciiDoc document, there are certain flags you can enable for JRuby and Java that make it startup much, much faster, esp when invoked via Java (like 3x as fast). The trade-off is that you are disabling optimizations that impact long-running processes, but...exactly, we don't need them.

Here's the set of flags I've worked out thus far:

-Djruby.compat.version=RUBY1_9 -Djruby.compile.mode=OFF -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none

Here's an example of making a simple JRuby call without these flags:

time jruby -e 'puts "Hello, World!"'

real 0m1.170s
user 0m1.966s
sys 0m0.078s

Now I'll add these flags,

export JRUBY_OPTS="-Djruby.compat.version=RUBY1_9 -Djruby.compile.mode=OFF -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none"

and call the same script again:

time jruby -e 'puts "Hello, World!"'

real 0m0.090s
user 0m0.070s
sys 0m0.021s

That certainly speeds things up.

Now, I'll execute the generate-resources goal in Maven to invoke the Asciidoctor Maven plugin, first without any flags:

real 0m7.361s
user 0m14.733s
sys 0m0.297s

Now I'll add the flags. The only way I can figure out to pass these flags to JRuby is to set them as Maven options:

real 0m3.310s
user 0m4.537s
sys 0m0.260s

Voila! I think that will certainly save a lot of waiting :)

If anyone knows:

a. Flags that can make it go even faster
b. How to pass flags to JRuby w/o having to apply them to Maven globally

please let us know!

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Faster-JRuby-execution-tp130.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Faster-JRuby-execution-tp130p131.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
Hi,

thank you very much for this offer, I will write this information on asciidoctor-java-integration documentation and of course in a blog post, thank Dan for sharing this valuable information.

This week I will release all this information using asciidoctor-java-integration as example.

Cheers,
Alex.
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
In reply to this post by mojavelinux
For Ruby options there is a way: https://github.com/jruby/jruby/wiki/ConfiguringJRuby

Now I am finding for the -XX options. When I finish all my research I will update the project and write the blog.

Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
Wow!!! with only setting next properties programmatically:

RubyInstanceConfig config = new RubyInstanceConfig();  
config.setCompatVersion(CompatVersion.RUBY1_9);
config.setCompileMode(CompileMode.OFF);
Ruby rubyRuntime = JavaEmbedUtils.initialize(Collections.EMPTY_LIST, config);


Startup has improved from 5.5 seconds to 4.3 and rendering from 0.30 to 0.17. Cool improvement, I will continue researching on how to improve speed, and after that I will write a blog post about it.

OMG I have two articles about asciidoctor-java-integration pending to be written, really happy :D
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

LightGuardjp
Great work! Let's get this as fast as we can programmatically then tell them to go even faster they can modify java / maven startup with additional settings


On Mon, Apr 22, 2013 at 1:21 PM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Wow!!! with only setting next properties programmatically:

RubyInstanceConfig config = new RubyInstanceConfig();  
config.setCompatVersion(CompatVersion.RUBY1_9);
config.setCompileMode(CompileMode.OFF);
Ruby rubyRuntime = JavaEmbedUtils.initialize(Collections.EMPTY_LIST, config);


Startup has improved from 5.5 seconds to 4.3 and rendering from 0.30 to 0.17. Cool improvement, I will continue researching on how to improve speed, and after that I will write a blog post about it.

OMG I have two articles about asciidoctor-java-integration pending to be written, really happy :D


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Faster-JRuby-execution-tp130p155.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
Next step I will try to modify RUBY_OPTS before creating JRuby instance, and see what happens, maybe can be an approach for even faster execution
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
This afternoon I have been reading some interesting posts about speeding up jRuby when it is run embedded into JVM, I have arrived to next conclusions:

- some flags, mostly related with jRuby can be set programmatically. so DONE.
- some flags are related to JVM, and its version. (For example --client only in 32 bits JVM, or -XX:+TieredCompilation introduced in JDK7). PROBLEM.

In last case, this attributes are set using JRUBY_OPTS. So we have got two approaches, the first one, set and unset JRUBY_OPTS inside Asciidoctor java class before starting JRuby (it should work but I have not tried), or leave that responsibility to the user of the library. First approach has a big disadvantage, which of all flags we set? what's happening if let's say in JDK 8 an attribute is changed, ..., but of course user has not to worry about all these parameters.

The other approach, I think it is better because users will be able to set the parameters they think are the best one. (User knows version of JDK they are running Asciidoctor so can decide the best flags). But of course this require some knowledge that maybe he/she doesn't have it. But we can write a section in documentation with a table of options depending on JDK, so if user wants more speed can consult it and configure RUBY_OPTS properly.

What you think?
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

LightGuardjp
I'd suggest putting it up on the documentation section


On Tue, Apr 23, 2013 at 10:20 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
This afternoon I have been reading some interesting posts about speeding up jRuby when it is run embedded into JVM, I have arrived to next conclusions:

- some flags, mostly related with jRuby can be set programmatically. so DONE.
- some flags are related to JVM, and its version. (For example --client only in 32 bits JVM, or -XX:+TieredCompilation introduced in JDK7). PROBLEM.

In last case, this attributes are set using JRUBY_OPTS. So we have got two approaches, the first one, set and unset JRUBY_OPTS inside Asciidoctor java class before starting JRuby (it should work but I have not tried), or leave that responsibility to the user of the library. First approach has a big disadvantage, which of all flags we set? what's happening if let's say in JDK 8 an attribute is changed, ..., but of course user has not to worry about all these parameters.

The other approach, I think it is better because users will be able to set the parameters they think are the best one. (User knows version of JDK they are running Asciidoctor so can decide the best flags). But of course this require some knowledge that maybe he/she doesn't have it. But we can write a section in documentation with a table of options depending on JDK, so if user wants more speed can consult it and configure RUBY_OPTS properly.

What you think?


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Faster-JRuby-execution-tp130p159.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
+1 to add it in documentation.
Reply | Threaded
Open this post in threaded view
|

Re: Faster JRuby execution

asotobu
Pushed changes for improving startup performance as described in this post.