metriks 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,10 +2,7 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
- group :development do
6
- gem 'perftools.rb'
7
- end
8
-
9
5
  group :test do
10
- gem 'turn'
11
- end
6
+ gem 'turn', '0.8.2', :require => false
7
+ gem 'rake', '0.8.7'
8
+ end
@@ -1,6 +1,8 @@
1
1
 
2
2
  module Metriks::Reporter
3
3
  class Graphite
4
+ attr_reader :host, :port
5
+
4
6
  def initialize(host, port, options = {})
5
7
  @host = host
6
8
  @port = port
@@ -13,8 +15,8 @@ module Metriks::Reporter
13
15
  end
14
16
 
15
17
  def socket
16
- @socket = nil if @socket.closed?
17
- @socket ||= TCPSocket.new(host, port)
18
+ @socket = nil if @socket && @socket.closed?
19
+ @socket ||= TCPSocket.new(@host, @port)
18
20
  end
19
21
 
20
22
  def start
data/lib/metriks.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Metriks
3
- VERSION = '0.9.2'
3
+ VERSION = '0.9.3'
4
4
 
5
5
  def self.get(name)
6
6
  Metriks::Registry.default.get(name)
data/metriks.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'metriks'
16
- s.version = '0.9.2'
17
- s.date = '2012-03-06'
16
+ s.version = '0.9.3'
17
+ s.date = '2012-03-12'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
data/test/counter_test.rb CHANGED
@@ -3,6 +3,8 @@ require 'test_helper'
3
3
  require 'metriks/counter'
4
4
 
5
5
  class CounterTest < Test::Unit::TestCase
6
+ include ThreadHelper
7
+
6
8
  def setup
7
9
  @counter = Metriks::Counter.new
8
10
  end
@@ -13,9 +15,25 @@ class CounterTest < Test::Unit::TestCase
13
15
  assert_equal 1, @counter.count
14
16
  end
15
17
 
18
+ def test_increment_threaded
19
+ thread 10, :n => 100 do
20
+ @counter.increment
21
+ end
22
+
23
+ assert_equal 1000, @counter.count
24
+ end
25
+
16
26
  def test_increment_by_more
17
27
  @counter.increment 10
18
28
 
19
29
  assert_equal 10, @counter.count
20
30
  end
21
- end
31
+
32
+ def test_increment_by_more_threaded
33
+ thread 10, :n => 100 do
34
+ @counter.increment 10
35
+ end
36
+
37
+ assert_equal 10000, @counter.count
38
+ end
39
+ end
@@ -3,6 +3,8 @@ require 'test_helper'
3
3
  require 'metriks/histogram'
4
4
 
5
5
  class HistogramTest < Test::Unit::TestCase
6
+ include ThreadHelper
7
+
6
8
  def setup
7
9
  end
8
10
 
@@ -33,6 +35,17 @@ class HistogramTest < Test::Unit::TestCase
33
35
  assert_equal 7, @histogram.mean
34
36
  end
35
37
 
38
+ def test_uniform_sample_mean_threaded
39
+ @histogram = Metriks::Histogram.new(Metriks::UniformSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE))
40
+
41
+ thread 10, :n => 100 do
42
+ @histogram.update(5)
43
+ @histogram.update(10)
44
+ end
45
+
46
+ assert_equal 7, @histogram.mean
47
+ end
48
+
36
49
  def test_uniform_sample_2000
37
50
  @histogram = Metriks::Histogram.new(Metriks::UniformSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE))
38
51
 
@@ -42,6 +55,21 @@ class HistogramTest < Test::Unit::TestCase
42
55
 
43
56
  assert_equal 1999, @histogram.max
44
57
  end
58
+
59
+ def test_uniform_sample_2000_threaded
60
+ @histogram = Metriks::Histogram.new(Metriks::UniformSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE))
61
+
62
+ t = 10
63
+ thread t do |i|
64
+ 2000.times do |x|
65
+ if (x % t) == i
66
+ @histogram.update x
67
+ end
68
+ end
69
+ end
70
+
71
+ assert_equal 1999, @histogram.max
72
+ end
45
73
 
46
74
  def test_uniform_sample_snashot
47
75
  @histogram = Metriks::Histogram.new(Metriks::UniformSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE))
@@ -55,6 +83,20 @@ class HistogramTest < Test::Unit::TestCase
55
83
  assert_equal 49.5, snapshot.median
56
84
  end
57
85
 
