Skip to content

Commit

Permalink
in_tail: reduce the lifespan of the buffer area (#4763)
Browse files Browse the repository at this point in the history
**Which issue(s) this PR fixes**: 
Fixes #

**What this PR does / why we need it**: 
When log files are rotated at high speed, the lifespan of `IOHandler`
objects may become extended.
Along with this, the lifespan of `@iobuf` also increases.

Since `@iobuf` uses 8 KB of memory, if many such objects exist
simultaneously, memory usage might significantly increase.

**Docs Changes**:

**Release Note**:

Signed-off-by: Shizuo Fujita <[email protected]>
  • Loading branch information
Watson1978 authored Jan 9, 2025
1 parent 2df84a9 commit 17d9322
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ def initialize(watcher, path:, read_lines_limit:, read_bytes_limit_per_second:,
@receive_lines = receive_lines
@open_on_every_update = open_on_every_update
@fifo = FIFO.new(from_encoding || Encoding::ASCII_8BIT, encoding || Encoding::ASCII_8BIT, log, max_line_size)
@iobuf = ''.force_encoding('ASCII-8BIT')
@lines = []
@io = nil
@notify_mutex = Mutex.new
Expand Down Expand Up @@ -1201,6 +1200,7 @@ def handle_notify
end

with_io do |io|
iobuf = ''.force_encoding('ASCII-8BIT')
begin
read_more = false
has_skipped_line = false
Expand All @@ -1211,7 +1211,7 @@ def handle_notify
@start_reading_time ||= Fluent::Clock.now
group_watcher&.update_reading_time(@path)

data = io.readpartial(BYTES_TO_READ, @iobuf)
data = io.readpartial(BYTES_TO_READ, iobuf)
@eof = false
@number_bytes_read += data.bytesize
@fifo << data
Expand Down

0 comments on commit 17d9322

Please sign in to comment.