1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Server Lag ! Help

Discussion in 'Development' started by Bluzzi, Dec 7, 2017.

  1. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Hey, I have a faction server that is very often filled 100/100 connected players, I want to know if there was a way to strongly optimize the server because it lag a lot with everything it's player !

    Hum, and here is also a message that appears quickly, when I reboot the server:
    [Server thread/WARNING]: Can't keep up! Is the server overloaded ?

    Thank you for your help, I did my best to optimize it... But it's not enough :(

    Eh and I'm sorry for my bad English I'm French :rolleyes:
     
  2. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    1. That message is basically just saying that the server is lagging.
    2. Try reducing the number of plugins.
    3. Add more RAM to your server if possible.
    4. Reduce the number of connected players.
    How many plugins do you have installed?
     
    EdwardHamHam and XCodeMCPE like this.
  3. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    My players do not like when they have to wait too long to join the server that's why I leave the number of players to 100, the server never uses all his ram, the only plugins I use his "Plugins (7): DevTools v1.12.7, BuycraftPM v0.2.1, FactionCore v3.5, KitsAPI v1, MagicWE v0.2.1, Worlds v1, Factions v1" the biggest and most used its done by myself, you want me to send you the result of a timings?
     
  4. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Yes, please send the timings.
     
  5. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
  6. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    FactionsCore v3.5 seems to be causing the most trouble. Here is the entire diagnostic for the FactionsCore v3.5:
    Code:
    FactionCore v3.5 Total: Pct:
       Pct Total    Pct Tick       Total          Avg     PerTick         Count        Event
           2.04%       6.22%      5.57 s         3.11 ms     4.5           8.1k        Core\Events::onMove(PlayerMoveEvent)
           1.55%      14.95%      4.21 s         7.48 ms     0.3           0.6k        Core\Events::EditLootAndPoint(BlockBreakEvent)
           0.81%     294.91%      2.21 s       147.45 ms     0.0           0.0k        Task: Core\Tasks\ChestFinder(interval 60)
           0.44%       1.33%      1.19 s         0.66 ms     4.5           8.1k        Core\Events::moveNoel(PlayerMoveEvent)
           0.30%     184.58%      0.83 s        92.29 ms     0.0           0.0k        Core\Events::onJoin(PlayerJoinEvent)
    ChestFinder (Look at the 294.91% Tick) is using up the most resources. I assume you made FactionsCore, in which case you need to do something to fix whatever ChestFinder is doing. Maybe stop checking for chests so frequently.
     
  7. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    I will try to optimize this function, even if I do not know how to do it otherwise, but I have already tried to disable it a few days, and there is no difference, the lagger server still !

    If you have an idea to do otherwise my ChestFinder:
    PHP:
        public function onRun(int $tick){
            
    $level $this->plugin->getServer()->getLevelByName("world");
            
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $players){
                
    $chest 0;
                
                foreach(
    $level->getTiles() as $t){
                    if(
    $t instanceof Chest){
                        if(
    $players->distance($t) <= 50){
                            
    $chest++;
                        }
                    }
                }

                if(
    $players->getInventory()->getItemInHand()->getId() == 347){
                    if(
    $chest === 0){
                        
    $players->sendPopup("§9-§f Il y a §caucun§f coffre autours de vous §9-");
                    } else {
                        
    $players->sendPopup("§9-§f Il y a §a{$chest}§f coffre autours de vous §9-");
                    }
                }
            }
        }
     
  8. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Try disabling it, restarting the server, and doing the timings again. Then I will see what it says is using up the resources.
     
    Last edited: Dec 7, 2017
    Awzaw likes this.
  9. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
  10. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    Hey, to optimize your code you should check if the player has the item in hand first then look for close chests. It will improve your performance when there is a lot of connected players.

    Here is what I made :
    PHP:
    public function onRun(int $tick){
            
    $level $this->plugin->getServer()->getLevelByName("world");
           
            foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $player){

                if(
    $player->getInventory()->getItemInHand()->getId() == 347){
                    
    $chest 0;
                   
                    foreach(
    $level->getTiles() as $t){
                        if(
    $t instanceof Chest){
                            if(
    $player->distance($t) <= 50){
                                
    $chest++;
                            }
                        }
                    }

                    if(
    $chest === 0){
                        
    $player->sendPopup("§9-§f Il y a §caucun§f coffre autours de vous §9-");
                    } else {
                        
    $player->sendPopup("§9-§f Il y a §a{$chest}§f coffre autours de vous §9-");
                    }
                   
                }
            }
        }
    I think you can even further optimize it by saving the position of chests the first time you execute the code in an array.
     
  11. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    Hit me up with a dm on twitter if you need help to optimize more your server :)
     
  12. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    You could additionally try reducing the view-distance in server.properties (if not already done).
     
    Bluzzi likes this.
  13. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    i was gonna say that ^
    Don't try to set it lower than 4 or it's gonna mess up player's chunk loading(gameplay) !
     
  14. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you should also just use the select/hold item event over a task
    why? because you dont want to be scanning irrelevant players every X tick that's utter waste

    you can cache the result, so you dont go chest scanning every time by doing on a $cache = [lvname=>[vec,vec2]]
    all vecs are just chest positions(so you dont need to differentiate chests with other tiles)

    you can calculate it by
    foreach $cache[levelname] as vec{
    if player->distance(vec) < 50
    chests++
    }

    and recalculate/refresh it every 30min/1 hour etc by doing

    by doing this(below) on a task and make sure it's long enough period to prevent lag
    foreach $enabledlevels as $lvname{
    $lv = getlvbyname($lvname)
    $chests=[]
    foreach $lv->getTiles() as $tile{
    if $tile instance of Chest
    $chests[]=$tile(since tile is instance of vector3)
    }
    $cache[$lvname] = $chests;
    }
    also adding a cooldown(but please implement it correctly by NOT using a task to manage the cooldown use time() to do it) even a 60 sec deter people who have malicious intents while keeping it reasonable(or just make 1 min for guest, 40 sec for vip 20 sec for mvp (NEVER 0 second))
    so i cant lag your server by spamming chest

    use the profile private messages please
     
  15. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    i use whatever i want and..
    PHP:
    //next time use php format
     
    Levi likes this.
  16. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    okay? i mean you can be more helpful to just do it here then twitter/pm as it allow others to help themself
    but i use whatever i want
    and that includes not using php format because it's NOT php, it's at best pseudo PHP
     
  17. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    1- We are talking about Private messages and they can be done anywhere + he's a friend since 2016.
    2- Edwardthedog2 you need to stop liking every Verified person's post fr.
     
  18. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    That really wasn't necessary, but I liked those posts because I agree with them. Plus @Thunder33345 is actually trying to help.
     
  19. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you should just initiate a private message wherever you can without posting here if you already know eachother
     
    EdwardHamHam and HimbeersaftLP like this.
  20. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Back on topic: Did you solve the problem @Bluzzi ?
     
    Thunder33345 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.