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
That message is basically just saying that the server is lagging. Try reducing the number of plugins. Add more RAM to your server if possible. Reduce the number of connected players. How many plugins do you have installed?
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?
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.
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-"); } } } }
Try disabling it, restarting the server, and doing the timings again. Then I will see what it says is using up the resources.
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.
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) !
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
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
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.
That really wasn't necessary, but I liked those posts because I agree with them. Plus @Thunder33345 is actually trying to help.
you should just initiate a private message wherever you can without posting here if you already know eachother