Optimally saving user data [MySQL]
#1

Currently, I use MySQL account system (r39-2) in the traditional way. You load user data into variables when he connects, and send an UPDATE query when he disconnects.

Sometimes, the server might crash, be DDoSed or whatsoever. I don't want to lose users' data and have a rollback.
What would be the optimal way to solve this?

Saving users' stats every X amount of time?
Updating the MySQL entry whenever the variable changes?

P.S. I have an additional question. Is it okay to use mysql_pquery when OnGameModeExit is called? I'm afraid that the server will shutdown before all threaded queries are executed.
Reply
#2

Saving users' stats every X amount of time

this one

save it every let's see 1 minute or 30 seconds

and about gamemodeexit thing I think it maybe safe just try
Reply
#3

You could use y_timers or just the native timer function, then make a loop within the timer function that saves the player information the same way you would in OnPlayerDisconnect.
Reply
#4

Save the users who are logged in every 5-10 minutes or so.

and then request a save when they disconnect or timeout

That way not much data is lost when the server goes down. and shouldn't cause massive stress to the server

(i do mine every 5 minutes)
Reply
#5

Okay, I'll probably set a ptask with y_timers so the save won't be at the same time for all players
Reply
#6

Trigger the save to be global i.e not each for players that can cause stress to the database with all the open connections happening over time.

If you just trigger it once per 5-10 minutes to those logged in you should be fine as the disconnect should catch those who logout before / after the interval
Reply
#7

Quote:
Originally Posted by Eth
Посмотреть сообщение
Saving users' stats every X amount of time

this one

save it every let's see 1 minute or 30 seconds

and about gamemodeexit thing I think it maybe safe just try
Every 1 minute or 30 seconds!?! With MySQL?!? For EVERY Users?!? I would recommend you extend this to arond every 5 - 10 minutes. It's less server load, thus less stress on the network, server, and the machine itself.

No one's going to care if they loose 5 - 10 minutes of game play.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)