Completely unloading a PIDed script?

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
User avatar
Damien White
Journeyman Poster
Posts: 68
Joined: Tue Aug 18, 2009 6:34 pm

Completely unloading a PIDed script?

Post by Damien White »

I tried looking around in a few sources and could not figure this out, please if anyone has any ideas or a post to dirrect me to...

I have a charm animal subscript (startscript), I want to launch from scrolls, wands, etc. Each time it is run to completetion, is the script fully unloaded from the server? Or does the Pid need to be unlaoded for that instance to be fully unloaded?

So if I run the charmed script 5000 times, without unloading it, do I need to the be unloading the subscript.

So in another case. If say I have a script, that is constantly running in the background. Like a hunger script. Regularly making players hungrier and hungrier. Then I want to startscript("dizzy"). Which might last 10 seconds before completetion. At it's end, will it be completely unloaded, or does the server hold onto a residue of memory or code? If it does, can I unload the Pid to flush it?

code
code
code

subscript := startscript("dizzy");

code
code
code

unload_pid(subscript); <---- ???

BTW - I do know about Unload_Scripts(scriptname := ""), but I don't want to unload all instances of this script, just the specific IDs.



Just curious, thanks in advance
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm

Re: Completely unloading a PIDed script?

Post by Yukiko »

From what I know the server keeps one cached copy of a script when it is run and does not load a new copy each time it gets called again. In otherwords if you call a script 5000 times POL will only load it into RAM once. POL will then call the cached script for each instance. So you don't have a build-up of 4999 extra copies of the same script eating RAM.
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

Re: Completely unloading a PIDed script?

Post by Gnafu »

Yukiko is right, the only thing you can do to reduce server load is to unload the rarely-used-scripts from memory.
If you plan to use a script 5000 times, it's better for you to keep it loaded to memory.
(Performance tip: if your shard uses more than one map, and there are some of them often empty, try setting "mapserver file" instead of "mapserver memory" in the realm.cfg of the empty ones)

I think a script istance is automatically "unloaded" when it ends it's execution, like any other application using a garbage collector. If it's not, the pol will explode in a few seconds just by having all the istances of the startup scripts still there.

Try to launch this and look the output:

File "script1.src"

Code: Select all

use os;
program dummy
  // do some useless stuff here, just be sure it ends in a few seconds
  var dummy = 12345;
  sleep(3);
endprogram
File "main.src"

Code: Select all

use os;
program main
  var s := start_script("script1");
  // let's look at the script !
  print("The PID is" + s.pid);
  print("status" + s.state);
  // waiting the script to end
  // (you can use while(s){}; but it's not a good idea)
  sleep(5);
  print("The PID is" + s.pid);
  print("status" + s.state);
endprogram
PS: unloading scripts is usefull when updating scripts without restarting the server, just recompile and unload the script, the new image will be loaded at the next call..
User avatar
Damien White
Journeyman Poster
Posts: 68
Joined: Tue Aug 18, 2009 6:34 pm

Re: Completely unloading a PIDed script?

Post by Damien White »

THanks to everyone for the feedback! You guys are awesome!
Post Reply