mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +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 $nextTick = 0;
|
||||||
private $tickAverage = [20,20,20,20,20];
|
private $tickAverage = [20,20,20,20,20];
|
||||||
private $useAverage = [20,20,20,20,20];
|
private $useAverage = [20,20,20,20,20];
|
||||||
private $inTick = false;
|
|
||||||
|
|
||||||
/** @var \AttachableThreadedLogger */
|
/** @var \AttachableThreadedLogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
@ -1840,7 +1839,7 @@ class Server{
|
|||||||
|
|
||||||
$this->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "checkTicks"]), 20 * 5);
|
$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 "?"');
|
$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(){
|
private function tickProcessor(){
|
||||||
$lastLoop = 0;
|
$lastLoop = 0;
|
||||||
while($this->isRunning){
|
while($this->isRunning){
|
||||||
++$lastLoop;
|
$this->tick();
|
||||||
|
usleep((int) max(1, ($this->nextTick - microtime(true)) * 1000000));
|
||||||
if(($ticks = $this->tick()) !== true){
|
|
||||||
if($lastLoop > 2 and $lastLoop < 16){
|
|
||||||
usleep(1000);
|
|
||||||
}elseif($lastLoop < 128){
|
|
||||||
usleep(2000);
|
|
||||||
}else{
|
|
||||||
usleep(10000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2028,8 +2018,7 @@ class Server{
|
|||||||
/**
|
/**
|
||||||
* Tries to execute a server tick
|
* Tries to execute a server tick
|
||||||
*/
|
*/
|
||||||
public function tick(){
|
private function tick(){
|
||||||
if($this->inTick === false){
|
|
||||||
$tickTime = microtime(true);
|
$tickTime = microtime(true);
|
||||||
if($tickTime < $this->nextTick){
|
if($tickTime < $this->nextTick){
|
||||||
return false;
|
return false;
|
||||||
@ -2037,23 +2026,20 @@ class Server{
|
|||||||
|
|
||||||
Timings::$serverTickTimer->startTiming();
|
Timings::$serverTickTimer->startTiming();
|
||||||
|
|
||||||
$this->inTick = true; //Fix race conditions
|
|
||||||
++$this->tickCounter;
|
++$this->tickCounter;
|
||||||
|
|
||||||
$this->checkConsole();
|
$this->checkConsole();
|
||||||
|
|
||||||
//TODO: move this to tick
|
|
||||||
Timings::$connectionTimer->startTiming();
|
Timings::$connectionTimer->startTiming();
|
||||||
foreach($this->interfaces as $interface){
|
foreach($this->interfaces as $interface){
|
||||||
$interface->process();
|
$interface->process();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Timings::$connectionTimer->stopTiming();
|
Timings::$connectionTimer->stopTiming();
|
||||||
|
|
||||||
Timings::$schedulerTimer->startTiming();
|
Timings::$schedulerTimer->startTiming();
|
||||||
$this->scheduler->mainThreadHeartbeat($this->tickCounter);
|
$this->scheduler->mainThreadHeartbeat($this->tickCounter);
|
||||||
Timings::$schedulerTimer->stopTiming();
|
Timings::$schedulerTimer->stopTiming();
|
||||||
|
|
||||||
$this->checkTickUpdates($this->tickCounter);
|
$this->checkTickUpdates($this->tickCounter);
|
||||||
|
|
||||||
if(($this->tickCounter & 0b1111) === 0){
|
if(($this->tickCounter & 0b1111) === 0){
|
||||||
@ -2084,7 +2070,4 @@ class Server{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user