A bit more work for 1.14

This commit is contained in:
Shane Freeder
2019-04-24 03:34:11 +01:00
parent 43b4755c1b
commit 024f92b2bb
11 changed files with 119 additions and 408 deletions

View File

@@ -12,19 +12,19 @@ Previous implementation did not calculate TPS correctly.
Switch to a realistic rolling average and factor in std deviation as an extra reporting variable
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index df85f35f37..7ca7b9f3ac 100644
index 89ad19e59c..7dfe1f0a3c 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
public org.bukkit.command.ConsoleCommandSender console;
public org.bukkit.command.RemoteConsoleCommandSender remoteConsole;
public ConsoleReader reader;
- public static int currentTick = (int) (System.currentTimeMillis() / 50);
+ public static int currentTick = 0; // Paper - Further improve tick loop
public final Thread primaryThread;
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
public int autosavePeriod;
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
public File bukkitDataPackFolder;
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Spigot start
public static final int TPS = 20;
public static final int TICK_TIME = 1000000000 / TPS;
@@ -33,16 +33,7 @@ index df85f35f37..7ca7b9f3ac 100644
public final double[] recentTps = new double[ 3 ];
public final SlackActivityAccountant slackActivityAccountant = new SlackActivityAccountant();
// Spigot end
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
}
private boolean canSleepForTick() {
- return SystemUtils.getMonotonicMillis() < this.nextTick;
+ return System.nanoTime() - lastTick + catchupTime < TICK_TIME; // Paper - improved "are we lagging" check to match our own
}
// Spigot Start
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
{
return ( avg * exp ) + ( tps * ( 1 - exp ) );
}
@@ -100,16 +91,24 @@ index df85f35f37..7ca7b9f3ac 100644
// Spigot End
public void run() {
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Spigot start
Arrays.fill( recentTps, 20 );
- long lastTick = System.nanoTime(), catchupTime = 0, curTime, wait, tickSection = lastTick, tickCount = 1;
- long curTime, tickSection = SystemUtils.getMonotonicMillis(), tickCount = 1;
+ long start = System.nanoTime(), curTime, wait, tickSection = start; // Paper - Further improve server tick loop
+ lastTick = start - TICK_TIME; // Paper
while (this.isRunning) {
curTime = System.nanoTime();
- wait = TICK_TIME - (curTime - lastTick) - catchupTime;
- long i = (curTime = SystemUtils.getMonotonicMillis()) - this.nextTick;
-
- if (i > 2000L && this.nextTick - this.lastOverloadTime >= 15000L) {
- long j = i / 50L;
-
- if (server.getWarnOnOverload()) // CraftBukkit
- MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
- this.nextTick += j * 50L;
- this.lastOverloadTime = this.nextTick;
+ curTime = System.nanoTime();
+ // Paper start - Further improve server tick loop
+ wait = TICK_TIME - (curTime - lastTick);
+ if (wait > 0) {
@@ -123,12 +122,8 @@ index df85f35f37..7ca7b9f3ac 100644
+ catchupTime = 0;
+ }
+ }
if (wait > 0) {
Thread.sleep(wait / 1000000);
- catchupTime = 0;
- continue;
- } else {
- catchupTime = Math.min(1000000000, Math.abs(wait));
+ if (wait > 0) {
+ Thread.sleep(wait / 1000000);
+ curTime = System.nanoTime();
+ wait = TICK_TIME - (curTime - lastTick);
}
@@ -137,7 +132,7 @@ index df85f35f37..7ca7b9f3ac 100644
+ catchupTime = Math.min(MAX_CATCHUP_BUFFER, catchupTime - wait);
+ if ( ++MinecraftServer.currentTick % SAMPLE_INTERVAL == 0 )
{
- double currentTps = 1E9 / ( curTime - tickSection ) * SAMPLE_INTERVAL;
- double currentTps = 1E3 / ( curTime - tickSection ) * SAMPLE_INTERVAL;
- recentTps[0] = calcTps( recentTps[0], 0.92, currentTps ); // 1/exp(5sec/1min)
- recentTps[1] = calcTps( recentTps[1], 0.9835, currentTps ); // 1/exp(5sec/5min)
- recentTps[2] = calcTps( recentTps[2], 0.9945, currentTps ); // 1/exp(5sec/15min)
@@ -153,15 +148,25 @@ index df85f35f37..7ca7b9f3ac 100644
+ // Paper end
tickSection = curTime;
}
lastTick = curTime;
// Spigot end
- MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
+ //MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit // Paper - don't overwrite current tick time
this.a(this::canSleepForTick);
+ this.a(this::canSleepForTick);
this.nextTick += 50L;
// Spigot end
if (this.T) {
this.T = false;
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
}
private boolean canSleepForTick() {
- return this.bg() || SystemUtils.getMonotonicMillis() < (this.ac ? this.ab : this.nextTick);
+ return System.nanoTime() - lastTick + catchupTime < TICK_TIME; // Paper - improved "are we lagging" check to match our own
}
protected void sleepForTick() {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 351313d98c..7b4af7a904 100644
index a750d8ab5b..423cbd558e 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {