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

fix try_flush_interval < 1 and queued_chunk_flush_interval < 1 to work #568

Merged
merged 1 commit into from
Apr 19, 2015
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: 8 additions & 8 deletions lib/fluent/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OutputThread
def initialize(output)
@output = output
@finish = false
@next_time = Engine.now + 1.0
@next_time = Time.now.to_f + 1.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just directly use Time.now + 1.0. Time objects can be compared or subtracted as-is.

irb(main):001:0> next_time = Time.now + 1.0
=> 2015-03-28 11:24:03 +0900
irb(main):002:0> next_wait = next_time - Time.now
=> 0.719691

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float + float is faster than time + float, and time < float results in error

irb(main):001:0> Time.now < Time.now.to_f
ArgumentError: comparison of Time with 1427512006.7472174 failed
        from (irb):1:in `<'

but I think we can change it to time object here. let me try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made change like this to use time object > https://gist.github.com/sonots/3cd09b3022460ec1aac8

But, test did not pass. I felt it makes code complicated.
Also, note that float + float is faster than time + float.

My opinion is to use float rather than time object. Any opinions? > ALL

PS. Test passed with this additional change, though > https://gist.github.com/sonots/3cd09b3022460ec1aac8#comment-1422381

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I now feel that changing to Time objects here is kinda overkill to this original issue. It is a good thing to have, but we can live without them.

end

def configure(conf)
Expand Down Expand Up @@ -132,7 +132,7 @@ def run
@mutex.lock
begin
until @finish
time = Engine.now
time = Time.now.to_f

if @next_time <= time
@mutex.unlock
Expand All @@ -141,7 +141,7 @@ def run
ensure
@mutex.lock
end
next_wait = @next_time - Engine.now
next_wait = @next_time - Time.now.to_f
else
next_wait = @next_time - time
end
Expand Down Expand Up @@ -231,7 +231,7 @@ def configure(conf)
end

def start
@next_flush_time = Engine.now + @flush_interval
@next_flush_time = Time.now.to_f + @flush_interval
@buffer.start
@secondary.start if @secondary
@writers.each {|writer| writer.start }
Expand Down Expand Up @@ -280,10 +280,10 @@ def enqueue_buffer(force = false)
end

def try_flush
time = Engine.now
time = Time.now.to_f

empty = @buffer.queue_size == 0
if empty && @next_flush_time < (now = Engine.now)
if empty && @next_flush_time < (now = Time.now.to_f)
@buffer.synchronize do
if @next_flush_time < now
enqueue_buffer
Expand Down Expand Up @@ -330,7 +330,7 @@ def try_flush
end

if has_next
return Engine.now + @queued_chunk_flush_interval
return Time.now.to_f + @queued_chunk_flush_interval
else
return time + @try_flush_interval
end
Expand Down Expand Up @@ -385,7 +385,7 @@ def try_flush

def force_flush
@num_errors_lock.synchronize do
@next_retry_time = Engine.now - 1
@next_retry_time = Time.now.to_f - 1
end
enqueue_buffer(true)
submit_flush
Expand Down