• Advertisement
Sign in to follow this  

When do I save the buffer data?

This topic is 1002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My entire game is server side and I use nodejs with mysql
 
When players connect or join a game, their player data (Items, Stash, Quests, etc) all get stored into the memory buffer.  
 
For example, if a player joins a game and there are 40 items on the floor and he decides to pick them all up, it's easier just to add that to their Inventory object instead of using a `insert` statement each time. Then, when that user disconnects I can save all that data respectively. (Now that I think of it, that query would run 40 insertion rows..)
 
  That's the problem I have though, do I save the data during the looting process or wait until the player disconnects and run a `db update` to save their memory buffer (only the changed buffer) to the database?
 
The Issue I have with that is, if a player picks up over 40 items in the game, that's going to be a lot of sql insertions when they disconnect.. 
 
Imagine them finding a ton of items from mobs and having a huge amount of new updated buffer data that needs to be stored.. (after they disconnect), that would be a dreadful update. Especially if they stored hundreds of items in their stash or whatnot. Hmmm.
 
 ayUVw.gif
Edited by WombatTurkey

Share this post


Link to post
Share on other sites
Advertisement

What if many people play like 10 hours or even let the game running for weeks while they are afk and then your server crashes? They wont be happy loosing all their progress.

Or someone drops an item, his buddy collects it and immediately logs out, while the first intentionally lets the game running until you are doing maintenance and stop the server? Sounds like an easy way to cheat and dupe rare items.

Before you engage in premature optimization you better do it in the simplest and safest possible way that works (save everything immediately), then measure if its really too slow and optimize as needed.

 

Yeah, you bring up a great point. I have no idea why I didn't think of that.  

 

I think when the loot is dropped from a monster, all that item data will be stored in the buffer (as it is now), but only 'WHEN', a player loots it, I will insert it into the items table serverside.  Great post, thank you!

 

Edit: I kept thinking I should stay away from mysql because players will be picking up and dropping items like crazy, and a ton of stuff is sent across the pipes in the nodejs/ws server. But now that I think of it after your post, it has to be done.  MYSQL is going to be slammed hard, but it's the only way really. Good thing I have MYSQL pooling laugh.png

 

 

I have never done that level of coding on the web but i think it would be best to try to keep your real data storage (mysql) updated as often as possible. So if mouse eats on the server cable you have as much as possible saved. So i vote for wintertime's suggestion of saving immediately. If it does not work try to do a timed update that runs once every 30 seconds or so to save the player data.

 

Hmm strange, the vote arrows are gone from the posts for me unsure.png.

 
Same here, was going to add to his rep!
Edited by WombatTurkey

Share this post


Link to post
Share on other sites

 

Hmm strange, the vote arrows are gone from the posts for me unsure.png.

 
Same here, was going to add to his rep!

 

 
That's because he posted it to the Lounge, where voting is disabled. A moderator will probably move it to a more fitting, technical forum, when the arrows will be re-enabled.

Edited by Oluseyi
Trim quotes

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement