Improves server ticking.

As I was lying in my bed, I came to a solution for the tick problem.
While remembering how most of the time the server is sleeping,
and how the TPS drops once costly operations are ticked,
I reviewed mentally that part of the code, Server::tick().

Then I saw it: I was setting the next execution time
using the time after it was executed as the base, but it should
have been done using the tick start time - that way if something takes
longer, the server will catch up and won't drop the TPS
until the CPU hits its limit.

I got up, got to my computer, and checked that function.
It was exactly as I saw in a near-dream state, so I fixed it
and tested things if they worked right.

Now I'm fully awake and I can't sleep anymore, so I wrote this.
This commit is contained in:
Shoghi Cervantes 2014-09-04 00:55:25 +02:00
parent ba08bfaa45
commit 352497d88c

View File

@ -2057,15 +2057,16 @@ class Server{
}
}
$this->tickMeasure = (($time = microtime(true)) - $this->tickTime);
$this->tickTime = $time;
$this->nextTick = 0.05 * (0.05 / max(0.05, $this->tickMeasure)) + $time;
$this->inTick = false;
Timings::$serverTickTimer->stopTiming();
TimingsHandler::tick();
$time = microtime(true);
$this->tickMeasure = ($tickTime - $this->tickTime);
$this->tickTime = $time;
$this->nextTick = $tickTime + 0.05;
$this->inTick = false;
return true;
}