Class: Fluent::GcInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_gc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_checkedObject

Returns the value of attribute last_checked.



14
15
16
# File 'lib/fluent/plugin/in_gc.rb', line 14

def last_checked
  @last_checked
end

Instance Method Details

#configure(conf) ⇒ Object



16
17
18
19
20
# File 'lib/fluent/plugin/in_gc.rb', line 16

def configure(conf)
  super

  @interval = @interval.to_i
end

#shutdownObject



28
29
30
31
32
# File 'lib/fluent/plugin/in_gc.rb', line 28

def shutdown
  super
  @watcher.terminate
  @watcher.join
end

#startObject



22
23
24
25
26
# File 'lib/fluent/plugin/in_gc.rb', line 22

def start
  super
  GC.disable if @disable
  @watcher = Thread.new(&method(:watcher))
end

#start_gcObject



51
52
53
54
55
56
57
# File 'lib/fluent/plugin/in_gc.rb', line 51

def start_gc
  log.info "gc: before #{GC.stat}" if @debug # intentionally info level
  disabled = GC.enable
  GC.start
  GC.disable if disabled
  log.info "gc: after  #{GC.stat}" if @debug
end

#watcherObject

thread callback



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/in_gc.rb', line 35

def watcher
  @last_checked = Fluent::Engine.now
  while true
    sleep 0.5
    begin
      if Fluent::Engine.now - @last_checked >= @interval
        now = Fluent::Engine.now
        start_gc
        @last_checked = now
      end
    rescue => e
      log.warn "#{e.class} #{e.message} #{e.backtrace.first}"
    end
  end
end