Most efficient way to save data into mysql database?

Discussion in 'Plugin Development' started by Ahmet094, Jan 28, 2013.

Thread Status:
Not open for further replies.
  1. Hey,

    I'm working on a Team Deathmatch plugin at the moment and almost finished it.
    Now it's time to implement MySQL for webstats etc, which I should have done till the beginning, because now it's a lot of work to recode the whole 3.000 lines.. anyways.

    However.. my question is if it's faster/more efficient to keep the player stats (kills, points they get during the match) until the end in a config and then insert them into the database when resetting the map and porting all the players to the lobby OR instantly insert the datas into the database when a kill happens.

    Sorry for the bad explaining..

    Thanks in advance!
     
  2. It depends on if you want real time stats to appear on the site.
    If not, it's more efficient to keep records in memory, then when a match ends start a Runnable to write out to MySQL.

    Couple of things to improve MySQL performance, from my experience writing BeardStat.

    1) Have write out in a seperate thread, so other game tasks can run concurrently, and slow connection to the database will not cause timeouts for players.
    2) Create prepared statements once, then reuse them, prepared statements are quicker if used multiple times rather than instantiating them on each write.
    3) Use the add/clear/execute batch commands to run prepared statements multiple times with different data, this cuts down the overhead of communicating with the MySQL server.
     
  3. Thanks for your informativ answer!
    I'll test different things out when I'm home again. Currently in the bus...
     
Thread Status:
Not open for further replies.

Share This Page