diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index 1f357828a0..bd1544b54a 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -1252,7 +1252,13 @@ def update_retry_state(chunk_id, using_secondary, error = nil) log.debug "buffer queue cleared" @retry = nil else - @retry.step + # Ensure that the current time is greater than or equal to @retry.next_time to avoid the situation when + # @retry.step is called almost as many times as the number of flush threads in a short time. + if Time.now >= @retry.next_time + @retry.step + else + @retry.recalc_next_time # to prevent all flush threads from retrying at the same time + end if error if using_secondary msg = "failed to flush the buffer with secondary output." diff --git a/lib/fluent/plugin_helper/retry_state.rb b/lib/fluent/plugin_helper/retry_state.rb index d8d629afef..687e8052f3 100644 --- a/lib/fluent/plugin_helper/retry_state.rb +++ b/lib/fluent/plugin_helper/retry_state.rb @@ -127,6 +127,10 @@ def step nil end + def recalc_next_time + @next_time = calc_next_time + end + def limit? if @forever false