MySQL query lags server

Discussion in 'Plugin Development' started by jacklin213, Jul 12, 2014.

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

    jacklin213

    Hey guys was wonder if it is possible to reduce the weight of mysql querry's on a server. I currently have an import command for a plugin which transfers a .yml file into mysql database. It causes a ridiculous amount of lag ATM while running the querry. Any idea's guys?
     
  2. Offline

    Rocoty

    My guess is that you are running the query on the main thread, which then has to wait for a response, blocking the server in the process. But this is just a guess, since there is no way I could know as you did not post any code.
     
    Dealyise likes this.
  3. Offline

    Dealyise

    jacklin213
    Exactly what Rocoty said, I also bet that you execute your queries through the main thread, better run them in a Async Scheduler and you should be fine.
    Otherwise, do it like me:
    Store their player data in a file when they log in and upload it again to the Database when they log out or when plugin gets disabled.
    That one is a lightweight solution and will prevent lags.
     
  4. Offline

    Rocoty

    Dealyise Yes, that works. But would still block the server unless it is run in a thread asynchronous from the main one.

    Got me thinking though: Maybe your way of doing it is not as reliable as you think? Think about what would happen if the server crashes while the player is online. Data will be lost.
     
  5. Offline

    jacklin213

    is there a tutorial on how to run the queries async
     
  6. Offline

    Dealyise

    jacklin213
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(YourPluginInstance, new Runnable(){
    2.  
    3.  
    4. @Override
    5. public void run() {
    6. //your queries here.
    7. }
    8. },1);
    9.  


    There you go.
     
  7. Offline

    jacklin213


    Does that do this ?
     
  8. Offline

    Dealyise

  9. Offline

    jacklin213

    hmmm the documentation says that method is deprecated
     
  10. Offline

    Dealyise

    jacklin213
    True, when I remember correctly they want to change the scheduler threads. But I am not sure.
    Anyway, this should fix your problem. I don't have any lags.
     
  11. Offline

    jacklin213

    hmm is there anyway to speed up the process eg) executing 2 queries to import the data
     
Thread Status:
Not open for further replies.

Share This Page