MySQL effienct queries

Discussion in 'Plugin Development' started by TehVoyager, Apr 14, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    I can connect to a MySQL Database fine and can execute queries but I am planning on making a Kit-PvP server where every kill a Stored Procedure is called but I believe it would lag the server to make a call every 15 seconds or so. What would be the best way to optimize this / have minimum lag.
    - Thank You.​


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 7, 2016
  2. Offline


    TehVoyager You don't necessarily have to execute a statement every time a player gets a kill. You could create a class, lets call it StatsSession. It would store kills, deaths and whatever else you want. Make a hashmap with the key being a string (for the UUID) and the value being a StatsSession object. When a player joins the server, you'd create the instance of StatsSession for the player who joined and load whatever you need into there. Then, when they get a kill or get killed you'd just increase the kill or death integer by 1. When they quit, save the data to the database and remove the StatsSession instance from the hashmap.

    This way you only have to do 1 query when a player joins and 1 statement when they leave rather than 1 statement every 15 seconds or whatever.
  3. Offline


    This is actually what I do on my server, it works fairly well and keeps the database server from getting congested. But either way, you would need some serious amounts of queries to be happening to cause lag on your server, but ultimately preventative measures can be made to reduce the chances of that even happening.
Thread Status:
Not open for further replies.

Share This Page