Author Topic: How bad are Pseudo HB's?  (Read 2470 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
How bad are Pseudo HB's?
« on: June 23, 2011, 05:22:32 pm »


               Ok, I have 600 areas.


Is there any manageable way to Assign a function to fire on each of them, without it eating too much cpu time or lagging.


I already have looped through all my areas on mod load, and have stored an object reference on the Module to each area.

eg

GetAreaByResRef(string sResRef)    // ResRef's are unique, tags are not.

which basically gets

object oModule = GetModule();
return GetLocalObject(oModule,sResRef+"_ar");


I would like to add a pseudo hb to each area, to allow modifications to climate, earthquakes etc and other funky stuff.


Im jus worrying that if I do this, then a Pseudo HB would technically result in 600 Scripts trying to run at the same time?

How would you recommend me doing this?
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #1 on: June 23, 2011, 06:20:33 pm »


               My recommendation would be to start the pseudo hb in the OnAreaEnter script and then check for the presence of PCs in the OnAreaExit script.  If PCs are found, continue the hb, otherwise exit it.

That way you're only using the hb in the areas that matter- where the PCs are.  Even in the largest PW's, that's probably a dozen or so areas at any one point in time- far less than the 600 in your world.

My opinion is that they're in general as bad as a hb script if left unchecked.  The benefit of them is that you can turn them on/off only as needed.

Hope that helps.

Hope that helps.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #2 on: June 23, 2011, 09:06:34 pm »


               

Baaleos wrote...

Im jus worrying that if I do this, then a Pseudo HB would technically result in 600 Scripts trying to run at the same time?

No this is how normal heartbeats works. Pseudo heartbeats runs only at certain circumstances/with higher delay which is what saves resources.

Anyway to your question, pseudo-hbs are more CPU intensive and may even cause memory leak if not done properly. If you got only few variables/instructions then you are perfectly safe with recursive function, if your script is more complex then you should use ExecuteScript command on the same script in conjuction with DelayCommand.
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #3 on: June 23, 2011, 09:27:06 pm »


               Our module is over 1200 areas atm and thanks to clean lean code every step of the way, has no issues with lag/crash/required resets. It _CAN_ be done, just be a mizer with resources as you go, simplify as much as you can.

Be well. Game on.
GM_ODA
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #4 on: June 24, 2011, 01:18:22 am »


               ShaDoOoW's answer is essentially correct. There's NO WAY you want pseudos running in all your areas at once, or even one to cover all areas - they're roughly five times as cpu intensive as heartbeats. If you really must loop all areas every so often, use the mod hearbeat, but by far the more probable scenario is that you only need them running in an area when the player is there. If that's the case, you would fire them off onenter the area, and terminate them when there are no longer pcs in the area.

If you describe in more detail what you're doing, I can offer more specific advice. Also, check to make sure that GetResRef works on areas - it didn't use to, and it still doesn't according to the 1.69 lexicon, but I THINK it was changed in 1.67 or later to work. I can't easily tell because the old forums are down, and the post I remember on the topic isn't showing in the Omnibus.

Funky
               
               

               


                     Modifié par FunkySwerve, 24 juin 2011 - 12:18 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #5 on: June 24, 2011, 02:16:58 am »


               Why not just write one script for handling the areas, and put it in the onheartbeat of each area. You can control the script to skip processing if no one is in the area, also you can limit its processing further if you index your heartbeats each minute.

Example: you have 10 heartbeats per minute. Iterate a tick count for each mod heartbeat, and store this tick on the mod. when it is greater than 10, subtract 10 from the number. You can then limit your heartbeats according to which HB tick you are on. If it is not the right tick, don't run run script. Basically this could limit your HB script to run only once a minute when a player is present. You can also use this system to stagger your HB processes in different areas, so not all of your areas get prcessed on the same HB tick. Store a local int on the area that identifies which index for the area HB to run.
               
               

               


                     Modifié par henesua, 24 juin 2011 - 01:18 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #6 on: June 24, 2011, 03:24:02 am »


               Because that's an enormous waste of cpu.

