mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
Optimized server sleep times
This commit is contained in:
parent
09428bc8c7
commit
c71689a919
@ -129,7 +129,6 @@ class Server{
|
||||
private $nextTick = 0;
|
||||
private $tickAverage = [20,20,20,20,20];
|
||||
private $useAverage = [20,20,20,20,20];
|
||||
private $inTick = false;
|
||||
|
||||
/** @var \AttachableThreadedLogger */
|
||||
private $logger;
|
||||
@ -1840,7 +1839,7 @@ class Server{
|
||||
|
||||
$this->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "checkTicks"]), 20 * 5);
|
||||
|
||||
$this->logger->info("Default game type: " . self::getGamemodeString($this->getGamemode())); //TODO: string name
|
||||
$this->logger->info("Default game type: " . self::getGamemodeString($this->getGamemode()));
|
||||
|
||||
$this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"');
|
||||
|
||||
@ -1937,17 +1936,8 @@ class Server{
|
||||
private function tickProcessor(){
|
||||
$lastLoop = 0;
|
||||
while($this->isRunning){
|
||||
++$lastLoop;
|
||||
|
||||
if(($ticks = $this->tick()) !== true){
|
||||
if($lastLoop > 2 and $lastLoop < 16){
|
||||
usleep(1000);
|
||||
}elseif($lastLoop < 128){
|
||||
usleep(2000);
|
||||
}else{
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
$this->tick();
|
||||
usleep((int) max(1, ($this->nextTick - microtime(true)) * 1000000));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2028,8 +2018,7 @@ class Server{
|
||||
/**
|
||||
* Tries to execute a server tick
|
||||
*/
|
||||
public function tick(){
|
||||
if($this->inTick === false){
|
||||
private function tick(){
|
||||
$tickTime = microtime(true);
|
||||
if($tickTime < $this->nextTick){
|
||||
return false;
|
||||
@ -2037,23 +2026,20 @@ class Server{
|
||||
|
||||
Timings::$serverTickTimer->startTiming();
|
||||
|
||||
$this->inTick = true; //Fix race conditions
|
||||
++$this->tickCounter;
|
||||
|
||||
$this->checkConsole();
|
||||
|
||||
//TODO: move this to tick
|
||||
Timings::$connectionTimer->startTiming();
|
||||
foreach($this->interfaces as $interface){
|
||||
$interface->process();
|
||||
}
|
||||
|
||||
|
||||
Timings::$connectionTimer->stopTiming();
|
||||
|
||||
Timings::$schedulerTimer->startTiming();
|
||||
$this->scheduler->mainThreadHeartbeat($this->tickCounter);
|
||||
Timings::$schedulerTimer->stopTiming();
|
||||
|
||||
$this->checkTickUpdates($this->tickCounter);
|
||||
|
||||
if(($this->tickCounter & 0b1111) === 0){
|
||||
@ -2084,7 +2070,4 @@ class Server{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user