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 +4 -4
- data/lib/corn.rb +1 -4
- data/lib/corn/post.rb +3 -25
- data/lib/corn/profiler.rb +2 -3
- data/lib/corn/rack/slow_request_profiler.rb +3 -13
- metadata +4 -5
- data/lib/corn/reservoir_sampling.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7adcac6cd343ea4ceb786ec24182d90eeb416384
|
4
|
+
data.tar.gz: f94f2cd9f9c2eb685de12fce3473fe93ab1aaebb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c4a2a716cce0a5db01e713129e60023ac5627b1b4c592e1f47e896e9705c38434d7f8100bf8a5b216e073279c93f32e956438158e3a54bb8150c987f481b2ac
|
7
|
+
data.tar.gz: 90ab740aee78df5ffd2068b542bf303d09b1cbe2154f6285ad6e0d3fd0f3e680b1d2d11fd0e6d96acbdff6496fcdcc87886817866728b4c155eec42c1d8b06f4
|
data/lib/corn.rb
CHANGED
@@ -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
|
data/lib/corn/post.rb
CHANGED
@@ -5,12 +5,9 @@ require 'time'
|
|
5
5
|
|
6
6
|
module Corn
|
7
7
|
class Post
|
8
|
-
def initialize(interval
|
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
|
-
|
31
|
-
|
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
|
data/lib/corn/profiler.rb
CHANGED
@@ -3,9 +3,8 @@ require 'sampling_prof'
|
|
3
3
|
|
4
4
|
module Corn
|
5
5
|
class Profiler
|
6
|
-
def initialize(post_interval,
|
7
|
-
|
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
|
-
|
38
|
-
|
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
|
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-
|
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:
|
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
|