Funky
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #7 on: June 24, 2011, 02:48:38 pm »


               Explain. I've got a 1000 area mod and this has almost no impact on it.
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #8 on: June 24, 2011, 03:06:56 pm »


               What I do for weather, is instead of looping through all areas, I loop through all PCs and use the area they're in. I also set a variable on the area to mark what its weather should be, and only change it if the current settings don't match the variable on it. That way time is not wasted applying weather effects to empty areas, and I don't do it multiple times if the area has multiple players in it.

Although, this is made much easier cos I only use a single weather setting for the whole world at once, but I think logic based around where players are rather than all areas is the way to go regardless.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #9 on: June 24, 2011, 04:06:44 pm »


               

henesua wrote...

Explain. I've got a 1000 area mod and this has almost no impact on it.


It should be fairly obvious. You wind up with a ton of hearbeat scripts firing to no purpose. Even if you end them right away, based on variable or pc presence, you're still wasting a ton of executions. There's just no good reason to do it this way, when there are solutions that are just as simple and result in far fewer scripts firing. The fact that this additional load has yet to push your server's total load into the 'unacceptable' realm, is not really relevant, even anecdotally.

Funky
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #10 on: June 24, 2011, 04:09:17 pm »


               

_six wrote...

What I do for weather, is instead of looping through all areas, I loop through all PCs and use the area they're in. I also set a variable on the area to mark what its weather should be, and only change it if the current settings don't match the variable on it. That way time is not wasted applying weather effects to empty areas, and I don't do it multiple times if the area has multiple players in it.

Although, this is made much easier cos I only use a single weather setting for the whole world at once, but I think logic based around where players are rather than all areas is the way to go regardless.

Bingo. This is another smart way of accomplishing this. I still prefer firing pseudos from area enter, but a lot of my reasoning is specific to my own module (we have pseudo-handy behavior in a lot of areas, and already have a set of universal area entry and exit scripts).

Funky
               
               

               
            

Legacy_Khuzadrepa

  • Sr. Member
  • ****
  • Posts: 347
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #11 on: June 24, 2011, 04:51:42 pm »


               I also agree that from a resource perspective, it's definitely way more efficient to only have it executing where players are.
Sixes, are you doing yours on heartbeat, or doing it from a pseudo?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #12 on: June 24, 2011, 04:59:50 pm »


               

Khuzadrepa wrote...

I also agree that from a resource perspective, it's definitely way more efficient to only have it executing where players are.
Sixes, are you doing yours on heartbeat, or doing it from a pseudo?

My assumption was that he was doing that from the module heartbeat. If you're only going to use one for everything modwide, you definitely want it in a heartbeat, because it'll have to run continuously. It'll mean wasted code when no one is an an area that needs special treatment, but not all that much (any exterior area has weather, after all, if we look at sixs' usage). That IS one disadvantage of doing it this way, as opposed to area-based pseudos, but a reletively minor one. By contrast, using a pseudoheartbeat instead of the mod heartbeat would chew up roughly 5 times the cpu, because it would have to run constantly, and because pseudos chew up roughly 5 times the cpu, based on some benchmarking I did a number of years ago (I'd link the old forum post if I could). You only want to use them when the psuedo in question will only be running 20% of uptime or less. Obviously, that's going to vary from script to script - I just use it as a rule of thumb.

Funky
               
               

               


                     Modifié par FunkySwerve, 24 juin 2011 - 04:01 .
                     
                  


            

Legacy_Khuzadrepa

  • Sr. Member
  • ****
  • Posts: 347
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #13 on: June 24, 2011, 05:06:53 pm »


               Gotcha. That's what I was thinking, but he didn't specify from where it was being executed, so I wanted to be sure.
Both approaches seem to be excellent ways to get this done. It's giving me a lot to think about...
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How bad are Pseudo HB's?
« Reply #14 on: June 24, 2011, 06:44:59 pm »


               I believe the heartbeat event runs for each area regardless of whether you apply a script to a particular event. Anyone have evidence to the contrary?