Question considering script lenght -
||123|| - 03.11.2012
I don't know why but whenever I script something advanced in my gamemode I always get worried that it will make my server lag :/ I'm not sure what causes server lagging, and I'll be pretty happy if someone told me that large scripts don't make servers lag. I want to know, what can I do to minimize the cause of server lagging. And what's the difference between lagging and high ping. Please be brief, thank you.
Re: Question considering script lenght -
RehLoccz - 03.11.2012
Ping is different to lag, So other words.
Like just say you host your server in America, And a person from New Zealand, joins, they will get high ping this is because they are more far than the host. But if you disable ping then it doesn't matter, and if you have a maximum ping like 1000. anybody above 1000 would be kick.
Lag is caused for gang of cars on top, like a car bugger. or something, it piles alot of cars, and it causes alot of server lag, for exactly where it is.
Thank if i helped, or ask if i can detail that.
Re: Question considering script lenght -
||123|| - 03.11.2012
I'm not talking about game lag. I'm talking about web based lag. Lag in sending recieving packets, is it something other than ping speed?
Re: Question considering script lenght -
Vince - 03.11.2012
Larger scripts naturally use up more resources, but if you manage them well you shouldn't have problems. Just don't put a shitload of things in OnPlayerUpdate.
Re: Question considering script lenght -
||123|| - 03.11.2012
Quote:
Originally Posted by Vince
Larger scripts naturally use up more resources, but if you manage them well you shouldn't have problems. Just don't put a shitload of things in OnPlayerUpdate.
|
I hate putting useless things there, it's useless. I'd rather make a short timer, and destroy it when it's not needed anymore.
Anyway, what about if my script is about 70k lines. How little or big will it affect. I just want to know for my mind's peace sake.
Re: Question considering script lenght -
Drake_Lopez - 04.11.2012
The script could actually make servers lag!
Re: Question considering script lenght -
Drake_Lopez - 04.11.2012
If it's very big it takes much CPU usage..
Re: Question considering script lenght -
thimo - 04.11.2012
Dont use too big strings....
Re: Question considering script lenght -
Babul - 04.11.2012
reading a MC Donalds Menu wont take that long as reading a Phone Book. it needs more time to be read cause its longer. a longer script takes more CPU time to complete than a short one - as long each command gets executed 1 single time - for programing, this is not really valid, due to algorithms (executing commands on a iterative/recursive base):
my gamemode is close to 18000 lines, but regardless of the players/npcs amount logged in, despite if theyre spamming commands/chat, and using approx. 10 timers: its not lagging (using 5-6% CPU constantly), this leaves 94% for other scripts to run. (like fireworks using another 10%, or another 60% for the pathfinding)
all those ms/percentual estimations are the most vital part of checking for server lag - if a timer (its function being ececuted) takes longer to complete than its set interval, THEN your server will "lag", not being able to perform tasks like detecting players entering pickups/checkpoints (will drive through them), commands will get processed with the mentioned delay (which will sum up!).
heres a little snippet which you should NOT try to run:
Код:
for(new IterA=0;IterA<1000;IterA++){
for(new IterB=0;IterB<1000;IterB++){
for(new IterC=0;IterC<1000;IterC++){
}
}
}
... pay attention to the loops intervals: each loop got set to 1000 times to repeat. due to the loops are nested, the required iterations are 1000*1000*1000 = 1000000000. this will cause some seconds lag if you add that into a command,
while this wont lag at all:
Код:
for(new IterA=0;IterA<1000;IterA++){
}
for(new IterB=0;IterB<1000;IterB++){
}
for(new IterC=0;IterC<1000;IterC++){
}
...3 loops with 1000 iterations each, but NOT nested, this means linear runtime - 3000 iterations needed..
compare those 2 variants' runtime, its 1000000000/3000= 333333 x faster - the script got the same lenght btw: 6 lines. the difference between scripting the first/second method, are best described as:
first = fail/lag/crash
second = success
edit: i forgot to mention 2 invaluable plugins:
JIT Compiler and
Performance profiler