Tuned CPU usage on main lop and RakLib

This commit is contained in:
Shoghi Cervantes 2014-07-09 23:39:25 +02:00
parent 9604907566
commit 5b69f07a55
3 changed files with 16 additions and 17 deletions

View File

@ -1743,15 +1743,15 @@ class Server{
$this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"'); $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 //if(Utils::getOS() === "win"){ //Workaround less usleep() waste
$this->tickProcessorWindows(); // $this->tickProcessorWindows();
}else{ //}else{
$this->tickProcessor(); $this->tickProcessor();
} //}
$this->forceShutdown(); $this->forceShutdown();
} }
private function tickProcessorWindows(){ /*private function tickProcessorWindows(){
$lastLoop = 0; $lastLoop = 0;
while($this->isRunning){ while($this->isRunning){
foreach($this->interfaces as $interface){ foreach($this->interfaces as $interface){
@ -1763,14 +1763,14 @@ class Server{
if(($ticks = $this->tick()) !== true){ if(($ticks = $this->tick()) !== true){
++$lastLoop; ++$lastLoop;
if($lastLoop > 128){ if($lastLoop > 8){
usleep(1000); usleep(1000);
} }
}else{ }else{
$lastLoop = 0; $lastLoop = 0;
} }
} }
} }*/
public function checkTicks(){ public function checkTicks(){
if($this->getTicksPerSecond() < 12){ if($this->getTicksPerSecond() < 12){
@ -1884,17 +1884,16 @@ class Server{
} }
$this->generationManager->handlePackets(); $this->generationManager->handlePackets();
++$lastLoop;
if(($ticks = $this->tick()) !== true){ if(($ticks = $this->tick()) !== true){
++$lastLoop; if($lastLoop > 2 and $lastLoop < 16){
if($lastLoop > 16 and $lastLoop < 128){
usleep(200);
}elseif($lastLoop < 512){
usleep(400);
}else{
usleep(1000); usleep(1000);
}elseif($lastLoop < 128){
usleep(2000);
}else{
usleep(10000);
} }
}else{
$lastLoop = 0;
} }
} }
} }

View File

@ -107,7 +107,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{
} }
public function process(){ public function process(){
$this->interface->handlePacket(); return $this->interface->handlePacket();
} }
public function closeSession($identifier, $reason){ public function closeSession($identifier, $reason){

@ -1 +1 @@
Subproject commit 740c96f033322d99e8804bb1a0218abef0ef117a Subproject commit 85237bba6b6290397f2e1346587518437b96933b