[mythtv-users] Auto shutdown occurs while transcode/commflag job is in progress (bad idle detection)

Matt Doran matt.doran at papercut.biz
Sun Apr 15 08:47:15 UTC 2007


Hi there,

I've delved into the code and think I've figured out why the machine is 
shutting down when it shouldn't.  It's not while the job is running ... 
but after a job completes and before the next starts. And would 
appreciate one of the developers opinions on how to fix this (so have 
CCed dev).

If I understand the idle detection / shutdown process .... I think it is 
slightly flawed.  Here's how I think it works.

   1. The scheduler (scheduler.cpp), detects that there are no
      recordings in progress, and no clients detected so starts the idle
      count down.
   2. Once the idle timeout is reached, the CheckShutdownServer() method
      is called.  By default this calls "mythshutdown --check", which
      checks various things to see if the shutdown is allowed.  One
      thing is it does is to grep the list of running programs to see if
      "mythtranscode" or "mythcommflag" are running.  If "mythshutdown
      --check" indicates that the shutdown cannot happen, the idle idle
      time is reset, and the process starts again.
   3. This happens over and over.  In the logs you see the the idles
      countdown, counting down to 0..... than starting over again.


The problem arises when the "CheckShutdownServer()" is called just after 
a job has completed, and the next job has not yet started.  This will 
cause the machine to be shutdown even though there are still jobs 
pending in the queue.

Possible work-arounds are:

    * Increase the idle timeout.  This will mean that
      "CheckShutdownServer()" is called less often, which will reduce
      the likelihood of incorrect shutdown.
    * Reduce the "JobQueueCheckFrequency" from the default of 60
      seconds.   This will reduce the time between one job completing
      and the next job starting, which will reduce the likelihood of
      incorrect shutdown.

These are OK options.  But neither is perfect.   I'd like to keep the 
idle shutdown time short, so the machine shuts down soon after becoming 
idle.   Setting the job check frequency too low will cause unnecessary 
work checking the job queue when it rarely changes state.

Any ideas on the best way to improve this behaviour?  One thought I had 
was to perform the "CheckShutdownServer()", more often than just once 
that idle timeout has expired.  Say once every 10 seconds when the "XX 
secs left to system shutdown!" message is displayed.  Something like the 
attached patch??

Thanks,
Matt



Matt Doran wrote:
> Hi there,
>
> I have my myth box (0.20-fixes) configured to autoshutdown when idle.  
> I also make use of mythwelcome, etc, so that the machine isn't on 
> wasting power when it doesn't need to be.
>
> It all works nicely, except it is common for it to shutdown, while a 
> transcode or commflag job is in progress.
>
> Here's some sample output from last night's logs....
>
>    2007-04-15 01:47:53.244 110 secs left to system shutdown!
>    2007-04-15 01:48:03.316 100 secs left to system shutdown!
>    2007-04-15 01:48:13.368 90 secs left to system shutdown!
>    2007-04-15 01:48:23.417 80 secs left to system shutdown!
>    2007-04-15 01:48:33.457 70 secs left to system shutdown!
>    2007-04-15 01:48:43.509 60 secs left to system shutdown!
>    2007-04-15 01:48:47.441 JobQueue: Currently set at 1 job(s) max and
>    to run new jobs from 00:00 to 12:00
>    2007-04-15 01:48:47.450 JobQueue: GetJobsInQueue: findJobs search
>    bitmask 4, found 14 total jobs
>    2007-04-15 01:48:47.477 JobQueue: GetJobsInQueue: Ignore 'Flag
>    Commercials' Job for 2512 @ 20070412195900 in Finished state.
>    2007-04-15 01:48:47.478 JobQueue: GetJobsInQueue: Ignore 'Transcode'
>    Job for 2512 @ 20070412195900 in Finished state.
>    2007-04-15 01:48:47.479 JobQueue: GetJobsInQueue: Ignore 'Flag
>    Commercials' Job for 2512 @ 20070412222900 in Finished state.
>    2007-04-15 01:48:47.480 JobQueue: GetJobsInQueue: Ignore 'Transcode'
>    Job for 2512 @ 20070412222900 in Finished state.
>    2007-04-15 01:48:47.481 JobQueue: GetJobsInQueue: Ignore 'Flag
>    Commercials' Job for 2511 @ 20070413155900 in Finished state.
>    2007-04-15 01:48:47.482 JobQueue: GetJobsInQueue: Ignore 'Transcode'
>    Job for 2511 @ 20070413155900 in Finished state.
>    *2007-04-15 01:48:47.483 JobQueue: GetJobsInQueue: Found 'Flag
>    Commercials' Job for 2501 @ 20070413203236 in Running state.*
>    2007-04-15 01:48:47.484 JobQueue: GetJobsInQueue: Found 'Transcode'
>    Job for 2501 @ 20070413203236 in Queued state.
>    2007-04-15 01:48:47.484 JobQueue: GetJobsInQueue: Found 'Flag
>    Commercials' Job for 2501 @ 20070414142900 in Queued state.
>    2007-04-15 01:48:47.485 JobQueue: GetJobsInQueue: Found 'Transcode'
>    Job for 2501 @ 20070414142900 in Queued state.
>    2007-04-15 01:48:47.486 JobQueue: GetJobsInQueue: Found 'Flag
>    Commercials' Job for 2511 @ 20070414193400 in Queued state.
>    2007-04-15 01:48:47.487 JobQueue: GetJobsInQueue: Found 'Transcode'
>    Job for 2511 @ 20070414193400 in Queued state.
>    2007-04-15 01:48:47.488 JobQueue: GetJobsInQueue: Found 'Flag
>    Commercials' Job for 2501 @ 20070414230000 in Queued state.
>    2007-04-15 01:48:47.489 JobQueue: GetJobsInQueue: Found 'Transcode'
>    Job for 2501 @ 20070414230000 in Queued state.
>    2007-04-15 01:48:53.562 50 secs left to system shutdown!
>    2007-04-15 01:49:03.618 40 secs left to system shutdown!
>
>
> As you can see there is a commercial flag going (job 2501) ... but the 
> system still thinks that it needs to shutdown.    So it seems that 
> there is a problem in the way that the backend detects if these jobs 
> are still running (i.e. it's idle detection).
>
> I see plenty of this type of output.  You see it counting down to 
> shutdown and then it restarts the counting.  But eventually the system 
> will shutdown without completing the current job ... or any of the 
> others in the queue.   The idle time is set to 120 secs and the job 
> queue is checked every 60 secs.
>
> Anyone else seeing this?  Any idea how to fix it?  Is there a bug 
> hiding here somewhere?
>
> Regards,
> Matt
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mythtv.org/pipermail/mythtv-users/attachments/20070415/e23e62f2/attachment-0001.htm 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sched-shutdown.diff
Url: http://mythtv.org/pipermail/mythtv-users/attachments/20070415/e23e62f2/attachment-0001.diff 


More information about the mythtv-users mailing list