Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace in_tail with a faster implementation. #2527

Merged
merged 2 commits into from
Jul 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,18 @@ def convert(s)
s.encode!(@encoding, @from_encoding, :invalid => :replace, :undef => :replace)
end

def next_line
def read_lines(lines)
idx = @buffer.index(@eol)
convert(@buffer.slice!(0, idx + 1)) unless idx.nil?

until idx.nil?
# Using freeze and slice is faster than slice!
# See https://github.com/fluent/fluentd/pull/2527
@buffer.freeze
rbuf = @buffer.slice(0, idx + 1)
@buffer = @buffer.slice(idx + 1, @buffer.size)
idx = @buffer.index(@eol)
lines << convert(rbuf)
end
end

def bytesize
Expand Down Expand Up @@ -733,9 +742,7 @@ def handle_notify
begin
while true
@fifo << io.readpartial(8192, @iobuf)
while (line = @fifo.next_line)
@lines << line
end
@fifo.read_lines(@lines)
if @lines.size >= @watcher.read_lines_limit
# not to use too much memory in case the file is very large
read_more = true
Expand Down