corn 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/corn/config.rb +2 -1
- data/lib/corn/post.rb +2 -2
- data/lib/corn/rack/slow_request_profiler.rb +19 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a48acabdb1beaeceb6915bca571c759409f21812
|
4
|
+
data.tar.gz: f046e870baf89b719f4c4de7865ad8212f25e82f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b0f65086ebb697d15394f7c85df9e2b198c1d38ca4379dd5b79ee2c72894c67243f0feea02672db994f05734e37ef9ecaf1a12f77c5b3e4366623afa2488cf
|
7
|
+
data.tar.gz: b8a35e2f0d5c829b51db9f0b8cdcb2b0d98f0839d988447d557dc98f440238718f6d9976ff6fe12eb4a587cbc66b41d9d29850fc02555e88dd3b240eacf4ce72
|
data/lib/corn/config.rb
CHANGED
data/lib/corn/post.rb
CHANGED
@@ -15,8 +15,8 @@ module Corn
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def start_post_thread(interval)
|
18
|
-
if interval
|
19
|
-
Corn.logger.info("Corn post interval
|
18
|
+
if interval <= 0
|
19
|
+
Corn.logger.info("Corn post interval <= 0 sec, change it to 1 sec")
|
20
20
|
interval = 1
|
21
21
|
else
|
22
22
|
Corn.logger.info("Corn post interval #{interval} sec(s)")
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'corn/config'
|
1
2
|
require 'corn/post'
|
2
3
|
require 'corn/rack/request_env'
|
3
4
|
require 'sampling_prof'
|
@@ -5,21 +6,27 @@ require 'sampling_prof'
|
|
5
6
|
module Corn
|
6
7
|
module Rack
|
7
8
|
class SlowRequestProfiler
|
9
|
+
include Config
|
10
|
+
config(:profiling => true,
|
11
|
+
:slow_request_threshold => 5,
|
12
|
+
:sampling_interval => 0.1,
|
13
|
+
:post_interval => 2)
|
14
|
+
|
8
15
|
class ProfilingApp
|
9
|
-
def initialize(app,
|
10
|
-
slow_request_threshold=5,
|
11
|
-
sampling_interval=0.1,
|
12
|
-
post_interval=2)
|
16
|
+
def initialize(app, config)
|
13
17
|
@app = app
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@prof = SamplingProf.new(@sampling_interval)
|
18
|
+
@config = config
|
19
|
+
@post = Post.new(config.post_interval)
|
20
|
+
@prof = SamplingProf.new(config.sampling_interval)
|
18
21
|
at_exit { terminate }
|
19
22
|
end
|
20
23
|
|
21
24
|
def call(env)
|
22
|
-
|
25
|
+
if @config.profiling?
|
26
|
+
@prof.profile(output_handler(env)) { @app.call(env) }
|
27
|
+
else
|
28
|
+
@app.call(env)
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
def terminate
|
@@ -30,15 +37,15 @@ module Corn
|
|
30
37
|
def output_handler(env)
|
31
38
|
request_env = RequestEnv.new(env)
|
32
39
|
lambda do |data|
|
33
|
-
if request_env.time > @slow_request_threshold
|
40
|
+
if request_env.time > @config.slow_request_threshold
|
34
41
|
@post.enqueue(request_env.to_report.merge("data" => data))
|
35
42
|
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
39
46
|
|
40
|
-
def initialize(app
|
41
|
-
@app = Corn.configured? ? ProfilingApp.new(app,
|
47
|
+
def initialize(app)
|
48
|
+
@app = Corn.configured? ? ProfilingApp.new(app, self.class) : app
|
42
49
|
end
|
43
50
|
|
44
51
|
def call(env)
|