-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obtaining and releasing a Mutex lock on JRuby 9000 is 5 times slower than on MRI. #3255
Comments
I don't see that here:
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.51-b03 on 1.8.0_51-b16 +jit [FreeBSD-amd64]
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-freebsd10.2]
|
The problem is there - it's just hidden by another layer of the interpreter that let's it speed up when the same short piece of code repeats itself. In other words: the difference shrinks with repetitive operations (interpreter own code optimization perhaps?), but would be heavily experienced in a real life application. Allow me to demonstrate this change using the following benchmarks. Please observe how the results in MRI are consistent factors of 10, whereas the results in JRuby improve with each time the repetition increase and do not represent a consistent factor. Also, you will get different results if you repeat the test (unless you restart jirb), since optimization already took place. Here are the results on my machine (MacBook Pro 2.5 GHz Intel Core i7): require 'benchmark'
require 'benchmark/ips'
def test_both
l = Mutex.new
Benchmark.bm do |b|
b.report('non-ips 10K') { 10_000.times { l.synchronize { true } unless l.locked? } }
b.report('non-ips 100K') { 100_000.times { l.synchronize { true } unless l.locked? } }
b.report('non-ips 1M') { 1_000_000.times { l.synchronize { true } unless l.locked? } }
end
l = Mutex.new
Benchmark.ips do |b|
b.report('ips-report') { l.synchronize { true } unless l.locked? }
end
nil
end
test_both JRuby 9000
ruby 2.2.2p95
|
Yep, that's the JIT warming up. It takes time for JRuby and the JVM to reach steady-state - basically everything starts off interpreted, and it compiles stuff as it goes along if it feels the need to. The price we pay for that is ropey startup performance with just about anything. Using 2.2.2p95:
9.0.0.0:
If you replace Mutex with a stub class like:
You'll find you get basically identical behaviour. |
Seems to be my bad.... sorry. Thank you for your time. |
Obtaining and releasing a Mutex lock on JRuby 9000 is 5 times slower than on MRI.
This is an important issue, especially considering that JRuby's advantage is the lack of a GIL, which allows true multithreading.
replicating the issue
The text was updated successfully, but these errors were encountered: