can I use asyncTask instead of repeating? because I have a task that use repeating(run a command every 2 minutes) and i'm getting too much lag. This is my result of timings : Code: 0.03% 276.86% 0.14 s 138.43 ms 0.0 0.0k Task: cd\Tasks\ResetAll(interval 24000) 0.02% 116.81% 0.12 s 58.40 ms 0.0 0.0k Task: cd\Tasks\ClearLagg(interval 2400) Main onEnable: PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(new ResetAll($this), 1200 * 20); $this->getServer()->getScheduler()->scheduleRepeatingTask(new ClearLagg($this), 120 * 20); ClearLagg.php PHP: <?phpnamespace cd\Tasks;use pocketmine\Server;use pocketmine\scheduler\PluginTask;use pocketmine\utils\TextFormat as TF;use pocketmine\command\CommandExecuter;use pocketmine\command\ConsoleCommandSender;use cd\Main;class ClearLagg extends PluginTask { public function __construct(Main $plugin){ parent::__construct($plugin); $this->plugin = $plugin; } public function onRun($tick){ $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender, "clearlagg clear"); }} resetall's basically the same
no you can't simply put. (I am too tired to explain why, and you wouldn't understand it anyways) Just remember: ASYNC TASKS DO NOT JUST MAGICALLY GIVE INFINITE PERFORMANCE But instead of "Clearing Lagg" (I call it creating Lagg) You can simply prevent any entities from getting spawned with the help of events. and what does ResetAll do?
yea, that's just going to give you a small lag spike every 20mins. 130ms is no problem every 20min. For your ClearLagg task, do what I said.
and all other entities. just cancel all https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/event/entity/EntitySpawnEvent.php (Except if the entity is a player)
will that cancel players from throwing items on the ground? if it will i can't really do that because players throw items on the ground to give it to someone else
If the task randomly exactly executes during the time they throw items on the ground they will be gone too.
MineReset does something totally different. It uses a complicated way of chunk manipulation, not simply calling normal API methods. See @falk's blog for more details: http://blog.falkirks.com/setting-huge-areas-of-blocks
To prevent lag, you have to truly investigate where the source of lag comes from, not just blindly throw everything to AsyncTask. For example, to set a large area of blocks, you have to notice that the main lag comes from encoding a lot of block updates, and investigate how to prevent this lag (compress the block update packets in an AsyncTask and batch them, or just send the whole chunk compressed). Some things like sending packets inevitably have to be done on the main thread, so you have to figure out how to do the other things asynchronously, which requires quite a lot of hacking (and instability). You also have to pay attention to the cost of transferring data between threads. It can be quite costly, because all data have to be replicated to be sent from a thread to another.