Skip to content
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

Faster implementation of monitor than standard library #2645

Closed
ganmacs opened this issue Oct 9, 2019 · 8 comments · Fixed by #2670
Closed

Faster implementation of monitor than standard library #2645

ganmacs opened this issue Oct 9, 2019 · 8 comments · Fixed by #2670
Assignees
Labels
enhancement Feature request or improve operations

Comments

@ganmacs
Copy link
Member

ganmacs commented Oct 9, 2019

I'll try https://github.com/nurse/ext_monitor

cc. @nurse

@ganmacs ganmacs self-assigned this Oct 9, 2019
@repeatedly
Copy link
Member

Why this issue on this repository?

@ganmacs ganmacs transferred this issue from fluent/fluent-plugin-kafka Oct 10, 2019
@ganmacs
Copy link
Member Author

ganmacs commented Oct 10, 2019

oh… I made a mistake… transfered to fluent/fluentd.

@repeatedly
Copy link
Member

Here is my benchmark result of #2561
Monitor#synchronize is still slower...

- ruby 2.6.3

Warming up --------------------------------------
             monitor   184.967k i/100ms
               mutex   289.882k i/100ms
Calculating -------------------------------------
             monitor      3.287M (± 2.2%) i/s -     16.462M in   5.011436s
               mutex      8.005M (± 1.6%) i/s -     40.294M in   5.034949s

- ruby 2.6.5
Warming up --------------------------------------
             monitor    56.806k i/100ms
               mutex   280.742k i/100ms
Calculating -------------------------------------
             monitor    678.492k (± 4.7%) i/s -      3.408M in   5.035571s
               mutex      8.054M (± 2.4%) i/s -     40.427M in   5.022535s

- ruby 2.6.5 with ext_monitor
Warming up --------------------------------------
             monitor    62.786k i/100ms
               mutex   292.756k i/100ms
Calculating -------------------------------------
             monitor    754.165k (± 2.2%) i/s -      3.830M in   5.080977s
               mutex      8.031M (± 1.4%) i/s -     40.400M in   5.031691s

@ganmacs
Copy link
Member Author

ganmacs commented Oct 28, 2019

For my understanding, this gem is a faster version of the exising Monitor class, not Mutex class.
So we should compare Monitor library ruby provides and this gem.

require 'benchmark/ips'
# require 'ext_monitor'

mo = Monitor.new
mu = Mutex.new

p "Ruby #{RUBY_VERSION}"

Benchmark.ips do |x|
  x.report("monitor") do
    mo.synchronize {}
  end

  x.report("mutex") do
    mu.synchronize {}
  end
end

with ext_monitor

"Ruby 2.5.5"
Warming up --------------------------------------
             monitor   266.565k i/100ms
               mutex   351.016k i/100ms
Calculating -------------------------------------
             monitor      4.937M (± 4.7%) i/s -     24.791M in   5.036034s
               mutex      7.851M (± 4.7%) i/s -     39.314M in   5.018843s

without ext_monitor (commented out)

"Ruby 2.5.5"
Warming up --------------------------------------
             monitor   228.634k i/100ms
               mutex   347.341k i/100ms
Calculating -------------------------------------
             monitor      3.797M (± 2.1%) i/s -     18.977M in   5.000240s
               mutex      8.139M (± 1.8%) i/s -     40.986M in   5.037270s

@repeatedly
Copy link
Member

Yes, but the problem is ruby 2.6.4 and later has slower Monitor.
See my benchmark result. ruby 2.6.5 with ext_monitor is still very slower than ruby 2.6.3 without ext_monitor.

@ganmacs
Copy link
Member Author

ganmacs commented Oct 28, 2019

ah, my bad. You already compared them...
The benchmark running on my local MacBook results in a similar one to yours (around 838.033k even if using ext_monitor).

@nurse
Copy link
Contributor

nurse commented Oct 28, 2019

Thank you for testing. I found a bug and fixed and released v0.1.1: https://rubygems.org/gems/ext_monitor/versions/0.1.1

@ganmacs
Copy link
Member Author

ganmacs commented Oct 28, 2019

Great 👏 thanks.

with ext_monitor (2x faster)

"Ruby 2.6.3"
Warming up --------------------------------------
             monitor   327.029k i/100ms
               mutex   362.710k i/100ms
Calculating -------------------------------------
             monitor      7.507M (± 2.4%) i/s -     37.608M in   5.012856s
               mutex     10.517M (± 2.5%) i/s -     52.593M in   5.004291s

without ext_monitor

"Ruby 2.6.3"
Warming up --------------------------------------
             monitor   230.079k i/100ms
               mutex   364.688k i/100ms
Calculating -------------------------------------
             monitor      3.781M (± 4.7%) i/s -     18.866M in   5.000347s
               mutex      9.479M (± 5.1%) i/s -     47.409M in   5.014644s

with ext_monitor(10x faster)

"Ruby 2.6.5"
Warming up --------------------------------------
             monitor   333.879k i/100ms
               mutex   377.950k i/100ms
Calculating -------------------------------------
             monitor      8.036M (± 3.1%) i/s -     40.399M in   5.033352s
               mutex     10.204M (± 3.9%) i/s -     51.023M in   5.008424s

without ext_monitor

"Ruby 2.6.5"
Warming up --------------------------------------
             monitor    73.338k i/100ms
               mutex   385.539k i/100ms
Calculating -------------------------------------
             monitor    892.246k (± 5.1%) i/s -      4.474M in   5.028408s
               mutex     10.528M (± 2.6%) i/s -     52.819M in   5.020783s

@ganmacs ganmacs added the enhancement Feature request or improve operations label Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improve operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants