1.15.0 PowerScheduler plugin -- Standby timeout timer does not get update (1 Viewer)

Edward Cheung

New Member
August 23, 2016
4
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
 

mm1352000

Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    Hello and welcome Edward :)

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

    The standby time does not get reset after a system busy event is detected. It stays unchanged.
    So you want the system to sleep 60 minutes after the last user activity (eg. login)?

    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.
    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
     

    Edward Cheung

    New Member
    August 23, 2016
    4
    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
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    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.

    Logon via terminal service is just one.
    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.

    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.
    The correct understanding is: PS prevents Windows from suspending 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.
    The correct understanding is: PS prevents Windows from suspending the machine for X minutes after the last MediaPortal user activity.

    I thought that should include all the conditions that powerscheduler allows me to configure i.e. network traffic, file shares, processes.
    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.
    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.
    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.

    Take my case as an example...
    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
     

    Edward Cheung

    New Member
    August 23, 2016
    4
    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
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    Home Country
    New Zealand New Zealand
    I can workaround with setting the ping monitor to look at the client machines...
    Indeed, you could. (y)

    Just another thought. Is it possible to make the 2 minutes grace period configurable?
    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.)
     

    regeszter

    Retired Team Member
  • Premium Supporter
  • October 29, 2005
    5,335
    4,954
    Home Country
    Hungary Hungary
    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

    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.
     

    Edward Cheung

    New Member
    August 23, 2016
    4
    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;
     

    Users who are viewing this thread

    Top Bottom