Skip to content

Commit

Permalink
Bump up avl_gem and use ConcurrentRedBlackTree
Browse files Browse the repository at this point in the history
It's slightly slower according to benchmark we have for samplers but
we get thread safety.

```
    ~/projects/metriks concurrent-redbacktree * be ruby ./benchmark/samplers.rb
    Resolving dependencies...
    The Gemfile's dependencies are satisfied
    fib(10): 100000 iterations
    --------------------------------------------------
                      plain: 0.863473 secs 0.000009 secs/call
                    uniform: 2.034218 secs 0.000020 secs/call
                              - 135.6% slower than plain (0.000012 secs/call)
            exponential_avl: 2.227544 secs 0.000022 secs/call
                              - 9.5% slower than uniform (0.000002 secs/call)
                              - 158.0% slower than plain (0.000014 secs/call)
      exponential_red_black: 2.273125 secs 0.000023 secs/call
                              - 2.0% slower than exponential_avl (0.000000 secs/call)
                              - 163.3% slower than plain (0.000014 secs/call)
    exponential_concurrent_red_black: 2.433853 secs 0.000024 secs/call
                              - 7.1% slower than exponential_red_black (0.000002 secs/call)
                              - 181.9% slower than plain (0.000016 secs/call)
```
  • Loading branch information
lukaszx0 committed Sep 30, 2014
1 parent b3ba1a8 commit e083aa4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions benchmark/samplers.rb
Expand Up @@ -86,6 +86,9 @@ def fib(n)
reporter.measure :exponential_red_black, Metriks::Timer.new(Metriks::ExponentiallyDecayingSample.new(
Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA, RedBlackTree.new))

reporter.measure :exponential_concurrent_red_black, Metriks::Timer.new(Metriks::ExponentiallyDecayingSample.new(
Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA, ConcurrentRedBlackTree.new))

puts "fib(#{fib_times}): #{iter} iterations"
puts "-" * 50

Expand Down
2 changes: 1 addition & 1 deletion lib/metriks/exponentially_decaying_sample.rb
Expand Up @@ -7,7 +7,7 @@ class ExponentiallyDecayingSample
RESCALE_THRESHOLD = 60 * 60 # 1 hour

def initialize(reservoir_size, alpha, values = nil)
@values = values || RedBlackTree.new
@values = values || ConcurrentRedBlackTree.new
@count = Atomic.new(0)
@next_scale_time = Atomic.new(0)
@alpha = alpha
Expand Down
2 changes: 1 addition & 1 deletion metriks.gemspec
Expand Up @@ -41,7 +41,7 @@ Gem::Specification.new do |s|
## that are needed for an end user to actually USE your code.
s.add_dependency('atomic', ["~> 1.0"])
s.add_dependency('hitimes', [ "~> 1.1"])
s.add_dependency('avl_tree', [ "~> 1.1.2" ])
s.add_dependency('avl_tree', [ "~> 1.2.0" ])

## List your development dependencies here. Development dependencies are
## those that are only needed during development
Expand Down

0 comments on commit e083aa4

Please sign in to comment.