Avoiding the cause of lag
#1

Which is the best way to make the players info get updated with a timer?
I have set a timer of 5seconds for saving players info/stats but i am pretty sure it will cause lagging at the future with more players on testing. How many seconds or minute, should i put on timer to save stats ?
Reply
#2

Instead of a timer, you can save player data when they have done something needs to be saved and when they disconnected. Also you can save all player data in every 30min or 1h will probably enough.
Reply
#3

None. Update immediately as and when it is needed. There are certain exceptions, such as stuff that gets updated very frequently (distance traveled and such) which can be saved every n calls to the function, e.g.:

PHP код:
public OnPlayerUpdate()
{
    static 
updateCount[MAX_PLAYERS];
    
    if(++
updateCount[playerid] > 1000)
    {
        
SaveTheStuff(playerid);
        
updateCount[playerid] = 0;
    }
    
    
PlayerInfo[playerid][pDistance] += GetDistanceTravelled(...);
    
// ...
    
return 1;

Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
None. Update immediately as and when it is needed. There are certain exceptions, such as stuff that gets updated very frequently (distance traveled and such) which can be saved every n calls to the function, e.g.:

PHP код:
public OnPlayerUpdate()
{
    static 
updateCount[MAX_PLAYERS];
    
    if(++
updateCount[playerid] > 1000)
    {
        
SaveTheStuff(playerid);
        
updateCount[playerid] = 0;
    }
    
    
PlayerInfo[playerid][pDistance] += GetDistanceTravelled(...);
    
// ...
    
return 1;

My script is saving player position so he gets spawned at the last position he was before death.
Any method to change the way i am working it ?
Reply
#5

Quote:
Originally Posted by vassilis
Посмотреть сообщение
My script is saving player position so he gets spawned at the last position he was before death.
Any method to change the way i am working it ?
You don't really need anything saved until the player logs out. So put most of your saving under OnPlayerDisconnect. But for important stuff like money and VIP level and admin level save them as soon as they are updated for example at the end of your makeadmin command if you have one make it save the data. And a 5 minutes timer to save everything should be enough. I have been doing that for years now and I never experienced any lag even when my server reached around 60 players. I also never lost any data more than a few minutes old even through some of the worst DDOSes we experienced.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)