Skip to content

Commit

Permalink
Merge pull request #1901 from fujimotos/sf/output-busywaits
Browse files Browse the repository at this point in the history
output: Prevent flushing threads from consuming too much CPU.
  • Loading branch information
repeatedly authored Mar 19, 2018
2 parents 0003cfc + 9be8e86 commit 9c58346
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1313,9 +1313,17 @@ def flush_thread_run(state)
# This thread don't use `thread_current_running?` because this thread should run in `before_shutdown` phase
while @output_flush_threads_running
current_clock = Fluent::Clock.now
interval = state.next_clock - current_clock
next_retry_time = nil

if state.next_clock <= current_clock && @retry_mutex.synchronize { @retry ? @retry.next_time <= Time.now : true }
@retry_mutex.synchronize do
next_retry_time = @retry ? @retry.next_time : nil
end

if state.next_clock > current_clock
interval = state.next_clock - current_clock
elsif next_retry_time && next_retry_time > Time.now
interval = next_retry_time.to_f - Time.now.to_f
else
try_flush

# next_flush_time uses flush_thread_interval or flush_thread_burst_interval (or retrying)
Expand Down

0 comments on commit 9c58346

Please sign in to comment.