autotuner 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +13 -1
- data/lib/autotuner/heuristic/base.rb +1 -3
- data/lib/autotuner/heuristic/gc_compact.rb +9 -3
- data/lib/autotuner/heuristic/heap_size_warmup.rb +0 -2
- data/lib/autotuner/heuristic/malloc.rb +0 -2
- data/lib/autotuner/heuristic/oldmalloc.rb +0 -2
- data/lib/autotuner/heuristic/remembered_wb_unprotected_objects.rb +0 -2
- data/lib/autotuner/heuristics.rb +3 -3
- data/lib/autotuner/request_collector.rb +14 -6
- data/lib/autotuner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aa488d0dd08183c2fb01c791f8c6348161e5c986ac3a77d2e70b395823330aa
|
4
|
+
data.tar.gz: 205b668f35e3abe8c52bd0cd84438dad052efa9d26432ec86b19170f0c487e3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bc44e43c8851f850dfc542b9004ebdcb3f446036d0064947006815867bb9a4ad9502d2db0dd41fcfdebd68bf100d359a1537ed81b9e5147d936e0219a1fa8c5
|
7
|
+
data.tar.gz: 706cc7f127c5004e6dc8473531b5a305809e6eab762481b3f0bbf48571668bd807d2388e4d2a621d63bdb1e0ca5972848b61175707a3b01b13888bb0bee885ba
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -64,11 +64,23 @@ While autotuner aims to comprehensively analyze your traffic to give the suggest
|
|
64
64
|
## Configuration
|
65
65
|
|
66
66
|
- `Autotuner.enabled=`: (required, unless `Autotuner.sample_ratio` is set) Sets whether autotuner is enabled or not. When autotuner is disabled, data is not collected and suggestions are not given. Defaults to `false`.
|
67
|
-
- `Autotuner.sample_ratio=`: (optional) Sets the portion of instances where autotuner is enabled. Pass a value between 0 (enabled on no
|
67
|
+
- `Autotuner.sample_ratio=`: (optional) Sets the portion of instances where autotuner is enabled. Pass a value between 0 (enabled on no instances) and 1.0 (enabled on all instances). Note that this does not sample requests, but rather samples the portion of instances that have autotuner enabled (it will be enabled for all requests on those instances). Do not configure `Autotuner.enabled=` when you use this option.
|
68
68
|
- `Autotuner.reporter=`: (required) Callback called when a heuristic is ready to give a suggestion. The callback will be called with one argument which will be an instance of `Autotuner::Report::Base`. Call `#to_s` on this object to get a string containing instructions and recommendations. You must set this when autotuner is enabled.
|
69
69
|
- `Autotuner.debug_reporter=`: (optional) Callback to periodically emit debug messages of internal state of heuristics. The callback will be called with one argument which will be a hash with the heuristic name as the key and the debug message as the value. Regular users do not need to configure this as this is only useful for debugging purposes.
|
70
70
|
- `Autotuner.metrics_reporter=`: (optional) Callback to emit useful metrics about your service. The callback will be called with a hash containing the metric names (string) as the key and integer values.
|
71
71
|
|
72
|
+
## Emitted Metrics
|
73
|
+
|
74
|
+
The following metrics are passed to the `metrics_reporter` callback after each request.
|
75
|
+
|
76
|
+
| Name | Description |
|
77
|
+
| --------------------- | ----------- |
|
78
|
+
| `diff.time` | Time spent doing garbage collection during the request. Produced by [GC::stat](https://docs.ruby-lang.org/en/master/GC.html#method-c-stat) |
|
79
|
+
| `diff.minor_gc_count` | Number of minor garbage collections that occurred during the request. Produced by [GC::stat](https://docs.ruby-lang.org/en/master/GC.html#method-c-stat) |
|
80
|
+
| `diff.major_gc_count` | Number of major garbage collections that occurred during the request. Produced by [GC::stat](https://docs.ruby-lang.org/en/master/GC.html#method-c-stat) |
|
81
|
+
| `heap_pages` | Number of heap pages in use after the request. Produced by [GC::stat](https://docs.ruby-lang.org/en/master/GC.html#method-c-stat) |
|
82
|
+
| `request_time` | Total duration of the request. |
|
83
|
+
|
72
84
|
## Contributing
|
73
85
|
|
74
86
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/autotuner.
|
@@ -4,8 +4,6 @@ module Autotuner
|
|
4
4
|
module Heuristic
|
5
5
|
class GCCompact < Base
|
6
6
|
class << self
|
7
|
-
private
|
8
|
-
|
9
7
|
def supported?
|
10
8
|
true
|
11
9
|
end
|
@@ -41,10 +39,18 @@ module Autotuner
|
|
41
39
|
3.times { GC.start }
|
42
40
|
GC.compact
|
43
41
|
|
44
|
-
For example,
|
42
|
+
For example, with Puma, which runs its before fork hook once on boot (before the initial fork), add the following code into config/puma.rb:
|
43
|
+
|
44
|
+
before_fork do
|
45
|
+
3.times { GC.start }
|
46
|
+
GC.compact
|
47
|
+
end
|
48
|
+
|
49
|
+
With Unicorn, which runs its before fork hook before each fork, add the following code into config/unicorn.rb:
|
45
50
|
|
46
51
|
compacted = false
|
47
52
|
before_fork do
|
53
|
+
# avoid invalidating heap pages shared with previously forked children
|
48
54
|
unless compacted
|
49
55
|
3.times { GC.start }
|
50
56
|
GC.compact
|
data/lib/autotuner/heuristics.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
module Autotuner
|
4
4
|
module Heuristics
|
5
5
|
HEURISTICS = Heuristic::Base.subclasses.freeze
|
6
|
-
|
6
|
+
SUPPORTED_HEURISTICS = HEURISTICS.dup.keep_if(&:supported?).freeze
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def supported_heuristics
|
9
|
+
SUPPORTED_HEURISTICS
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,8 +5,6 @@ module Autotuner
|
|
5
5
|
HEURISTICS_POLLING_FREQUENCY = 100
|
6
6
|
DEBUG_EMIT_FREQUENCY = 1000
|
7
7
|
|
8
|
-
attr_reader :heuristics
|
9
|
-
|
10
8
|
def initialize
|
11
9
|
@request_count = 0
|
12
10
|
|
@@ -14,7 +12,7 @@ module Autotuner
|
|
14
12
|
|
15
13
|
@system_context = SystemContext.new
|
16
14
|
|
17
|
-
@heuristics = Autotuner.
|
15
|
+
@heuristics = Autotuner.supported_heuristics.map { |h| h.new(@system_context) }
|
18
16
|
end
|
19
17
|
|
20
18
|
def request
|
@@ -27,6 +25,16 @@ module Autotuner
|
|
27
25
|
|
28
26
|
private
|
29
27
|
|
28
|
+
def enabled_heuristics
|
29
|
+
Enumerator.new do |y|
|
30
|
+
@heuristics.each do |heuristic|
|
31
|
+
next unless heuristic.class.enabled?
|
32
|
+
|
33
|
+
y << heuristic
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
def before_request
|
31
39
|
@request_context.before_request
|
32
40
|
|
@@ -38,7 +46,7 @@ module Autotuner
|
|
38
46
|
|
39
47
|
@system_context.update(@request_context)
|
40
48
|
|
41
|
-
|
49
|
+
enabled_heuristics.each do |heuristic|
|
42
50
|
heuristic.call(@request_context)
|
43
51
|
end
|
44
52
|
|
@@ -48,7 +56,7 @@ module Autotuner
|
|
48
56
|
end
|
49
57
|
|
50
58
|
def emit_heuristic_reports
|
51
|
-
|
59
|
+
enabled_heuristics.each do |heuristic|
|
52
60
|
report = heuristic.tuning_report
|
53
61
|
|
54
62
|
next unless report
|
@@ -68,7 +76,7 @@ module Autotuner
|
|
68
76
|
system_context: @system_context.debug_state,
|
69
77
|
}
|
70
78
|
|
71
|
-
|
79
|
+
enabled_heuristics.each do |h|
|
72
80
|
debug_states[h.name] = h.debug_state
|
73
81
|
end
|
74
82
|
|
data/lib/autotuner/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autotuner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zhu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mocha
|