Lag when teleporting to random locations

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

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

    jojodmo

    Whenever I have a player teleport to a random location, using:

    Code:java
    1. final Chunk c = l.getChunk();
    2.  
    3. l.getWorld().getChunkAt(c.getX() - 1, c.getZ()).load();
    4. l.getWorld().getChunkAt(c.getX() - 1, c.getZ() - 1).load();
    5. l.getWorld().getChunkAt(c.getX(), c.getZ() - 1).load();
    6. l.getWorld().getChunkAt(c.getX() + 1, c.getZ()).load();
    7. l.getWorld().getChunkAt(c.getX() + 1, c.getZ() + 1).load();
    8. l.getWorld().getChunkAt(c.getX(), c.getZ() + 1).load();
    9. l.getWorld().getChunkAt(c.getX() - 1, c.getZ() + 1).load();
    10. l.getWorld().getChunkAt(c.getX() + 1, c.getZ() - 1).load();
    11. l.getWorld().refreshChunk(c.getX(), c.getZ());
    12.  
    13. c.load();
    14. p.teleport(l);
    15.  


    Even when I wait 10 seconds before teleporting, to allow the chunks to load. The server freezes for about 7 seconds after they teleport, and you cant run any commands. Even when I use refreshChunk(), It still happens. I get no errors in console, and the teleported player just sees the void for about 7 seconds.

    This only happens when teleporting to a location that no other players have teleported to before.
    Also, the server doesn't lag when I load the chunks, only when the player teleports.
    So, how can I fix this? Do I have to make a longer wait time? Do I have to change how I load chunks?

    Thanks!
     
  2. Offline

    EcMiner

    Maybe your server can't handle the loading of new chunks? Usually when you teleport someone to a chunk that's not loaded it starts loading it and it lags the server, but with decent servers it shouldn't freeze the server for 10 seconds... I know this is not really helping but I do think it's something you should check.
     
  3. Offline

    jacklin213

    jojodmo Are you purposely teleporting players by loading chunks? if not there is an easier way of teleporting players to a random location
     
  4. Offline

    jojodmo

    I have 24 gb of ram on the server, and it's hosted on a detected server with 4 quad-core intel xeons... So I don't think it's that :)

    I teleport them to a random location by getting a random location, loading the chunk the location is in, and all of the chunks around it (corners around it, and directly around it), then waiting 10 seconds and teleporting the player (not waiting using java's wait() methods)

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

    jojodmo

    Buuuuummmpppp
     
  6. Offline

    fireblast709

    jojodmo post the code you use to wait
     
  7. Offline

    jojodmo

    I'm using the bukkit SyncDelayedTasks, not the java wait methods
     
  8. Offline

    jojodmo

    Bump b = new Bump();
    b.execute();
    b.close();
     
  9. Offline

    Shevchik

    Ofc it freezes the server, you are loading 9 chunks sync, don't expect it to be fast.
     
  10. Offline

    xepisolonxx

    jojodmo If yoor using Thead.sleep() that can be a promblem and are you sure its not client lag.
     
  11. Offline

    fireblast709

    xepisolonxx he is using Bukkit's scheduler to delay it, not sleep
     
  12. Offline

    jojodmo

    Even when I try loading 1 chunk it still gets the same amount of lag...
     
  13. Offline

    xepisolonxx

  14. Offline

    jojodmo

    Ok I'll try that

    It's a little bit better, but it still freezes the server for about 5 seconds now, instead of 7...

    while(true){
    System.out.println("bump");
    }

    Whoops I just created an infinite loop...

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

    teej107

    Code:java
    1. while(false){
    2. System.out.println("bump");
    3. }
    4.  
    5. Whoops I just created an infinite loop...

    Fixed it xD
     
  16. Offline

    jojodmo

    Why thank you :p

    You wouldn't happen to know anything about fixing the lag would you?
     
  17. Offline

    teej107

    jojodmo To be honest, I don't have a straight answer but timing between loading the chunk and teleporting the player is the key. I've played on a couple servers where I see players teleport individually instead of all at once and I don't see any chunk loading issues on them when I get tp'd. You may try to check when the chunk finished loading and then teleport the player.
     
  18. Offline

    jojodmo

    Ok, I'll do that.
     
  19. Offline

    teej107

    There may be a better solution out there too but this has been a problem for me too.
     
  20. Offline

    Shevchik

    Just stop loading chunks before teleporting player. Why are you doing it anyway?
     
  21. Offline

    jojodmo

    Because if I don't load the chunks it freezes for a lot longer

    Also, the server doesn't freeze when the chunks are loaded, only when the player teleports.

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

    _LB

    What's the bandwidth of the server? It doesn't matter if the server is running futuristic alien technology from the year 2307, if you don't have a decent bandwidth you're going to experience connection lag.
     
  23. Offline

    Jozeth

    Yeah I agree with you, as .refreshChunk() resends the chunk to everyone online.
     
  24. Offline

    jojodmo

    50/90 up/down (in MB/s... Not KB/s :p)

    _LB Jozeth The thing is, the server still doesn't lag when the chunks load, it's only when the player teleports... It's not connection lag either... Try reading the OP :)

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

    xTrollxDudex

    jojodmo
    Does just the server freeze or just the client freeze? Or do both? What's your client bandwidth?
     
  26. Offline

    jojodmo

    The server freezes, as it says in the OP...
     
  27. Offline

    xTrollxDudex

    jojodmo
    Just making sure it wasn't client sided. Try async loading?
     
  28. Offline

    jojodmo

    But the thing is, the server doesn't lag when the chunks are loaded, only when the player is teleported...
     
  29. Offline

    _LB

    Please explain exactly how you know that the server lags/freezes. What are the symptoms and how are you checking?
     
  30. Offline

    jojodmo

    What do you mean by "exactly how the server freezes"? The server just stops responding to commands for about 7 seconds... The symptoms are that the server doesn't respond for 7 seconds... I'm checking by being on the server when it happens...
     
Thread Status:
Not open for further replies.

Share This Page