SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/12/2016, 12:01 AM   #1
BiosMarcel
High-roller
 
BiosMarcel's Avatar
 
Join Date: Jul 2012
Location: Germany
Posts: 1,232
Reputation: 225
Smile Performance Question , Per Player Timer vs Timer that loops through all players

Hello,

So, i have a Log script, it offers you to log each players location every X seconds. When a player spawns it sets a timer that will log the location of the player and repeat that until he dies or disconnects. I have been wondering what the differences in memory usage and overall performance are if i would use a global timer that loops through all players.Is anyone able to share his/her knowledge, would be great to know.

And if anyone wonders why i don't test it myself, i can't, because i ain't got no players to test it with D:

greetings Marcel
__________________
BiosMarcel is offline   Reply With Quote
Old 11/12/2016, 12:24 AM   #2
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,943
Reputation: 360
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Per player timer will be created at your will which means it will be created at login/register(?) and killed at disconnect(?). A global timer will have to do a check to see if there is any player online and then if he is not dead and if he is registered/logged(?) so it really use any performance data already to make checking.( not really extreme waste but whatever). I may be wrong.
vassilis is offline   Reply With Quote
Old 11/12/2016, 12:28 AM   #3
BiosMarcel
High-roller
 
BiosMarcel's Avatar
 
Join Date: Jul 2012
Location: Germany
Posts: 1,232
Reputation: 225
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Yeah that is right, but i was wondering how much just the running of the timer matters, let us say there is 1000 player timers running, doesn't that affect the server (ast least the memory consumption??)?
__________________
BiosMarcel is offline   Reply With Quote
Old 11/12/2016, 12:30 AM   #4
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,943
Reputation: 360
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Quote:
Originally Posted by [Bios]Marcel View Post
Yeah that is right, but i was wondering how much just the running of the timer matters, let us say there is 1000 player timers running, doesn't that affect the server (ast least the memory consumption??)?
It doesn't really depends on how many timers you have but how often you use it I mean if you have 1000 timers that are used every 1 second then good luck.BOOM.
vassilis is offline   Reply With Quote
Old 11/12/2016, 12:31 AM   #5
BiosMarcel
High-roller
 
BiosMarcel's Avatar
 
Join Date: Jul 2012
Location: Germany
Posts: 1,232
Reputation: 225
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Well, that's exactly why i am worried
__________________
BiosMarcel is offline   Reply With Quote
Old 11/12/2016, 12:38 AM   #6
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,943
Reputation: 360
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Quote:
Originally Posted by [Bios]Marcel View Post
Well, that's exactly why i am worried
Also do not forget that if you make a global timer it MUST be killed when server closes until next restart. So imagine already how much damage you can done with one global timer that checks every 2 seconds without any reason(no player online?/everyone is dead?/no one registered-logged?). At least per player will be killed everytime player disconnects so its more efficient.
vassilis is offline   Reply With Quote
Old 11/12/2016, 12:40 AM   #7
BiosMarcel
High-roller
 
BiosMarcel's Avatar
 
Join Date: Jul 2012
Location: Germany
Posts: 1,232
Reputation: 225
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

I don't really get what you mean, the tiemr doesn't live longer than the server does, ofcause.
And running isn't really a problem, because if there is no players anyways, no one will need the servers power.
But what actually might be an interesting idea, is switching from per player timers to a global timer when a certain amount of online players ahs been reached, so i could balance it.
__________________
BiosMarcel is offline   Reply With Quote
Old 11/12/2016, 12:44 AM   #8
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,943
Reputation: 360
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Quote:
Originally Posted by [Bios]Marcel View Post
I don't really get what you mean, the tiemr doesn't live longer than the server does, ofcause.
And running isn't really a problem, because if there is no players anyways, no one will need the servers power.
But what actually might be an interesting idea, is switching from per player timers to a global timer when a certain amount of online players ahs been reached, so i could balance it.
Tell me how you will check if any player is online to use a global timer? YOU WILL NEED ANOTHER TIMER ALREADY or use the same one to check is anyone is online. So both ways you will use timer for no reason if there is no player online.
vassilis is offline   Reply With Quote
Old 11/12/2016, 12:54 AM   #9
BiosMarcel
High-roller
 
BiosMarcel's Avatar
 
Join Date: Jul 2012
Location: Germany
Posts: 1,232
Reputation: 225
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Pretty easy, no timer needed

PHP Code:
new players 0;

onConnnect()
{
    
players++;
}

onDisconnect()
{
    
players--;

anyways, i'd still like to hear a professional opinion, no offense
__________________
BiosMarcel is offline   Reply With Quote
Old 11/12/2016, 01:16 AM   #10
vassilis
High-roller
 
vassilis's Avatar
 
Join Date: Nov 2009
Location: Greece,Athens
Posts: 1,943
Reputation: 360
Default Re: Performance Question , Per Player Timer vs Timer that loops through all players

Quote:
Originally Posted by [Bios]Marcel View Post
Pretty easy, no timer needed

PHP Code:
new players 0;

onConnnect()
{
    
players++;
}

onDisconnect()
{
    
players--;

anyways, i'd still like to hear a professional opinion, no offense
That is a very amateur way. Anyway, since you need a professional answer. Your answer is Per player Timer.
Global timer will take time to execute FOR ALL PLAYERS and it night cause sync problem. Per player timers are smaller chopped timers so it will reduce sync problems. However, there are more posts like yours on forums and you should check them
Apologizing for writing in a hurry but I am from phone.
Hope I helped cheers.
vassilis is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is better Per Player Timer or Global timer? (issue with timer) Dokins Scripting Help 4 07/06/2016 09:50 AM
Question about timer for a player. Stoyanov Scripting Help 2 23/09/2015 07:26 PM
Timer i all players to one player? Admigo Scripting Help 11 25/08/2012 10:03 PM
timer for all players? Evation Scripting Help 4 30/05/2012 03:01 AM
A timer that loops through all players or a timer for each player? x-cutter Help Archive 2 28/05/2011 03:35 PM


All times are GMT. The time now is 01:42 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.