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

EMDirWatcher#stop causes 100% CPU usage #4

Open
NV opened this issue Jan 22, 2011 · 2 comments · May be fixed by #5
Open

EMDirWatcher#stop causes 100% CPU usage #4

NV opened this issue Jan 22, 2011 · 2 comments · May be fixed by #5

Comments

@NV
Copy link
Member

NV commented Jan 22, 2011

require 'eventmachine'
require 'em-dir-watcher'

EM.kqueue = true if EM.kqueue?
EventMachine.run do
  puts 'Watching .'
  dw = EMDirWatcher.watch '.',
        :include_only => ['*.html'],
        :exclude => [],
        :grace_period => 0.1 do |paths|
    puts paths
  end

  puts 'Everything goes well so far'

  EventMachine::Timer.new(10) do
     puts 'Stoping EMDirWatcher. ruby CPU usage is 100% now. WTF?'
     dw.stop
   end
end

➤ ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.6.0]

@NV
Copy link
Member Author

NV commented Jan 29, 2011

After killing process notify_readable invokes too often. Don't know yet how to fix it.

@millermedeiros
Copy link

the ruby process is also using 100% of my CPU sometimes (I'm on a mac using mostly the FF extension).

the socket is probably running into a while(true), don't know how it was implemented and I'm not a ruby developer to look into it and solve the bug but I've seen it happening before, on that specific case the loop had a thread blocking operation (something related with I/O) when one of the sides of the socket disconnected that blocking operation didn't happened anymore, or happened too fast, so the loop was too short causing a result similar to a while(true).

If that is really the issue the way to solve it is to always enforce a delay of a few milliseconds before running the loop and kill the process after a couple seconds without any communication.

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 a pull request may close this issue.

2 participants