Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of JRuby performance optimization

Shulou Source: shulou.com Published: 2022-06-02 05:26:12 09月17日 Update

This article mainly explains "what are the JRuby performance optimization methods". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what JRuby performance optimization methods are.

1. Tuning the compiler

JRuby has long abandoned the secret to follow XRuby on the road of compiling this cow B, compiling Ruby Script into bytecode, so this link can not be ignored.

There are two compilation methods:

◆ AOT mode: directly generate class files, take off the skin of Ruby, we are everyone's "love" Java.

◆ JIT model: make full use of mature jit technology, we do not take off completely, hazy beauty is the real beauty. It is enabled by default from version 0.9.9.

Jruby-J-Djruby.jit.enabled=false

2. Close ObjectSpace

ObjectSpace is a module that Ruby uses to manipulate all run-time objects, which is quite awesome. The implementation of this is relatively easy in c ruby, but it is more expensive for JRuby. In fact, in most cases, you don't need it, so it's best to turn it off. JRuby provides

Jruby-J-Djruby.objectspace.enabled=false

Option to close it.

3. Open thread pool

We know that threads in c ruby are green lightweight threads, so the runtime is immobile with a hundred or so "threads" running around. However, in JRuby, the implementation of threads is a real native thread (that is, Ruby threads and Java threads are one to one). It is no wonder that you are so easy to move hundreds of threads. So JRuby provides a thread pool option to open threads as much as possible at run time, but when short-lived Ruby threads are created repeatedly, they will be reused, which improves performance in most cases, especially if one thread is started for each call. However, the specific effect is still the actual data to be tested.

Jruby-J-Djruby.thread.pooling=true

4. Use Java "server" mode virtual machine, which is a well-known JRuby performance optimization technique.

Jruby-J-server myscript.rb thank you for reading, these are the contents of "what are the JRuby performance optimization methods?" after the study of this article, I believe you have a deeper understanding of what JRuby performance optimization methods have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Thread performance method that is situation compilation mode learning running content short-lived mature expensive hazy shadowy practical next paragraph that is cost function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft MySQL vpn Apple