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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 511df4fa38774e70c89c66a4d3692098537189c2281851896327ce7b7df6fc05
4
- data.tar.gz: b97736b7e50e47753c0f487a37e32fd7fc3d3869ab50e6197cea4894978f7208
3
+ metadata.gz: 6aa488d0dd08183c2fb01c791f8c6348161e5c986ac3a77d2e70b395823330aa
4
+ data.tar.gz: 205b668f35e3abe8c52bd0cd84438dad052efa9d26432ec86b19170f0c487e3c
5
5
  SHA512:
6
- metadata.gz: 2bebcb6ee78c76d67b11436a4466629094e8157820a330fbcb93286d82a725b688cc0aad4ee9dd264a929a5669a30f9a8ab90f27a89a4b85885f9437a6b28070
7
- data.tar.gz: 5e69496888210a882723e2d9d54af4daf35546c7ddf14a5c225c07e51aedcf331e8d90d998a6eba267d6d8abcfb9474bd54dbbbee76cd2828dcef6f2a429e35f
6
+ metadata.gz: 5bc44e43c8851f850dfc542b9004ebdcb3f446036d0064947006815867bb9a4ad9502d2db0dd41fcfdebd68bf100d359a1537ed81b9e5147d936e0219a1fa8c5
7
+ data.tar.gz: 706cc7f127c5004e6dc8473531b5a305809e6eab762481b3f0bbf48571668bd807d2388e4d2a621d63bdb1e0ca5972848b61175707a3b01b13888bb0bee885ba
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- autotuner (1.0.0)
4
+ autotuner (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 intances) 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.
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.
@@ -5,15 +5,13 @@ module Autotuner
5
5
  class Base
6
6
  class << self
7
7
  def enabled?
8
- supported? && !@disabled
8
+ !@disabled
9
9
  end
10
10
 
11
11
  def disable!
12
12
  @disabled = true
13
13
  end
14
14
 
15
- private
16
-
17
15
  def supported?
18
16
  raise NotImplementedError
19
17
  end
@@ -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, in Puma, add the following code into config/puma.rb:
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
@@ -4,8 +4,6 @@ module Autotuner
4
4
  module Heuristic
5
5
  class HeapSizeWarmup < Base
6
6
  class << self
7
- private
8
-
9
7
  def supported?
10
8
  # Ruby 3.2 uses multiple heaps but does not support the
11
9
  # RUBY_GC_HEAP_%d_INIT_SLOTS environment variables, so we cannot
@@ -4,8 +4,6 @@ module Autotuner
4
4
  module Heuristic
5
5
  class Malloc < Base
6
6
  class << self
7
- private
8
-
9
7
  def supported?
10
8
  true
11
9
  end
@@ -4,8 +4,6 @@ module Autotuner
4
4
  module Heuristic
5
5
  class Oldmalloc < Base
6
6
  class << self
7
- private
8
-
9
7
  def supported?
10
8
  true
11
9
  end
@@ -4,8 +4,6 @@ module Autotuner
4
4
  module Heuristic
5
5
  class RememberedWBUnprotectedObjects < Base
6
6
  class << self
7
- private
8
-
9
7
  def supported?
10
8
  # Ruby 3.3.0 and later have support RUBY_GC_HEAP_REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIO
11
9
  RUBY_VERSION >= "3.3.0"
@@ -3,10 +3,10 @@
3
3
  module Autotuner
4
4
  module Heuristics
5
5
  HEURISTICS = Heuristic::Base.subclasses.freeze
6
- ENABLED_HEURISTICS = HEURISTICS.dup.keep_if(&:enabled?).freeze
6
+ SUPPORTED_HEURISTICS = HEURISTICS.dup.keep_if(&:supported?).freeze
7
7
 
8
- def enabled_heuristics
9
- ENABLED_HEURISTICS
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.enabled_heuristics.map { |h| h.new(@system_context) }
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
- heuristics.each do |heuristic|
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
- heuristics.each do |heuristic|
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
- heuristics.each do |h|
79
+ enabled_heuristics.each do |h|
72
80
  debug_states[h.name] = h.debug_state
73
81
  end
74
82
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Autotuner
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
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.1
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-06 00:00:00.000000000 Z
11
+ date: 2024-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mocha