2016-02-29 22:33:06 +01:00
From a3d56cde333f32d169ecb02f997126a45a2b3cbf Mon Sep 17 00:00:00 2001
2015-02-22 02:02:19 +01:00
From: md_5 <git@md-5.net>
Date: Fri, 20 Feb 2015 21:39:31 +1100
Subject: [PATCH] Allow Capping (Tile)Entity Tick Time.
This patch adds world configuration options for max-tick-time.entity / max-tick-time.tile which allows setting a hard cap on the amount of time (in milliseconds) that a tick can consume. The default values of 50ms each are very conservative and mean this feature will not activate until the server is well below 15tps (minimum). Values of 20ms each have been reported to provide a good performance increase, however I personally think 25ms for entities and 10-15ms for tiles would give even more significant gains, assuming that these things are not a large priority on your server.
For tiles there is very little tradeoff for this option, as tile ticks are based on wall time for most things, however for entities setting this option too low could lead to jerkiness / lag. The gain however is a faster and more responsive server to other actions such as blocks, chat, combat etc.
This feature was commisioned by Chunkr.
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2016-02-29 22:33:06 +01:00
index 55468dc..833d5a4 100644
2015-02-22 02:02:19 +01:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2016-02-29 22:33:06 +01:00
@@ -129,6 +129,9 @@ public abstract class World implements IBlockAccess {
private boolean guardEntityList; // Spigot
2015-02-22 02:02:19 +01:00
public static boolean haveWeSilencedAPhysicsCrash;
public static String blockLocation;
+ private org.spigotmc.TickLimiter entityLimiter;
+ private org.spigotmc.TickLimiter tileLimiter;
+ private int tileTickPosition;
2016-02-29 22:33:06 +01:00
public CraftWorld getWorld() {
return this.world;
@@ -163,6 +166,8 @@ public abstract class World implements IBlockAccess {
this.N = worldprovider.getWorldBorder();
this.getServer().addWorld(this.world); // CraftBukkit
timings = new SpigotTimings.WorldTimingsHandler(this); // Spigot - code below can generate new world and access timings
+ this.entityLimiter = new org.spigotmc.TickLimiter(spigotConfig.entityMaxTickTime);
2015-02-22 02:02:19 +01:00
+ this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
}
public World b() {
2016-02-29 22:33:06 +01:00
@@ -1361,7 +1366,12 @@ public abstract class World implements IBlockAccess {
2015-02-22 02:02:19 +01:00
timings.entityTick.startTiming(); // Spigot
guardEntityList = true; // Spigot
// CraftBukkit start - Use field for loop variable
- for (this.tickPosition = 0; this.tickPosition < this.entityList.size(); ++this.tickPosition) {
+ int entitiesThisCycle = 0;
2015-02-27 21:14:00 +01:00
+ if (tickPosition < 0) tickPosition = 0;
2015-02-22 02:02:19 +01:00
+ for (entityLimiter.initTick();
2015-10-07 08:23:59 +02:00
+ entitiesThisCycle < entityList.size() && (entitiesThisCycle % 10 != 0 || entityLimiter.shouldContinue());
2015-02-22 02:02:19 +01:00
+ tickPosition++, entitiesThisCycle++) {
+ tickPosition = (tickPosition < entityList.size()) ? tickPosition : 0;
entity = (Entity) this.entityList.get(this.tickPosition);
// CraftBukkit end
2016-02-29 22:33:06 +01:00
Entity entity1 = entity.by();
@@ -1418,14 +1428,20 @@ public abstract class World implements IBlockAccess {
this.tileEntityListUnload.clear();
2015-02-28 12:36:22 +01:00
}
2015-02-22 02:02:19 +01:00
// CraftBukkit end
2016-02-29 22:33:06 +01:00
- Iterator iterator = this.tileEntityListTick.iterator();
2015-02-22 02:02:19 +01:00
- while (iterator.hasNext()) {
- TileEntity tileentity = (TileEntity) iterator.next();
+ // Spigot start
2016-02-29 22:33:06 +01:00
+ // Iterator iterator = this.tileEntityListTick.iterator();
2015-02-22 02:02:19 +01:00
+ int tilesThisCycle = 0;
+ for (tileLimiter.initTick();
2016-02-29 22:33:06 +01:00
+ tilesThisCycle < tileEntityListTick.size() && (tilesThisCycle % 10 != 0 || tileLimiter.shouldContinue());
2015-02-22 02:02:19 +01:00
+ tileTickPosition++, tilesThisCycle++) {
2016-02-29 22:33:06 +01:00
+ tileTickPosition = (tileTickPosition < tileEntityListTick.size()) ? tileTickPosition : 0;
+ TileEntity tileentity = (TileEntity) this.tileEntityListTick.get(tileTickPosition);
2015-02-22 02:02:19 +01:00
// Spigot start
if (tileentity == null) {
getServer().getLogger().severe("Spigot has detected a null entity and has removed it, preventing a crash");
- iterator.remove();
2015-04-30 21:54:10 +02:00
+ tilesThisCycle--;
2016-02-29 22:33:06 +01:00
+ this.tileEntityListTick.remove(tileTickPosition--);
2015-02-22 02:02:19 +01:00
continue;
}
// Spigot end
2016-02-29 22:33:06 +01:00
@@ -1454,7 +1470,8 @@ public abstract class World implements IBlockAccess {
2015-02-22 02:02:19 +01:00
}
if (tileentity.x()) {
- iterator.remove();
2015-04-30 21:54:10 +02:00
+ tilesThisCycle--;
2016-02-29 22:33:06 +01:00
+ this.tileEntityListTick.remove(tileTickPosition--);
this.tileEntityList.remove(tileentity);
2015-02-22 02:02:19 +01:00
if (this.isLoaded(tileentity.getPosition())) {
2016-02-29 22:33:06 +01:00
this.getChunkAtWorldCoords(tileentity.getPosition()).d(tileentity.getPosition());
2015-02-22 02:02:19 +01:00
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2016-02-29 22:33:06 +01:00
index 8b40760..43242a8 100644
2015-02-22 02:02:19 +01:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2016-02-29 22:33:06 +01:00
@@ -281,4 +281,13 @@ public class SpigotWorldConfig
2015-02-22 02:02:19 +01:00
{
hangingTickFrequency = getInt( "hanging-tick-frequency", 100 );
}
+
+ public int tileMaxTickTime;
+ public int entityMaxTickTime;
+ private void maxTickTimes()
+ {
+ tileMaxTickTime = getInt("max-tick-time.tile", 50);
+ entityMaxTickTime = getInt("max-tick-time.entity", 50);
+ log("Tile Max Tick Time: " + tileMaxTickTime + "ms Entity max Tick Time: " + entityMaxTickTime + "ms");
+ }
}
diff --git a/src/main/java/org/spigotmc/TickLimiter.java b/src/main/java/org/spigotmc/TickLimiter.java
new file mode 100644
index 0000000..23a3938
--- /dev/null
+++ b/src/main/java/org/spigotmc/TickLimiter.java
@@ -0,0 +1,20 @@
+package org.spigotmc;
+
+public class TickLimiter {
+
+ private final int maxTime;
+ private long startTime;
+
+ public TickLimiter(int maxtime) {
+ this.maxTime = maxtime;
+ }
+
+ public void initTick() {
+ startTime = System.currentTimeMillis();
+ }
+
+ public boolean shouldContinue() {
+ long remaining = System.currentTimeMillis() - startTime;
+ return remaining < maxTime;
+ }
+}
--
2016-02-29 22:33:06 +01:00
2.5.0
2015-02-22 02:02:19 +01:00