[Approved] Recording Conflicts Optimization (1 Viewer)

romadd64

MP Donator
  • Premium Supporter
  • October 24, 2007
    82
    15
    Home Country
    Italy Italy
    When you set a new scheduled recording, tvplugin checks conflicts with other schedules.
    The check can be very slow, especially when there is a combination of :

    - multiseat setup and the new schedule is set on a client
    - many tuners
    - the new schedule has multiple episodes (record every...)
    - many schedules already present with multiple episodes
    - many channels with EPG across multiple days


    This patch introduces an optimization of the above check, and other bugfix/functionality :

    - optimization in GetConflictingSchedules(), search only between overlapping episodes
    - optimization in canViewTvChannel() and canTuneTvChannel(), create channel map only for current channel
    - bugfix, ConflictsManager should not use disabled cards for schedule allocation. It should not use also not present cards, but not implemented because I'm not sure the best way to do it
    - bugfix, ConflictsManager should check if schedule channel isn't mapped to a card, added user interaction like with episodes conflict


    romadd
     

    Attachments

    • Recording Conflicts Optimization.patch
      15.1 KB
    Last edited by a moderator:

    Neos

    Portal Member
    February 14, 2008
    18
    15
    Home Country
    Netherlands Netherlands
    You can further optimize the code by instancing DateTime.Now instead of calling it repeatedly:
    Code:
    DateTime now = DateTime.Now;
    and replace all calls to 'DateTime.Now' by 'now'

    Also you should not use the out parameter on an argument you already assigned:
    Code:
    List<Schedule> conflicts = new List<Schedule>();
    List<Schedule> notViewables = new List<Schedule>();
    layer.GetConflictingSchedules(schedule, out conflicts, out notViewables);
    Should instead be:
    Code:
    List<Schedule> conflicts;
    List<Schedule> notViewables;
    layer.GetConflictingSchedules(schedule, out conflicts, out notViewables);
    Out variables used as out-parameters should never be assigned. You assign them in the method 'GetConflictingSchedules'. The JIT might optimize this for you but if it does not (and it doesn't do much to much aggressive optimizations) you just created 2 lists which are destroyed once you call GetConflictingSchedules(). You can either use the lines I purposed or remove the 'out' parameters and not create the lists in GetConflictingSchedules().
     

    disaster123

    MP Donator
  • Premium Supporter
  • May 14, 2008
    3,558
    434
    Home Country
    Germany Germany
    AW: Recording Conflicts Optimization

    romadd64
    nice patch - which solves a lot of waiting for me. Also working fine here. Could you please fix the bugs/faults which Neos has found?
     

    romadd64

    MP Donator
  • Premium Supporter
  • October 24, 2007
    82
    15
    Home Country
    Italy Italy
    I will post in a few days a modified patch with optimizations suggested by Neos.
    Now I'm working on another patch.

    romadd
     

    disaster123

    MP Donator
  • Premium Supporter
  • May 14, 2008
    3,558
    434
    Home Country
    Germany Germany
    AW: Recording Conflicts Optimization

    Any news? This patch is great as it reduces scheduling recordings a lot.
     

    miroslav22

    Development Group Member
  • Premium Supporter
  • September 4, 2009
    703
    460
    Warwick
    Home Country
    United Kingdom United Kingdom
    we might be able to create additional indexes on columns in the database to further enhance this. I'll take a look in the next few days
     

    disaster123

    MP Donator
  • Premium Supporter
  • May 14, 2008
    3,558
    434
    Home Country
    Germany Germany
    AW: Recording Conflicts Optimization

    Oh that's also a good idea - never logged all queries not using indexes with mediaportal. But perhaps somebody should look at this in general.
     

    jameson_uk

    Retired Team Member
  • Premium Supporter
  • January 27, 2005
    7,258
    2,528
    Birmingham
    Home Country
    United Kingdom United Kingdom
    we might be able to create additional indexes on columns in the database to further enhance this. I'll take a look in the next few days

    Might make a difference but most likely will not. The main thing here is that the lookup is itterating over too many loops. The fact we are using a sort of ORM (GENTLE) means that queries tend to be "give me the list of cards" and then we itterate over that list saying well for this card give me the list of channels then for these channels give me the tuning details...

    The volume of data and type of query means that indexes are unlikely to help. The real thing here is to cut down the amount of loops
     

    miroslav22

    Development Group Member
  • Premium Supporter
  • September 4, 2009
    703
    460
    Warwick
    Home Country
    United Kingdom United Kingdom
    yea it depends on the volume of data and the number of queries. At the moment the number of queries increases exponentially as the number of schedules grows (eg double the number of schedules and you could have 50x more queries executed in total) .

    I usually have a lot of epg entries at any one time (~150,000) so i'll try benchmarking with additional indexes.
     

    disaster123

    MP Donator
  • Premium Supporter
  • May 14, 2008
    3,558
    434
    Home Country
    Germany Germany
    AW: Recording Conflicts Optimization

    But the initial path schould still getting checked - it reduced scheduling for me from 10-30s down to 5s.
     

    Users who are viewing this thread

    Top Bottom