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

Use nonblocking write #39

Merged
merged 2 commits into from
Jan 25, 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
16 changes: 15 additions & 1 deletion lib/fluent/logger/fluent_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def initialize(tag_prefix = nil, *args)
end
end

@wait_writeable = true
@wait_writeable = options[:wait_writeable] if options.key?(:wait_writeable)

@last_error = {}

begin
Expand Down Expand Up @@ -168,6 +171,9 @@ def write(msg)
@pending = nil
true
rescue => e
unless wait_writeable?(e)
raise e
end
set_last_error(e)
if @pending.bytesize > @limit
@logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
Expand All @@ -185,7 +191,7 @@ def send_data(data)
unless connect?
connect!
end
@con.write data
@con.write_nonblock data
#while true
# puts "sending #{data.length} bytes"
# if data.length > 32*1024
Expand Down Expand Up @@ -237,6 +243,14 @@ def set_last_error(e)
# TODO: Check non GVL env
@last_error[Thread.current.object_id] = e
end

def wait_writeable?(e)
if e.instance_of?(IO::EAGAINWaitWritable)
@wait_writeable
else
true
end
end
end
end
end