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.



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

def last_checked
  @last_checked
end

Instance Method Details

#configure(conf) ⇒ Object



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

def configure(conf)
  super

  @interval = @interval.to_i
end

#shutdownObject



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

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

#startObject



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

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

#start_gcObject



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

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



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

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