rack_gc_profiler 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +10 -0
- data/benchmark.rb +39 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rack_gc_profiler.rb +34 -0
- data/lib/rack_gc_profiler/version.rb +3 -0
- data/rack_gc_profiler.gemspec +28 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 818e9a84a8736d7b598e63481606c1770f7cb98e
|
4
|
+
data.tar.gz: 08e73c92b9b8214b3197d19a448ef548e4dae748
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39bbb305043682bdbdde9d324e30c54d3684b6b62a35622c1aabc194ae944b35b347e840b30f9fa9a00f36fff753d5bd388ad423f65c3d639631c41ba19ad7db
|
7
|
+
data.tar.gz: 75dc3674db310a724c17ba2cba0fba91b6b37af16979ce6ca5901be722e559397910a6c16a22cf07819aea59f30b1d156a34c640e1cecc4df4974bc95dfbc078
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Andrew A Smith
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# RackGcProfiler
|
2
|
+
|
3
|
+
A rack middleware for measuring GC activity during a request.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack_gc_profiler'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rack_gc_profiler
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Install the middleware into your application's list of rack middlewares.
|
24
|
+
|
25
|
+
Issue a request to your application where GC will occur. Two extra headers will
|
26
|
+
be appended to the response:
|
27
|
+
|
28
|
+
```console
|
29
|
+
$ curl -v -o /dev/null -sSq yourapp.example.com
|
30
|
+
< HTTP/1.1 200 OK
|
31
|
+
:
|
32
|
+
< GC-Runs: 1
|
33
|
+
< GC-Time: 0.040000
|
34
|
+
:
|
35
|
+
{ [1219 bytes data]
|
36
|
+
* Connection #0 to host yourapp.example.com left intact
|
37
|
+
```
|
38
|
+
|
39
|
+
`GC-Runs` is the number of times garbage collection ran during the request.
|
40
|
+
`GC-Time` is the duration of all the GC runs that occured, in seconds.
|
41
|
+
|
42
|
+
### Production Usage
|
43
|
+
|
44
|
+
Should you use this in production? Profiling anything always adds overhead. To
|
45
|
+
measure this more concretely, a benchmark has been provided. See benchmark.rb in
|
46
|
+
the root of the repo. On my machine, using MRI 2.3.1, GC profiling added 0.6%
|
47
|
+
overhead. This equates to about 0.1ms on a 200ms request. Always evaluate in
|
48
|
+
your own production environment first and decide for yourself before adding this
|
49
|
+
to a production application.
|
50
|
+
|
51
|
+
To prevent information leakage, the reverse proxy upstream from your
|
52
|
+
application server should log and delete the two headers listed in the section
|
53
|
+
above.
|
54
|
+
|
55
|
+
### Rails
|
56
|
+
|
57
|
+
To install in rails, add the following to your `application.rb`:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
config.middleware.use RackGcProfiler::Middleware
|
61
|
+
```
|
62
|
+
|
63
|
+
See http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack
|
64
|
+
for more details.
|
65
|
+
|
66
|
+
### Sinatra
|
67
|
+
|
68
|
+
To install in sinatra, add the following to your application:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
use RackGcProfiler::Middleware
|
72
|
+
```
|
73
|
+
|
74
|
+
See http://www.sinatrarb.com/intro#Rack%20Middleware for more details.
|
75
|
+
|
76
|
+
|
77
|
+
## Development
|
78
|
+
|
79
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
80
|
+
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aasmith/rack_gc_profiler.
|
86
|
+
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/benchmark.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
def busywork
|
4
|
+
GC.disable
|
5
|
+
100_000.times do |i|
|
6
|
+
Object.new
|
7
|
+
|
8
|
+
if i % 10_000 == 0
|
9
|
+
GC.enable
|
10
|
+
GC.start
|
11
|
+
GC.disable
|
12
|
+
end
|
13
|
+
end
|
14
|
+
GC.enable
|
15
|
+
end
|
16
|
+
|
17
|
+
def busywork_with_profiling
|
18
|
+
GC::Profiler.enable
|
19
|
+
busywork
|
20
|
+
GC::Profiler.disable
|
21
|
+
GC::Profiler.clear
|
22
|
+
end
|
23
|
+
|
24
|
+
N = 1_000
|
25
|
+
|
26
|
+
Benchmark.bmbm do |bm|
|
27
|
+
bm.report 'GC Profile' do
|
28
|
+
N.times do
|
29
|
+
busywork_with_profiling
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
bm.report 'No Profile' do
|
34
|
+
N.times do
|
35
|
+
busywork
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack_gc_profiler"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rack_gc_profiler/version"
|
2
|
+
|
3
|
+
module RackGcProfiler
|
4
|
+
class Middleware
|
5
|
+
|
6
|
+
GC_TIME_FORMAT = "%0.6f".freeze
|
7
|
+
GC_TIME_HEADER = "GC-Time".freeze
|
8
|
+
GC_RUNS_HEADER = "GC-Runs".freeze
|
9
|
+
|
10
|
+
attr_reader :profiler
|
11
|
+
|
12
|
+
def initialize(app, profiler = GC::Profiler)
|
13
|
+
@app = app
|
14
|
+
@profiler = profiler
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@profiler.enable
|
19
|
+
|
20
|
+
status, headers, body = @app.call(env)
|
21
|
+
|
22
|
+
headers[GC_TIME_HEADER] = GC_TIME_FORMAT % @profiler.total_time
|
23
|
+
headers[GC_RUNS_HEADER] = @profiler.raw_data.size.to_s
|
24
|
+
|
25
|
+
[status, headers, body]
|
26
|
+
|
27
|
+
ensure
|
28
|
+
@profiler.disable
|
29
|
+
@profiler.clear
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack_gc_profiler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack_gc_profiler"
|
8
|
+
spec.version = RackGcProfiler::VERSION
|
9
|
+
spec.authors = ["Andrew A Smith"]
|
10
|
+
spec.email = ["andy@tinnedfruit.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{A rack middleware for measuring GC activity during a request.}
|
13
|
+
spec.homepage = "http://github.com/aasmith/rack_gc_profiler"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
|
27
|
+
spec.add_dependency "rack", "~> 1.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack_gc_profiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew A Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- andy@tinnedfruit.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- benchmark.rb
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/rack_gc_profiler.rb
|
86
|
+
- lib/rack_gc_profiler/version.rb
|
87
|
+
- rack_gc_profiler.gemspec
|
88
|
+
homepage: http://github.com/aasmith/rack_gc_profiler
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.5.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A rack middleware for measuring GC activity during a request.
|
112
|
+
test_files: []
|