From 5b69f07a556e47fbcb2c809cafb3a7a1ab75dee1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 9 Jul 2014 23:39:25 +0200 Subject: [PATCH] Tuned CPU usage on main lop and RakLib --- src/pocketmine/Server.php | 29 +++++++++++----------- src/pocketmine/network/RakLibInterface.php | 2 +- src/raklib | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 1cbe48aad..50c150358 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1743,15 +1743,15 @@ class Server{ $this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"'); - if(Utils::getOS() === "win"){ //Workaround less usleep() waste - $this->tickProcessorWindows(); - }else{ + //if(Utils::getOS() === "win"){ //Workaround less usleep() waste + // $this->tickProcessorWindows(); + //}else{ $this->tickProcessor(); - } + //} $this->forceShutdown(); } - private function tickProcessorWindows(){ + /*private function tickProcessorWindows(){ $lastLoop = 0; while($this->isRunning){ foreach($this->interfaces as $interface){ @@ -1763,14 +1763,14 @@ class Server{ if(($ticks = $this->tick()) !== true){ ++$lastLoop; - if($lastLoop > 128){ + if($lastLoop > 8){ usleep(1000); } }else{ $lastLoop = 0; } } - } + }*/ public function checkTicks(){ if($this->getTicksPerSecond() < 12){ @@ -1884,17 +1884,16 @@ class Server{ } $this->generationManager->handlePackets(); + ++$lastLoop; + if(($ticks = $this->tick()) !== true){ - ++$lastLoop; - if($lastLoop > 16 and $lastLoop < 128){ - usleep(200); - }elseif($lastLoop < 512){ - usleep(400); - }else{ + if($lastLoop > 2 and $lastLoop < 16){ usleep(1000); + }elseif($lastLoop < 128){ + usleep(2000); + }else{ + usleep(10000); } - }else{ - $lastLoop = 0; } } } diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index d5dd84e91..b45df878b 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -107,7 +107,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ } public function process(){ - $this->interface->handlePacket(); + return $this->interface->handlePacket(); } public function closeSession($identifier, $reason){ diff --git a/src/raklib b/src/raklib index 740c96f03..85237bba6 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 740c96f033322d99e8804bb1a0218abef0ef117a +Subproject commit 85237bba6b6290397f2e1346587518437b96933b