corn 0.5.7.beta1 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cd2ed0bc9b102eca18ed7e80ea7a9313702fc02
4
- data.tar.gz: 6ce6d074da698b05112110f83635b497f8453735
3
+ metadata.gz: 7adcac6cd343ea4ceb786ec24182d90eeb416384
4
+ data.tar.gz: f94f2cd9f9c2eb685de12fce3473fe93ab1aaebb
5
5
  SHA512:
6
- metadata.gz: 07ad76f726b438be79b29f51144c913fd1f413abbd221c2c0beff3c9453db7a439441de4080bc4ebb111c330ef5c6c7f727709f8605b0aeca26925f3920eb22e
7
- data.tar.gz: 5d216ec62d5c8d3ccc111d7aee67b3740a3b1c4899023479ed725b27fe3855fd6c27afbaa8322d673d321c28d94471aa2590a65592532d190ad96ce84e6311d6
6
+ metadata.gz: 9c4a2a716cce0a5db01e713129e60023ac5627b1b4c592e1f47e896e9705c38434d7f8100bf8a5b216e073279c93f32e956438158e3a54bb8150c987f481b2ac
7
+ data.tar.gz: 90ab740aee78df5ffd2068b542bf303d09b1cbe2154f6285ad6e0d3fd0f3e680b1d2d11fd0e6d96acbdff6496fcdcc87886817866728b4c155eec42c1d8b06f4
@@ -33,12 +33,9 @@ module Corn
33
33
  :rack_middleware => Rack::SlowRequestProfiler,
34
34
  :rack_slow_request_profiler => Rack::SlowRequestProfiler,
35
35
  :slow_request_threshold => 5,
36
- :fast_request_threshold => lambda { [Corn.sampling_interval * 5, Corn.slow_request_threshold.to_f / 5].max },
37
36
  :profiling => true,
38
37
  :sampling_interval => 0.1,
39
- :post_interval => 2,
40
- :post_fast_request_interval => 60, #seconds
41
- :fast_request_sampling_limit => 1024 * 1024 * 2 #2MB
38
+ :post_interval => 2
42
39
  })
43
40
 
44
41
  module_function
@@ -5,12 +5,9 @@ require 'time'
5
5
 
6
6
  module Corn
7
7
  class Post
8
- def initialize(interval, sampling_limit, sampling_time)
8
+ def initialize(interval)
9
9
  @queue = Queue.new
10
10
  @thread = start_post_thread(interval)
11
- @sampling_limit = sampling_limit
12
- @sampling_time = sampling_time
13
- reset_sampling
14
11
  end
15
12
 
16
13
  def terminate
@@ -27,21 +24,8 @@ module Corn
27
24
  Thread.start do
28
25
  begin
29
26
  loop do
30
- d = @queue.pop
31
- case d[:action]
32
- when :post
33
- http_post([d])
34
- sleep interval
35
- when :sampling
36
- @sampling << d
37
- if Time.now - @sampling_start > @sampling_time
38
- http_post(@sampling.items, :sampling)
39
- reset_sampling
40
- sleep interval
41
- end
42
- else
43
- Corn.logger.info("Corn: Ignore unknown action: #{d[:action]}")
44
- end
27
+ http_post([@queue.pop])
28
+ sleep interval
45
29
  end
46
30
  rescue => e
47
31
  Corn.logger.error("Corn post thread stopped by error #{e.message}\n#{e.backtrace.join("\n")}")
@@ -93,11 +77,5 @@ module Corn
93
77
  def submit_url
94
78
  Corn.submit_url
95
79
  end
96
-
97
- private
98
- def reset_sampling
99
- @sampling = ReservoirSampling.new(@sampling_limit)
100
- @sampling_start = Time.now
101
- end
102
80
  end
103
81
  end
@@ -3,9 +3,8 @@ require 'sampling_prof'
3
3
 
4
4
  module Corn
5
5
  class Profiler
6
- def initialize(post_interval, post_sampling_limit, post_sampling_time,
7
- sampling_interval)
8
- @post = Post.new(post_interval, post_sampling_limit, post_sampling_time)
6
+ def initialize(post_interval, sampling_interval)
7
+ @post = Post.new(post_interval)
9
8
  @prof = SamplingProf.new(sampling_interval)
10
9
  at_exit { terminate }
11
10
  end
@@ -1,6 +1,5 @@
1
1
  require 'thread'
2
2
  require 'corn/profiler'
3
- require 'corn/reservoir_sampling'
4
3
  require 'corn/rack/request_env'
5
4
 
6
5
  module Corn
@@ -8,10 +7,7 @@ module Corn
8
7
  class SlowRequestProfiler
9
8
  class ProfilingApp
10
9
  def initialize(app)
11
- @@prof ||= Profiler.new(Corn.post_interval,
12
- Corn.fast_request_sampling_limit,
13
- Corn.post_fast_request_interval,
14
- Corn.sampling_interval)
10
+ @@prof ||= Profiler.new(Corn.post_interval, Corn.sampling_interval)
15
11
  @app = app
16
12
 
17
13
  Corn.logger.info("Corn sampling interval: #{Corn.sampling_interval}")
@@ -34,17 +30,11 @@ module Corn
34
30
  def output_handler(env)
35
31
  request_env = RequestEnv.new(env)
36
32
  lambda do |data|
37
- t = request_env.time
38
- if t < fast_request_threshold || t > slow_request_threshold
39
- action = t > Corn.slow_request_threshold ? :post : :sampling
40
- request_env.to_report.merge(:data => data, :action => action)
33
+ if request_env.time > slow_request_threshold
34
+ request_env.to_report.merge(:data => data)
41
35
  end
42
36
  end
43
37
  end
44
-
45
- def fast_request_threshold
46
- @frt ||= Corn.fast_request_threshold
47
- end
48
38
  def slow_request_threshold
49
39
  @srt ||= Corn.slow_request_threshold
50
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7.beta1
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sampling_prof
@@ -38,7 +38,6 @@ files:
38
38
  - lib/corn/post.rb
39
39
  - lib/corn/profiler.rb
40
40
  - lib/corn/rack.rb
41
- - lib/corn/reservoir_sampling.rb
42
41
  - lib/corn/rack/request_env.rb
43
42
  - lib/corn/rack/slow_request_profiler.rb
44
43
  - lib/generators/corn/config/config_generator.rb
@@ -57,9 +56,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
56
  version: '0'
58
57
  required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  requirements:
60
- - - '>'
59
+ - - '>='
61
60
  - !ruby/object:Gem::Version
62
- version: 1.3.1
61
+ version: '0'
63
62
  requirements: []
64
63
  rubyforge_project:
65
64
  rubygems_version: 2.1.9
@@ -1,29 +0,0 @@
1
- module Corn
2
- class ReservoirSampling
3
- attr_reader :items
4
- def initialize(limit)
5
- @limit = limit
6
- @items = []
7
- @size = -1
8
- @count = 0
9
- end
10
-
11
- def <<(item)
12
- @count += 1
13
- if @size < 0 && bytesize < @limit
14
- items << item
15
- else
16
- @size = items.size
17
- j = rand(@count).to_i
18
- if j < @size
19
- items[j] = item
20
- end
21
- end
22
- end
23
-
24
- private
25
- def bytesize
26
- items.map{|d|d[:data].bytesize}.reduce(:+) || 0
27
- end
28
- end
29
- end