Daemon eats too much CPU when being idle

277 views Asked by At

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
0

There are 0 answers