Skip to content

Commit 17d9322

Browse files
authored
in_tail: reduce the lifespan of the buffer area (#4763)
**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 <fujita@clear-code.com>
1 parent 2df84a9 commit 17d9322

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/fluent/plugin/in_tail.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,6 @@ def initialize(watcher, path:, read_lines_limit:, read_bytes_limit_per_second:,
11191119
@receive_lines = receive_lines
11201120
@open_on_every_update = open_on_every_update
11211121
@fifo = FIFO.new(from_encoding || Encoding::ASCII_8BIT, encoding || Encoding::ASCII_8BIT, log, max_line_size)
1122-
@iobuf = ''.force_encoding('ASCII-8BIT')
11231122
@lines = []
11241123
@io = nil
11251124
@notify_mutex = Mutex.new
@@ -1201,6 +1200,7 @@ def handle_notify
12011200
end
12021201

12031202
with_io do |io|
1203+
iobuf = ''.force_encoding('ASCII-8BIT')
12041204
begin
12051205
read_more = false
12061206
has_skipped_line = false
@@ -1211,7 +1211,7 @@ def handle_notify
12111211
@start_reading_time ||= Fluent::Clock.now
12121212
group_watcher&.update_reading_time(@path)
12131213

1214-
data = io.readpartial(BYTES_TO_READ, @iobuf)
1214+
data = io.readpartial(BYTES_TO_READ, iobuf)
12151215
@eof = false
12161216
@number_bytes_read += data.bytesize
12171217
@fifo << data

0 commit comments

Comments
 (0)