86
+ def test_uniform_sample_snapshot_threaded
87
+ @histogram = Metriks::Histogram.new(Metriks::UniformSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE))
88
+
89
+ thread 10 do
90
+ 100.times do |idx|
91
+ @histogram.update(idx)
92
+ end
93
+ end
94
+
95
+ snapshot = @histogram.snapshot
96
+
97
+ assert_equal 49.5, snapshot.median
98
+ end
99
+
58
100
  def test_exponential_sample_min
59
101
  @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
60
102
 
@@ -63,7 +105,7 @@ class HistogramTest < Test::Unit::TestCase
63
105
 
64
106
  assert_equal 5, @histogram.min
65
107
  end
66
-
108
+
67
109
  def test_exponential_sample_max
68
110
  @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
69
111
 
@@ -81,6 +123,17 @@ class HistogramTest < Test::Unit::TestCase
81
123
 
82
124
  assert_equal 7, @histogram.mean
83
125
  end
126
+
127
+ def test_exponential_sample_mean_threaded
128
+ @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
129
+
130
+ thread 10, :n => 100 do
131
+ @histogram.update(5)
132
+ @histogram.update(10)
133
+ end
134
+
135
+ assert_equal 7, @histogram.mean
136
+ end
84
137
 
85
138
  def test_exponential_sample_2000
86
139
  @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
@@ -91,6 +144,21 @@ class HistogramTest < Test::Unit::TestCase
91
144
 
92
145
  assert_equal 1999, @histogram.max
93
146
  end
147
+
148
+ def test_exponential_sample_2000_threaded
149
+ @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
150
+
151
+ t = 10
152
+ thread t do |i|
153
+ 2000.times do |idx|
154
+ if (idx % t) == i
155
+ @histogram.update(idx)
156
+ end
157
+ end
158
+ end
159
+
160
+ assert_equal 1999, @histogram.max
161
+ end
94
162
 
95
163
  def test_exponential_sample_snashot
96
164
  @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
@@ -104,4 +172,17 @@ class HistogramTest < Test::Unit::TestCase
104
172
  assert_equal 49.5, snapshot.median
105
173
  end
106
174
 
107
- end
175
+ def test_exponential_sample_snapshot_threaded
176
+ @histogram = Metriks::Histogram.new(Metriks::ExponentiallyDecayingSample.new(Metriks::Histogram::DEFAULT_SAMPLE_SIZE, Metriks::Histogram::DEFAULT_ALPHA))
177
+
178
+ thread 10 do
179
+ 100.times do |idx|
180
+ @histogram.update(idx)
181
+ end
182
+ end
183
+
184
+ snapshot = @histogram.snapshot
185
+
186
+ assert_equal 49.5, snapshot.median
187
+ end
188
+ end
data/test/meter_test.rb CHANGED
@@ -3,6 +3,8 @@ require 'test_helper'
3
3
  require 'metriks/meter'
4
4
 
5
5
  class MeterTest < Test::Unit::TestCase
6
+ include ThreadHelper
7
+
6
8
  def setup
7
9
  @meter = Metriks::Meter.new
8
10
  end
@@ -17,6 +19,14 @@ class MeterTest < Test::Unit::TestCase
17
19
  assert_equal 1, @meter.count
18
20
  end
19
21
 
22
+ def test_meter_threaded
23
+ thread 10, :n => 100 do
24
+ @meter.mark
25
+ end
26
+
27
+ assert_equal 1000, @meter.count
28
+ end
29
+
20
30
  def test_one_minute_rate
21
31
  @meter.mark 1000
22
32
 
@@ -25,4 +35,4 @@ class MeterTest < Test::Unit::TestCase
25
35
 
26
36
  assert_equal 200, @meter.one_minute_rate
27
37
  end
28
- end
38
+ end
data/test/test_helper.rb CHANGED
@@ -7,3 +7,28 @@ require 'mocha'
7
7
  require 'metriks'
8
8
 
9
9
  Thread.abort_on_exception = true
10
+
11
+ module ThreadHelper
12
+ require 'thread'
13
+
14
+ # Run the given block on n threads in parallel. Returns an array of the
15
+ # return values of each thread's last invocation of block. Options:
16
+
17
+ # :n: call block n times per thread. Default 1.
18
+ def thread(threads = 2, opts = {})
19
+ n = opts[:n] || 1
20
+ results = []
21
+
22
+ threads.times.map do |i|
23
+ Thread.new do
24
+ n.times do
25
+ results[i] = yield i
26
+ end
27
+ end
28
+ end.each do |thread|
29
+ thread.join
30
+ end
31
+
32
+ results
33
+ end
34
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 2
9
- version: 0.9.2
8
+ - 3
9
+ version: 0.9.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eric Lindvall
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-03-06 00:00:00 -08:00
17
+ date: 2012-03-12 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency