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.



8
9
10
# File 'lib/fluent/plugin/in_gc.rb', line 8

def last_checked
  @last_checked
end

Instance Method Details

#configure(conf) ⇒ Object



10
11
12
13
14
# File 'lib/fluent/plugin/in_gc.rb', line 10

def configure(conf)
  super

  @interval = @interval.to_i
end

#shutdownObject



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

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

#startObject



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

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

#start_gcObject



45
46
47
48
49
50
51
# File 'lib/fluent/plugin/in_gc.rb', line 45

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fluent/plugin/in_gc.rb', line 29

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