1.15.0 - PowerScheduler plugin -- Standby timeout timer does not get update

Discussion in 'Archive' started by Edward Cheung, August 23, 2016.

  1. Edward Cheung

    Edward Cheung New Member

    Joined:
    August 23, 2016
    Messages:
    4
    Likes Received:
    0
    Gender:
    Male
    Ratings:
    +0 / 0
    Home Country:
    Hong Kong Hong Kong
    MediaPortal Version: 1.14.0

    Description
    Dear Dev,

    I have a machine with TVServer installed and use the PowerScheduler to shutdown the machine.
    The standby time does not get reset after a system busy event is detected. It stays unchanged.

    Had a quick look into the source code and it seems possible fix is to modify the CheckForStandby() function such that the _lastUserTime gets updated to current time when system not idle is detected. I may well be wrong or there is better way to do this.

    I am happy to test the fix if you can send me the plugin files.


    else
    {
    if (_idle)
    {
    Log.Info("PS: System changed from idle state to busy state");
    _idle = false;
    SendPowerSchedulerEvent(PowerSchedulerEventType.SystemBusy);
    }
    ++ _lastUserTime = DateTime.Now <--Set _lastUserTime to current time
    Log.Debug("PS: System is busy and should not go to standby");
    }





    Regards,

    Edward


    Steps to Reproduce:
    Here's an extract of the log file and step to reproduce:

    ====PowerScheduler Initialize (For information only)====
    [2016-08-23 07:59:23,063] [Log ] [TVService] [DEBUG] - PS: Registered PowerScheduler as IPowerScheduler service to GlobalServiceProvider
    [2016-08-23 07:59:23,079] [Log ] [TVService] [INFO ] - PS: Starting PowerScheduler server plugin...
    [2016-08-23 07:59:23,079] [Log ] [TVService] [DEBUG] - PS: LoadSettings()
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: PowerScheduler forces system to go to standby when idle: True
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Shutdown mode: Shutdown
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Standby after: 60 minutes
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Pre-wakeup time: 60 seconds
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Pre-no-standby time: 300 seconds
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Standby allowed until 24 o' clock
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Standby allowed until 24 o' clock on weekend
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: Wakeup system for varios events: True
    [2016-08-23 07:59:23,110] [Log ] [TVService] [DEBUG] - PS: Run command on power state change:
    [2016-08-23 07:59:23,110] [Log ] [TVService] [INFO ] - PS: PowerSchedulerFactory
    [2016-08-23 07:59:23,110] [Log ] [TVService] [DEBUG] - PS: Registered standby/wakeup handlers to PowerScheduler server plugin
    [2016-08-23 07:59:23,126] [Log ] [TVService] [DEBUG] - PS: Registered PowerScheduler as IPowerEventHandler service to GlobalServiceProvider
    [2016-08-23 07:59:23,126] [Log ] [TVService] [DEBUG] - PS: Registered PowerScheduler as IPowerControl remoting service
    [2016-08-23 07:59:23,126] [Log ] [TVService] [DEBUG] - PS: StandbyWakeupThread started
    [2016-08-23 07:59:23,126] [Log ] [TVService] [DEBUG] - ProcessActiveHandler: Preventing standby for processes:

    ====First time powerscheduler check for events and detected I logon using terminal service====
    [2016-08-23 07:59:24,140] [Log ] [PS StandbyWakeup] [DEBUG] - PS: LoadSettings()
    [2016-08-23 07:59:24,155] [Log ] [PS StandbyWakeup] [DEBUG] - NetworkMonitorHandler: Network monitor started
    [2016-08-23 07:59:24,545] [Log ] [PS StandbyWakeup] [DEBUG] - NetworkMonitorHandler: Idle limit in KB/s: 10
    [2016-08-23 07:59:24,561] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetWakeupTimer()
    [2016-08-23 07:59:24,576] [Log ] [PS StandbyWakeup] [DEBUG] - PS: No pending events found in the future which should wakeup the system
    [2016-08-23 07:59:24,592] [Log ] [PS StandbyWakeup] [DEBUG] - PS: CheckForStandby()
    [2016-08-23 07:59:24,654] [Log ] [PS StandbyWakeup] [DEBUG] - PS: Inspecting ActivePorts: StandbyPrevented
    [2016-08-23 07:59:24,654] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetStandbyMode(StandbyPrevented)
    [2016-08-23 07:59:24,654] [Log ] [PS StandbyWakeup] [DEBUG] - PS: System is busy and should not go to standby

    ====I logged out and powerscheduler now detected system is idle and set the sleep timeout to 8:59:23====
    [2016-08-23 08:00:58,161] [Log ] [PS StandbyWakeup] [DEBUG] - PS: StandbyWakeupThread triggered by check interval
    [2016-08-23 08:00:58,161] [Log ] [PS StandbyWakeup] [DEBUG] - PS: LoadSettings()
    [2016-08-23 08:00:58,192] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetWakeupTimer()
    [2016-08-23 08:00:58,192] [Log ] [PS StandbyWakeup] [DEBUG] - PS: No pending events found in the future which should wakeup the system
    [2016-08-23 08:00:58,192] [Log ] [PS StandbyWakeup] [DEBUG] - PS: CheckForStandby()
    [2016-08-23 08:00:58,270] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetStandbyMode(StandbyAllowed)
    [2016-08-23 08:00:58,270] [Log ] [PS StandbyWakeup] [INFO ] - PS: System changed from busy state to idle state
    [2016-08-23 08:00:58,270] [Log ] [PS StandbyWakeup] [DEBUG] - PS: System is idle and may go to standby
    [2016-08-23 08:00:58,270] [Log ] [PS StandbyWakeup] [DEBUG] - PS: Active standby is enabled - go to standby after idle timeout at 8:59:23

    ====I login again via terminal service====
    [2016-08-23 08:01:28,394] [Log ] [PS StandbyWakeup] [DEBUG] - PS: StandbyWakeupThread triggered by check interval
    [2016-08-23 08:01:28,394] [Log ] [PS StandbyWakeup] [DEBUG] - PS: LoadSettings()
    [2016-08-23 08:01:28,425] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetWakeupTimer()
    [2016-08-23 08:01:28,425] [Log ] [PS StandbyWakeup] [DEBUG] - PS: No pending events found in the future which should wakeup the system
    [2016-08-23 08:01:28,425] [Log ] [PS StandbyWakeup] [DEBUG] - PS: CheckForStandby()
    [2016-08-23 08:01:28,503] [Log ] [PS StandbyWakeup] [DEBUG] - PS: Inspecting ActivePorts: StandbyPrevented
    [2016-08-23 08:01:28,503] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetStandbyMode(StandbyPrevented)
    [2016-08-23 08:01:28,503] [Log ] [PS StandbyWakeup] [INFO ] - PS: System changed from idle state to busy state
    [2016-08-23 08:01:28,503] [Log ] [PS StandbyWakeup] [DEBUG] - PS: System is busy and should not go to standby

    ====I logout but the idle timeout remained at 8:59:23. It should be 60 minutes from the time I logout based on my setting====
    [2016-08-23 08:01:58,642] [Log ] [PS StandbyWakeup] [DEBUG] - PS: StandbyWakeupThread triggered by check interval
    [2016-08-23 08:01:58,642] [Log ] [PS StandbyWakeup] [DEBUG] - PS: LoadSettings()
    [2016-08-23 08:01:58,674] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetWakeupTimer()
    [2016-08-23 08:01:58,674] [Log ] [PS StandbyWakeup] [DEBUG] - PS: No pending events found in the future which should wakeup the system
    [2016-08-23 08:01:58,674] [Log ] [PS StandbyWakeup] [DEBUG] - PS: CheckForStandby()
    [2016-08-23 08:01:58,767] [Log ] [PS StandbyWakeup] [DEBUG] - PS: SetStandbyMode(StandbyAllowed)
    [2016-08-23 08:01:58,767] [Log ] [PS StandbyWakeup] [INFO ] - PS: System changed from busy state to idle state
    [2016-08-23 08:01:58,767] [Log ] [PS StandbyWakeup] [DEBUG] - PS: System is idle and may go to standby
    [2016-08-23 08:01:58,767] [Log ] [PS StandbyWakeup] [DEBUG] - PS: Active standby is enabled - go to standby after idle timeout at 8:59:23
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,518
    Likes Received:
    4,730
    Ratings:
    +8,196 / 17
    Home Country:
    New Zealand New Zealand
    Hello and welcome Edward :)

    Thank you for taking the time to investigate and look at the code. (y)

    So you want the system to sleep 60 minutes after the last user activity (eg. login)?

    With the greatest respect, I think you have misunderstood.
    _lastUserTime is intended to relate to user activity inside any MediaPortal client. General user activity in the system is not considered.

    Best regards,
    mm
     
  4. Edward Cheung

    Edward Cheung New Member

    Joined:
    August 23, 2016
    Messages:
    4
    Likes Received:
    0
    Gender:
    Male
    Ratings:
    +0 / 0
    Home Country:
    Hong Kong Hong Kong
    Hi MM,

    Logon via terminal service is just one. I am using the server to serve video files, music, etc and set the powerscheduler to not shutdown the server when there is network traffic. Anyhow, I have the impression that the standby timeout in the configuration tells powerscheduler to keep the machine alive for x more minutes after the machine becomes idle. I thought that should include all the conditions that powerscheduler allows me to configure i.e. network traffic, file shares, processes.

    While modifying the _lastUserTime may not be the right way to fix the issue, powerscheduler not updating the standby time after a valid activity is still a problem.

    Take my case as an example. I set the timeout to 60 minutes. If I play a video file that is 120 minutes long, by the time the video end, I have already passed the timeout (because the timeout doesn't get updated as I play the file/generating network traffic). When I finish the current video, powerscheduler only gives a final 2minutes of "grace period" for me play another file in order to prevent the machines from being shutdown by the scheduler. This is obviously a problem.

    Regards,

    Edward
     
  5. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,518
    Likes Received:
    4,730
    Ratings:
    +8,196 / 17
    Home Country:
    New Zealand New Zealand
    Edward,

    You seem to expect PowerScheduler to completely manage the system power. Actually, Windows is responsible for automatically suspending (standby, hibernate, shutdown) the system. PowerScheduler's main purpose is only to prevent automatic suspension in certain scenarios (eg. network activity). It's very important that you understand that clearly.

    Windows is responsible for recognising all regular system user activity - including terminal service log in - and delaying/preventing automatic suspension. PowerScheduler doesn't have to do anything, so that's why that activity isn't tracked.

    The correct understanding is: PS prevents Windows from suspending the server when there is network traffic.

    The correct understanding is: PS prevents Windows from suspending the machine for X minutes after the last MediaPortal user activity.

    You are mistaken. MediaPortal user activity (eg. going to a different section within MediaPortal, playing media within MediaPortal) is the only valid condition related to the timeout setting. Network traffic, file shares, processes etc. are not MediaPortal user activity, so they are not valid conditions.
    As explained above: system activity such as terminal service log in/out is not valid MediaPortal user activity. PowerScheduler doesn't have to detect or handle that activity because Windows already detects and handles it.

    I think you may have created this problem for yourself when you enabled the force-standby-when-idle setting:
    [2016-08-23 07:59:23,094] [Log ] [TVService] [DEBUG] - PS: PowerScheduler forces system to go to standby when idle: True

    http://wiki.team-mediaportal.com/1_...uler_forces_system_to_go_to_standby_when_idle

    As far as I can see, that setting is the reason why you only get the 2 minute grace period.

    Why did you enable that setting?

    Regards,
    mm
     
    • Informative Informative x 1
  6. Edward Cheung

    Edward Cheung New Member

    Joined:
    August 23, 2016
    Messages:
    4
    Likes Received:
    0
    Gender:
    Male
    Ratings:
    +0 / 0
    Home Country:
    Hong Kong Hong Kong
    MM,

    I have a LSI hardware RAID card in the server in order to hold all the media content and it doesn't like any sleep/standby state except complete shutdown and restart. That's why I have to set powerscheduler to force S5. If powerscheduler is designed to only reset the timeout by user activity (i.e. more for client side usage which I can understand), that's fine. I can workaround with setting the ping monitor to look at the client machines so to keep the server alive although that would not give maxmium power saving as I can be using the client for activites not involving the server.

    Just another thought. Is it possible to make the 2 minutes grace period configurable? That can also work without conflicting with the usage of the _lastUserTime variable.

    In any case, I like the powerscheduler. It's a very powerful tool.


    Regards,

    Edward
     
  7. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,518
    Likes Received:
    4,730
    Ratings:
    +8,196 / 17
    Home Country:
    New Zealand New Zealand
    Indeed, you could. (y)

    At present it appears to be hard-coded. The code that's affecting you is here:
    https://github.com/MediaPortal/Medi...lugins/PowerScheduler/PowerScheduler.cs#L1287

    ...though it's also hard-coded elsewhere. For example:
    https://github.com/MediaPortal/Medi...lugins/PowerScheduler/PowerScheduler.cs#L1368

    (Not the best code practise, sorry.)
     
    • Informative Informative x 1
  8. regeszter
    • Team MediaPortal

    regeszter Retired Team Member

    Joined:
    October 29, 2005
    Messages:
    5,335
    Likes Received:
    2,863
    Ratings:
    +5,151 / 18
    Home Country:
    Hungary Hungary
    Serve with MediaPortal clients? If yes, the server won't power of if any MP client is on.
    If you use the server as file server, you may use the ping monitor to check if any clients is on.
     
  9. Edward Cheung

    Edward Cheung New Member

    Joined:
    August 23, 2016
    Messages:
    4
    Likes Received:
    0
    Gender:
    Male
    Ratings:
    +0 / 0
    Home Country:
    Hong Kong Hong Kong
    Regeszter: My server has no client running on it (i.e. dedicated and 'headless'), thus the problem with having _lastUserTime updated to prevent entering standby prematurely.
    Dev Group: Please consider the following patch for TvEngine3\TVLibrary\Plugins\PowerScheduler\PowerScheduler.cs in Mediaportal 1 Main branch.
    NOTES:
    1) I didn't modify the PowerScheduler in "PowerSchedulerClientPlugin" with the believe that it is for the client side. So using the user activity to drive the standby timeout is, by definition, appropiate.
    2) I introduce another variable _lastSystemTime not to contaminate the _lastUserTime.
    3) I didn't tweak the 120 second hardcoded timeout for determination of the "_ignoreSuspendUntil" as it's intend for other purpose.

    139a140,144
    > /// Last time any activity by the system was detected.
    > /// </summary>
    > private DateTime _lastSystemTime;
    >
    > /// <summary>
    1297,1298c1302,1307
    < DateTime idleTimeout = _lastUserTime.AddMinutes(_settings.IdleTimeout);
    <
    ---
    > DateTime idleTimeout = _lastUserTime.AddMinutes(_settings.IdleTimeout);
    > if (_lastUserTime < _lastSystemTime)
    > {
    > idleTimeout = _lastSystemTime.AddMinutes(_settings.IdleTimeout);
    > }
    >
    1327a1337
    > _lastSystemTime = DateTime.Now;
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!