SQL being super slow?

Discussion in 'Plugin Development' started by ImDeJay, Dec 27, 2013.

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

    ImDeJay

    Hi, I've just started working on adding SQL to my plugin, and only testing on my home server for right now.

    When i start the server, i watch console and it hangs on "[myPlugin] Enabling myPlugin v1.4"

    then when getting data from database from in-game, it hangs for like 3 seconds before the data shows.
    then when it finally does show i get the error
    Code:
    [19:24:39 WARN]: Can't keep up! Did the system time change, or is the server ove
    rloaded? Running 3238ms behind, skipping 64 tick(s)
    Is this because im doing this from my home connection?
    is it because im using a free database and maybe their servers are slow?(freesqldatabase.com)

    if neither of the above, what could be hanging the server?
     
  2. Offline

    1Rogue

    How many rows is your database? What sql operation are you doing when your server lags? Try providing some code.
     
  3. Offline

    Chlorek

    Do not call any queries and do not make connections from main thread. Use scheduled task to avoid lags and cache all data instead of reading/writing to the database all the time.
     
  4. Offline

    ImDeJay


    as of right now only 1 row. as i am only testing atm

    on server startup im doing a create table if not exists

    when i issue command i am doing a select statement.

    here is the code im running when i issue the command

    Code:
    try{
     
    ResultSet rs = sql.query("SELECT `kills` FROM `my_data` WHERE playername='dejay'");
    rs.next();
     
    int k = rs.getInt("kills");
     
    rs.close();
     
    return k;
     
    }catch(SQLException ex){
     
    ex.printStackTrace();
     
    }
    this is the code i am running at startup

    Code:
                try {
               
               sql.query("CREATE TABLE IF NOT EXISTS `my_data` (playername VARCHAR(17), kills INT, deaths INT, streak INT)");
                        
                } catch (Exception ex) {
               
                        ex.printStackTrace();
                        
                        this.logError(ex.getMessage());
                        
                        Bukkit.getPluginManager().disablePlugin(this);
                        return;
                }
     
  5. Offline

    Dread9Nought

    Always perform all MySQL operations asynchronously. (means on a different thread)
     
  6. Offline

    ImDeJay


    is that why it is lagging when i try to get data?

    how do i fix this?
     
Thread Status:
Not open for further replies.

Share This Page