Replies: 1 comment 1 reply
-
Ruby is essentially a singe thread due to infamous GIL. def write(chunk)
path = extract_placeholders(@path_template, chunk)
FileUtils.mkdir_p File.dirname(path), mode: @dir_perm
# begin
log.info "before loop"
abc = 0
# the loop is to slow down flush_thread, the slower, the easier to see the problem.
while abc < 500000000
# seems like io-independent operation cannot reproduce the problem
# like sleep 10 or puts "something"
abc += 1
end
log.info "after loop"
# end ... will block other threads in Fluentd from running. You need to use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I use elasticsearch to collect logs. First I use
in_tail
to collect logs andout_forward
to forward event to fluentd aggregator. In aggregator, I usein_forward
to accept events andout_elasticsearch
to bulk logs.And I encounted a problem, in which the buffer was processed extremely slow so that buffer's size became bigger and bigger.
The version of fluentd I use is 1.11.5, which is inside td-agent 3.8.1.
I checkout fluentd's source code, and checkout tag
v1.11.5
, head commit is 24fe4cb.By debugging, I found a simple way to reproduce this problem, but I was not sure it's properly. I just saw the similar
netstat
result(some connection got stuck at ESTABLISHED, and Recv-Q was large), and the buffer was slowly processed.Way to reproduce:
in_forward.rb
, which should be at/opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/fluentd-1.11.5/lib/fluent/plugin
if install fluentd through td-agent, or in sourcefluentd/lib/fluent/plugin/in_forward.rb
Lines 259 to 266 in 24fe4cb
Add
log.info
at probably line 263, inparser.feed_each
's block.buffer.rb
, which should be in the same directory ofin_forward.rb
, or in sourcefluentd/lib/fluent/plugin/buffer.rb
Lines 288 to 294 in 24fe4cb
and add
log.on_info
at probably line 292.out_file.rb
, which should be in the same directory ofin_forward.rb
, or in sourcefluentd/lib/fluent/plugin/out_file.rb
Lines 195 to 199 in 24fe4cb
and add code at probably line 199.
Start fluentd aggretator.
Start the first fluentd.
My local result.
Log of first fluentd.
log of aggretator.
According to the aggregator's log, I think the flush_thread getting slowly actually affect event_loop, and then cause
in_forward
works abnormally. There is another reason that I think the above way is similar toout_elasticsearch
. Inout_elasticsearch
, There is also a loop to map events in chunk to bulk request body, and I guess it's a io-independent operation.I am new to ruby, and I was tring to confirm whether ruby's thread switch machenism cause this problem. I also wrote simple tests(including pure ruby thread and interaction between ruby and c extension) to verify, but I failed.
Beta Was this translation helpful? Give feedback.
All reactions