Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Multiple monitors or 'If' ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Multiple monitors or 'If' ?

    My question relates to the process time involved in the following case:

    I have presently a single monitor with roughly 250 'If' sections, it's a kind of calendar thing where at certain turn numbers events fire, part of it underneath:

    Code:
    monitor_event FactionTurnStart FactionIsLocal
        if I_TurnNumber = 0
            campaign_wait 1
            historic_event    1618_01
        end_if
    
        if I_TurnNumber = 1
            campaign_wait 1
            historic_event 1618_01a    event\fenstersturz.bik
        end_if
    
        if I_TurnNumber = 2
            campaign_wait 1
            historic_event 1618_01b
        end_if
    
        if I_TurnNumber = 3
            campaign_wait 1
            historic_event 1618_01c
        end_if
    
    ...........
    
        if I_TurnNumber = 369
            campaign_wait 1
            historic_event 1648_10
        end_if
    
        if I_TurnNumber = 370
            campaign_wait 1
            historic_event 1648_11
        end_if
    
    end_monitor
    Would it be more efficient to use individual monitors, considering the size of this monitor? Processing time is already slow as the map is max size and it contains all factions.
    There are only very few monitors (approx 10) that monitor characters (which I believe are the major culprits on processing time). Total length of script so far is in excess of 23.000 lines (775KB), total count of monitors is slightly more then 1.400
    Last edited by Gigantus; November 11, 2011 at 03:32 AM.










  2. #2
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: Multiple monitors or 'If' ?

    The solution you're using is optimal, I did lots of research before for SS 6.3 scripts and even yesterday for some other project on this matter and:

    -if you check log file you'll see that checking 250 instances of "if" takes only a split second, plus it's fired only once per turn,
    - 250 monitors would equal up to few seconds lag (depends on construction... I'll do some tests on cs with 1k character\turn monitors only and see).

    My yesterday's testing brought interesting results as to actual worth of our lag reducing efforts. The conclusion is that CAI has the greatest influence over turn time and our attempts aren't as relevant to overall processing time as they are thought to be (which doesn't mean we shouldn't adhere to most optimal scripting practises).

    Breakdown of testing (32 factions, SS 6.5 beta):
    1. EDA, EDCT, guilds, CS, faction standing and CAI off - 2.27 sec avg turn time
    Spoiler Alert, click show to read: 
    00640307 1647.02282715 [328] 22:55:00.574 [game.script.counter] [trace] counter <sicily_ttc> = 1
    00640550 1650.20739746 [328] 22:55:03.757 [game.script.counter] [trace] counter <sicily_ttc> = 2
    00644958 1653.08972168 [328] 22:55:06.641 [game.script.counter] [trace] counter <sicily_ttc> = 3
    00645233 1655.93334961 [328] 22:55:09.485 [game.script.counter] [trace] counter <sicily_ttc> = 4
    00649570 1659.01623535 [328] 22:55:12.533 [game.script.counter] [trace] counter <sicily_ttc> = 5
    00649821 1659.76794434 [328] 22:55:13.319 [game.script.counter] [trace] counter <sicily_ttc> = 6
    00654205 1661.40295410 [328] 22:55:14.954 [game.script.counter] [trace] counter <sicily_ttc> = 7
    00654592 1662.33227539 [328] 22:55:15.884 [game.script.counter] [trace] counter <sicily_ttc> = 8
    00658890 1666.19116211 [328] 22:55:19.742 [game.script.counter] [trace] counter <sicily_ttc> = 9
    00659133 1669.70959473 [328] 22:55:23.261 [game.script.counter] [trace] counter <sicily_ttc> = 10

    2. CAI + faction standing only (faction standings proved irrelevant to turn time in other tests, turn time increases with every turn) - 58,3 sec turn time:
    Spoiler Alert, click show to read: 
    00403225 498.80633545 [2276] 23:31:20.637 [game.script.counter] [trace] counter <sicily_ttc> = 10
    00439283 558.73333740 [2276] 23:32:20.565 [game.script.counter] [trace] counter <sicily_ttc> = 11
    00469205 614.06945801 [2276] 23:33:15.902 [game.script.counter] [trace] counter <sicily_ttc> = 12
    00510562 686.05297852 [2276] 23:34:27.888 [game.script.counter] [trace] counter <sicily_ttc> = 13
    00542806 746.53857422 [2276] 23:35:28.374 [game.script.counter] [trace] counter <sicily_ttc> = 14
    00583380 810.63818359 [2276] 23:36:32.476 [game.script.counter] [trace] counter <sicily_ttc> = 15
    00612847 875.12219238 [2276] 23:37:36.960 [game.script.counter] [trace] counter <sicily_ttc> = 16
    00651777 945.25958252 [2276] 23:38:47.099 [game.script.counter] [trace] counter <sicily_ttc> = 17
    00680658 1009.84881592 [2276] 23:39:51.690 [game.script.counter] [trace] counter <sicily_ttc> = 18
    00725298 1079.71337891 [2276] 23:41:01.556 [game.script.counter] [trace] counter <sicily_ttc> = 19
    00754521 1145.44726563 [2276] 23:42:07.292 [game.script.counter] [trace] counter <sicily_ttc> = 20

    3.Everything apart from AI on (2k+ triggers in EDA and EDCT alone, CAI and faction standings off) -5,67 sec turn time:
    Spoiler Alert, click show to read: 
    02183653 2617.53198242 [660] 00:06:39.408 [game.script.counter] [trace] counter <sicily_ttc> = 70
    02195185 2622.67260742 [660] 00:06:44.548 [game.script.counter] [trace] counter <sicily_ttc> = 71
    02207370 2628.45556641 [660] 00:06:50.332 [game.script.counter] [trace] counter <sicily_ttc> = 72
    02219080 2634.43872070 [660] 00:06:56.315 [game.script.counter] [trace] counter <sicily_ttc> = 73
    02230296 2640.19042969 [660] 00:07:02.066 [game.script.counter] [trace] counter <sicily_ttc> = 74
    02241241 2647.52270508 [660] 00:07:09.399 [game.script.counter] [trace] counter <sicily_ttc> = 75
    02252229 2651.71215820 [660] 00:07:13.589 [game.script.counter] [trace] counter <sicily_ttc> = 76
    02263508 2657.53906250 [660] 00:07:19.415 [game.script.counter] [trace] counter <sicily_ttc> = 77
    02274653 2663.15991211 [660] 00:07:25.037 [game.script.counter] [trace] counter <sicily_ttc> = 78
    02285442 2670.73339844 [660] 00:07:32.610 [game.script.counter] [trace] counter <sicily_ttc> = 79
    02296449 2674.28491211 [660] 00:07:36.162 [game.script.counter] [trace] counter <sicily_ttc> = 80


    4. [Edit: added data] CS only results (898 event monitors, 143 battle-related conditions monitors), I tested with smaller camapign script before, so they can't be directly compared to p.3 - 5,8 sec turn time.
    Spoiler Alert, click show to read: 
    00230821 287.30136108 [2732] 11:15:02.562 [game.script.counter] [trace] counter <sicily_ttc> = 20
    00239634 293.62792969 [2732] 11:15:08.888 [game.script.counter] [trace] counter <sicily_ttc> = 21
    00248864 300.26419067 [2732] 11:15:15.524 [game.script.counter] [trace] counter <sicily_ttc> = 22
    00257878 309.74334717 [2732] 11:15:25.004 [game.script.counter] [trace] counter <sicily_ttc> = 23
    00266655 314.65957642 [2732] 11:15:29.920 [game.script.counter] [trace] counter <sicily_ttc> = 24
    00275256 320.72619629 [2732] 11:15:35.987 [game.script.counter] [trace] counter <sicily_ttc> = 25
    00284844 329.33004761 [2732] 11:15:44.591 [game.script.counter] [trace] counter <sicily_ttc> = 26
    00293691 333.62652588 [2732] 11:15:48.888 [game.script.counter] [trace] counter <sicily_ttc> = 27
    00302454 339.82058716 [2732] 11:15:55.082 [game.script.counter] [trace] counter <sicily_ttc> = 28
    00311104 345.77133179 [2732] 11:16:01.033 [game.script.counter] [trace] counter <sicily_ttc> = 29
    00319704 351.67556763 [2732] 11:16:06.937 [game.script.counter] [trace] counter <sicily_ttc> = 30


    Regards
    Last edited by Germanicu5; November 11, 2011 at 04:27 AM.
    I have no memory of this place.

  3. #3
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    Gigantus, given that each of these 250 if statements only needs to fire once, I would try out individual monitors that terminate. But why aren't you using descr_events?
    Last edited by Taiji; November 11, 2011 at 04:42 AM.

  4. #4
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Multiple monitors or 'If' ?

    Quote Originally Posted by Taiji View Post
    Gigantus, given that each of these 250 if statements only needs to fire once, I would try out individual monitors that terminate. But why aren't you using descr_events?
    It's a 12 turn per year script.

    I was thinking of terminating monitors, but then that would have meant having a lot of monitors hanging around until they eventually would be terminated - the last instance of my calendar script is in round 370.
    I just wasn't sure if the size of that one continuing monitor would be worse then having tons of termintaing monitors.

    In case you were wondering, it's for my 1648 mod.

    Thanks to everyone for their input, particularly for the detailed breakdown of Germanicu5's findings.
    Last edited by Gigantus; November 11, 2011 at 07:09 AM.










  5. #5

    Default Re: Multiple monitors or 'If' ?

    I agree with Taiji that descr_events would probably be better suited for such events that always happen on a specific turn. Unless there is more to it than the example given...
    I also agree with Germanicus that 250 seperate monitors would lag more then 250 if statements in one monitor.

    Well... i didnt add anything new to this discussion...
    ...longbows, in skilled hands, could reach further than trebuchets...

  6. #6
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    250 monitors that have terminated? You really think so?

  7. #7
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    Basically I don't see any impact at all from monitors that do nothing, just as your monitors would almost always do nothing. Whereas an if statement would get processed every turn, and definitely affect performance slightly.

    I'd suggest an if statement for this kind of thing if the possibility existed that multiple events could be firing in the same turn, which it seems they won't with your script. Because when 2 events are fired at once it can cause a CTD.

    So if you're doing other stuff with historic events then the if statement starts to look attractive again.
    Last edited by Taiji; November 11, 2011 at 07:35 AM.

  8. #8
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Multiple monitors or 'If' ?

    Quote Originally Posted by Taiji View Post
    Basically I don't see any impact at all from monitors that do nothing, just as your monitors would almost always do nothing. Whereas an if statement would get processed every turn, and definitely affect performance slightly.

    I'd suggest an if statement for this kind of thing if the possibility existed that multiple events could be firing in the same turn, which it seems they won't with your script. Because when 2 events are fired at once it can cause a CTD.

    So if you're doing other stuff with historic events then the if statement starts to look attractive again.
    You might have noticed the 'campaign_wait' entry in each section - the reason being that there are loads of other historic_events floating around that are not turn dependent, rather event dependent. A quick count gives me 450 historic_events total.










  9. #9
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: Multiple monitors or 'If' ?

    Thanks to everyone for their input, particularly for the detailed breakdown of Germanicu5's findings.
    I was just warming up .

    Here are tests I specifically made for your purpose (and for benefit of future scripting), only CS active.
    1. 140 turns with 1000 if statements launching in 4 monitors:
    if I_TurnNumber = 1-250
    set_event_counter blahblah 1
    end_if
    Total execution time: 527.157 s
    = 3,77 s per turn

    2. 140 turns with 1000 separate monitors that don't get shut:
    monitor_event FactionTurnStart FactionType sicily
    and I_TurnNumber = 1-250
    set_event_counter blahblah 1
    end_monitor
    Total execution time: 715.071 s
    = 5,11 s per turn

    3. 250 turns with 1000 separate monitors that get shut:
    monitor_event FactionTurnStart FactionType sicily
    and I_TurnNumber = 1-250
    set_event_counter blahblah 1
    terminate_monitor
    end_monitor

    Total execution time: 1026.843 s
    = 4,1 s per turn

    As seen here "if" statements are optimal, yet the benefit isn't as huge as expected. Although it'll also depend on when they shut, in my example script 4 were killed each turn until there were none active.

    I'd prefer them for the fact that they contribute to lower script size and better ptansparency\editability, I've had issues with loading huge scripts above 8MB on 2GB RAM machine (or to say simply - MTW ate all memory and didn't load campaign).
    On the other hand - if you want a tidy log file, then using separate monitors isn't that bad.

    We should ofc consider the fact they're the most simple kind of monitors and using more complicated ones instead of "if" statements (or ones that perform checks more often, like CHaracterTurnStart etc) will be more resource-consuming.

    Regards
    Last edited by Germanicu5; November 11, 2011 at 07:42 AM.
    I have no memory of this place.

  10. #10
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    Germanicu5, very interesting info, nice work

    1) Why 4 if monitors and not 1? And what event/s did you use to trigger them?

    1) & 2) Why 140 turns to cover 250 turns in the conditions?

    1), 2) & 3) I appreciate the large sample size, but it might not be necessary. Please would you check how much results differ in this case over 10 turns?

    3) I wonder if triggering and terminating multiple monitors at the same time may perhaps cause more performance loss than individual monitors terminated at different times.

    Really cool info already though, I have to say
    Last edited by Taiji; November 11, 2011 at 11:30 AM.

  11. #11
    Germanicu5's Avatar Will buy spare time...
    Join Date
    Feb 2009
    Location
    Not Zee Germany
    Posts
    2,101

    Default Re: Multiple monitors or 'If' ?

    Ad.1. Since I tested the "monitor event" version with 4 monitors firing at the same time, I did the same for the "if" statements version. So the result is credible.

    I used FactionTurnStart as this is the usual way to fire "if" statements. If we were to fire 1k checks on every character's turn it'd be pointless (unless the only other possible solution would be firing 1k standard monitors).

    Ad.1&2. I did 140 turns on "if" statements and initial monitors version because execution time doesn't change and the same number of checks is performed every turn. Plus I was too lazy to add a script that spawns family members - somehow without it it's possible for family to die out before turn 200.

    Ad. 1.2.3. 10 turns sample isn't enough, the average from more turns shows the big picture better imo - just multiply 4.11 s or whatever by 10. There are some turns that take longer and some take shorter, so either I do 10 tests on 10 turns or one on 100.

    Ad.3. That's not something to worry about imo, but I can perform a test on 1k "if" statements in one file and 1k montors firing at different times. Or 250 distributed among 4 factions.

    Regards

    P.S. I usually test historic events by sticking all I need in cs and fire them all at once, I've never had a CTD.
    Last edited by Germanicu5; November 11, 2011 at 03:48 PM.
    I have no memory of this place.

  12. #12
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    1) Oh I see now, thanks.

    2) Ah, OK, fair enough. It confused me a little, thanks for explaining.

    3) I appreciate that it shows the big picture better, it's more samples afterall. But if the 10 turns varies too much then perhaps enough variation is possible to account for the differing results in time taken. It would be interesting to see if a second batch of tests produces similar differences between times taken.

    4) 4 factions means that the monitors are triggering during the AI turns. I use an if statement at FactionTurnStart FactionIsLocal for firing historic events.

    5) I've fixed intermittent CTD issues by firing the events in an if statement (right at the end). Perhaps there's something missing from your setup that would otherwise conflict.
    Last edited by Taiji; November 11, 2011 at 05:53 PM.

  13. #13
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Multiple monitors or 'If' ?

    Another option could be something like this...

    Code:
    monitor_event FactionTurnStart FactionIsLocal
    
      if I_TurnNumber >= 0
        and I_TurnNumber <= 50
    
        if I_TurnNumber = 0
            campaign_wait 1
            historic_event    1618_01
        end_if
    
        if I_TurnNumber = 1
            campaign_wait 1
            historic_event 1618_01a    event\fenstersturz.bik
        end_if
    
        if I_TurnNumber = 2
            campaign_wait 1
            historic_event 1618_01b
        end_if
    
        if I_TurnNumber = 3
            campaign_wait 1
            historic_event 1618_01c
        end_if
    
        ...
      end_if
    
      if I_TurnNumber > 50
        and I_TurnNumber <= 100
    
        ...
    
      end_if
    
      if I_TurnNumber > 100
        and I_TurnNumber <= 150
    
        ...
    
    
    ...........
    
        if I_TurnNumber = 369
            campaign_wait 1
            historic_event 1648_10
        end_if
    
        if I_TurnNumber = 370
            campaign_wait 1
            historic_event 1648_11
        end_if
    
      end_if
    
    end_monitor
    Although adding more comparisons (two per 'block') only one block's collection of IFs are reached.

    I did this recently in a monitor that had ~1000 IFs and calculated that the number of comparisons was reduced to about 50, including the additional ones. It depends on how big the blocks are of course - I worked it out on a spreadsheet to find the optimum block size.

  14. #14
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Multiple monitors or 'If' ?

    Quote Originally Posted by Withwnar View Post
    It depends on how big the blocks are of course - I worked it out on a spreadsheet to find the optimum block size.
    I found that spreadsheet and ran it with 370 (the number you quoted earlier). The optimum block size is 31; reducing it to 55 comparisons done. Using 30 gives 56 which might be easier to work with (30, 60, 90, ...).

  15. #15
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Multiple monitors or 'If' ?

    Looks a little like those Russian dolls - one inside the next...
    But if it processes only one of the blocks at a time I guess it would help.
    Thanks for the suggestion.










  16. #16
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    If it's one per turn max then you could also use counters to make it stop processing the ifs when it fires one.

  17. #17
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Multiple monitors or 'If' ?

    There is only one 'if' per turn (some turns don't have any) in that monitor.
    Are you suggesting to put 'end_monitor' into each 'if' section?

    Code:
    if I_TurnNumber = 370         
       campaign_wait 1         
       historic_event 1648_11     
       end_monitor
    end_if










  18. #18
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: Multiple monitors or 'If' ?

    Ah nevermind, I was being stupid.
    Last edited by Taiji; November 13, 2011 at 12:11 PM.

  19. #19
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Multiple monitors or 'If' ?

    Just to pop in: with block size you mean how many 'if' sections are included in one?










  20. #20
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Multiple monitors or 'If' ?

    That's right. Each 'block' contains (e.g.) 30 IFs.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •