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

Conversation

okkez
Copy link
Contributor

@okkez okkez commented Dec 24, 2015

No description provided.

When detect EAGAIN or EWOULDBLOCK,

`:wait_writeable` is true: store the data in buffer and try to write
next time.

`:wait_writeable` is false: Raise IO::EAGAINWaitWritable
@okkez
Copy link
Contributor Author

okkez commented Dec 24, 2015

I've not able to produce the situation explaining in #30 because fluentd is very fast and robust.
I've tested this PR using following scripts.

Run fake-server.rb and t.rb.

In previous version,
fake-server.rb cannot process so many requests and may block the request sometimes.
t.rb blocks while writing logs sometimes.

In this PR, t.rb does not block while writing logs anymore.
But set :wait_writeable to false, fluent-logger raises an error when detect IO::EAGAINWaitWritable.

fake-server.rb:

require "socket"

server = TCPServer.open("localhost", 24224)
addr = server.addr
addr.shift
puts "server is on #{addr.join(":")}"

loop do
  Thread.start(server.accept) do |s|
    puts "#{s} is accepted"
    while s.gets
      print "#{$_.size}/"
      sleep 30
    end
    puts "#{s} is gone"
    s.close
  end
end

t.rb:

require "fluent-logger"

Fluent::Logger::FluentLogger.open(nil, :host=>'localhost', :port=>24224, :wait_writeable => true)

a = []

start = Time.now

100.times do |i|
  a << Thread.start(i, j = 0) do
    loop do
      Fluent::Logger.post("myapp.access", ENV.to_hash)
      j += 1
      #puts "#{i},#{j}" if j % 1000 == 0
      print "#{i},#{j}/"
    end
  end
end

a.each(&:join)

p :done
p Time.now - start

@theindra
Copy link

theindra commented May 30, 2016

+1
Hi, we ran into the same problem. Our ruby web app hangs after about 5 minutes and the profiler tells us that most of the time is spent in fluent-logger.
I think all available threads are waiting for the logger. When are you planing to release a fix for this issue

@repeatedly
Copy link
Member

Does anyone test this patch?
We want to know this patch resolves blocking issue properly.

@dCSeven
Copy link

dCSeven commented Jan 25, 2019

Are there any updates or plans to apply this patch?
I'm facing a similar problem concerning the blocking of fluentd-logger, where it would help.

@repeatedly repeatedly merged commit 4c929ef into fluent:master Jan 25, 2019
@repeatedly
Copy link
Member

We wait a response from users but no response.
So we merge this patch and release rc version soon.

@dCSeven
Copy link

dCSeven commented Jan 25, 2019

Thank you

@repeatedly
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants