0

I am using blue-daemons fork of daemons gem (since the second one looks totally abandoned) along with daemons-rails gem, which wraps daemons for rails.

The problem is that my daemon eats too much CPU when it's idle (10-20 times higher then it's actually performing the job).

By being idle, I mean that I have special flag - Status.active?. If Status.active? is true, then I perform the job, if it's false, then I just sleep 10 secs and iterate next step in the while($running) do block and check status again and again.

I don't want to hard stop job because there is really sensitive data and I don't want the process to break it. Is there any good way to handle that high CPU usaget? I tried Sidekiq, but it looks like it's primary aim is to run jobs on demand or on schedule, but I need the daemon to run on non-stop basis.

$running = true
Signal.trap("TERM") do 
  $running = false
end

while($running) do
  while Status.active? do
       ..... DO LOTS OF WORK ..... 
  else
     sleep 10
  end
end
Ilya Cherevkov
  • 1,743
  • 2
  • 17
  • 47
  • 1
    I just ran [this](http://lpaste.net/110842) and I am getting 0% CPU. Are you sure you aren't doing anything else? Also, `while predicate do ... else ... end` isn't valid. – Justin Wood Sep 10 '14 at 13:48
  • Looks like it was my bad, thank you. Fixing `while` syntax did it for me – Ilya Cherevkov Sep 10 '14 at 13:58
  • How were you even able to run it with bad syntax? It should have returned immediately stating there was an issue. – Justin Wood Sep 10 '14 at 14:47
  • There was an error but daemon were rerunning code each time and returning error in the loop. That's why it was eating so much CPU – Ilya Cherevkov Sep 10 '14 at 20:18

0 Answers0