Class: TuneMyGc::Syncer
- Inherits:
-
Object
- Object
- TuneMyGc::Syncer
- Defined in:
- lib/tunemygc/syncer.rb
Constant Summary collapse
- TIMEOUT =
seconds
20- ENVIRONMENT =
[ENV['RUBY_GC_TOKEN'], RUBY_VERSION, Rails.version, ENV.select {|k,v| k =~ /RUBY_GC_/ }, TuneMyGc::VERSION, GC::OPTS, GC::INTERNAL_CONSTANTS].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #environment(snapshotter) ⇒ Object
-
#initialize(host = TuneMyGc::HOST) ⇒ Syncer
constructor
A new instance of Syncer.
- #sync(snapshotter) ⇒ Object
- #sync_required?(snapshotter) ⇒ Boolean
Constructor Details
#initialize(host = TuneMyGc::HOST) ⇒ Syncer
Returns a new instance of Syncer.
14 15 16 17 18 19 |
# File 'lib/tunemygc/syncer.rb', line 14 def initialize(host = TuneMyGc::HOST) @uri = URI("http://#{host}/ruby") @client = Net::HTTP.new(@uri.host, @uri.port) @client.use_ssl = (uri.port == 443) @client.read_timeout = TIMEOUT end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
12 13 14 |
# File 'lib/tunemygc/syncer.rb', line 12 def client @client end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/tunemygc/syncer.rb', line 12 def uri @uri end |
Instance Method Details
#environment(snapshotter) ⇒ Object
41 42 43 |
# File 'lib/tunemygc/syncer.rb', line 41 def environment(snapshotter) ENVIRONMENT.dup.push(snapshotter.stat_keys) end |
#sync(snapshotter) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tunemygc/syncer.rb', line 21 def sync(snapshotter) if sync_required?(snapshotter) response = nil timeout do response = sync_with_tuner(snapshotter) end timeout do process_config_callback(response) end if response else TuneMyGc.log "Nothing to sync, discarding #{snapshotter.size} snapshots" snapshotter.clear end end |
#sync_required?(snapshotter) ⇒ Boolean
36 37 38 39 |
# File 'lib/tunemygc/syncer.rb', line 36 def sync_required?(snapshotter) return true if ENV['RUBY_GC_SYNC_ALWAYS'] snapshotter.unit_of_work end |