mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 03:55:14 +01:00
a65fedb3f8
IIRC, the main item I was driving towards was a consequence of persistent passive mobs - specifically, the fact that allowing a population limit of N (independent of view distance, which is what vanilla does) when your view distance limits actual loaded chunks to a much smaller area than default (say a view of 4, which would be 9 x 9 chunks loaded per player - and spawnable - versus default, which is 8 radius spawn, or 17 x 17 chunks) tends to result in more mobs per chunk. For persistent mobs, this is bad - since they count for server load and for population just by being loaded, versus being despawned beyond 128 blocks (8 chunk radius - unconditional of view distance, as well) - so they can cause the population limit to be reached more easily, cutting off spawning nearer to players. The goal was to make it so that the mobs-per-loaded-chunk was about the same for all view distances, versus having low view distances cause higher mob concentrations. Now, all of this assumes that loaded chunks beyond those around players are modest (since they could contain passive mobs that would count towards the limits) - which they should be, except that recent CBs leak chunks like mad, from what I can see (chunk-gc has become more required than optional), and I think there may be some issues with even hostile mobs "lurking" around - possibly even after their chunks are unloaded. Anything that causes more mobs to be in places players don't see them is going to drive population limit issues, and resulting low spawn behaviors. The trick for us, trying to make big servers as practical as possible, is to shift the math the other way - given low view distances, how to best make sure that folks get reasonable spawn behavior while minimizing the time/resources spent on the server on mobs that don't help that. Realistically, I think we need to analyse the mob demographics better - especially as it relates to lower view distances (our changes have no net impact on view distances above 7) - particularly to understand how the proportion of "useful" mobs is working out (ones close enough to players to be considered contributing to game play). One thought is to manage the population limit based on mobs that are 'tickable' - if they aren't close enough to be ticking, they aren't interesting. This is likely a big issue for view distance 5 folks, since mobs cannot spawn closer than 24 (approx 1 chunk radius, given that middle chunk is 0), and don't tick when any of the chunks within a 2 chunk radius aren't loaded) - so, effectively, they "live" within a zone of 7 x 7 with the middle 3 x 3 removed (so, about 40 chunks) out of a total load zone of 11 x 11 (121) - so about 2/3 of the area containing mobs has idle mobs. Normal view distance would result in mobs ticking as far out as they can spawn (radius 8 versus a load radius of 11), so 100% of the mobs that spawn are ticking when they spawn, and all hostile mobs that are loaded are ticking (since they always despawn beyond 128 blocks / 8 chunks from a player). One interesting thought would be to limit the chunks we spawn mobs in to those where they would be ticking initially (that is, view-distance minus 2 or 3).
330 lines
15 KiB
Diff
330 lines
15 KiB
Diff
From 944da35dce1c28a62ac3b019ae791d2ce20b6648 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Thu, 10 Jan 2013 00:18:11 -0500
|
|
Subject: [PATCH] Add Custom Timings to various points
|
|
|
|
---
|
|
.../net/minecraft/server/ChunkProviderServer.java | 4 ++++
|
|
.../java/net/minecraft/server/EntityLiving.java | 21 +++++++++++++++++++++
|
|
.../java/net/minecraft/server/PlayerConnection.java | 7 +++++++
|
|
src/main/java/net/minecraft/server/World.java | 9 +++++++++
|
|
src/main/java/net/minecraft/server/WorldServer.java | 4 ++++
|
|
.../java/org/bukkit/event/WorldTimingsHandler.java | 20 ++++++++++++++++++++
|
|
6 files changed, 65 insertions(+)
|
|
create mode 100644 src/main/java/org/bukkit/event/WorldTimingsHandler.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
index c0bab0f..279ba9e 100644
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
@@ -15,6 +15,7 @@ import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
|
|
import org.bukkit.craftbukkit.util.LongHash;
|
|
import org.bukkit.craftbukkit.util.LongHashSet;
|
|
import org.bukkit.craftbukkit.util.LongObjectHashMap;
|
|
+import org.bukkit.event.CustomTimingsHandler;
|
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
|
// CraftBukkit end
|
|
|
|
@@ -28,6 +29,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
|
public boolean forceChunkLoad = false; // true -> false
|
|
public LongObjectHashMap<Chunk> chunks = new LongObjectHashMap<Chunk>();
|
|
public WorldServer world;
|
|
+ static private CustomTimingsHandler syncChunkLoadTimer = new CustomTimingsHandler("syncChunkLoad"); // Spigot
|
|
// CraftBukkit end
|
|
|
|
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) {
|
|
@@ -103,6 +105,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
|
// CraftBukkit end
|
|
|
|
if (chunk == null) {
|
|
+ syncChunkLoadTimer.startTiming(); // Spigot
|
|
chunk = this.loadChunk(i, j);
|
|
if (chunk == null) {
|
|
if (this.chunkProvider == null) {
|
|
@@ -141,6 +144,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
|
// CraftBukkit end
|
|
|
|
chunk.a(this, this, i, j);
|
|
+ syncChunkLoadTimer.stopTiming(); // Spigot
|
|
}
|
|
|
|
// CraftBukkit start - If we didn't need to load the chunk run the callback now
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
index 7d2e633..b2481aa 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
@@ -8,6 +8,7 @@ import java.util.Random;
|
|
|
|
// CraftBukkit start
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.event.CustomTimingsHandler;
|
|
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
|
@@ -110,6 +111,14 @@ public abstract class EntityLiving extends Entity {
|
|
public int expToDrop = 0;
|
|
public int maxAirTicks = 300;
|
|
public int maxHealth = this.getMaxHealth();
|
|
+ // Spigot Start
|
|
+ public static CustomTimingsHandler timerEntityBaseTick = new CustomTimingsHandler("** entityBaseTick");
|
|
+ public static CustomTimingsHandler timerEntityAI = new CustomTimingsHandler("** entityAI");
|
|
+ public static CustomTimingsHandler timerEntityAIJump = new CustomTimingsHandler("** entityAIJump");
|
|
+ public static CustomTimingsHandler timerEntityAIMove = new CustomTimingsHandler("** entityAIMove");
|
|
+ public static CustomTimingsHandler timerEntityAILoot = new CustomTimingsHandler("** entityAILoot");
|
|
+ public static CustomTimingsHandler timerEntityTickRest = new CustomTimingsHandler("** entityTickRest");
|
|
+ // Spigot End
|
|
// CraftBukkit end
|
|
|
|
public EntityLiving(World world) {
|
|
@@ -505,6 +514,7 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
|
|
public void j_() {
|
|
+ timerEntityBaseTick.startTiming(); // Spigot
|
|
super.j_();
|
|
if (!this.world.isStatic) {
|
|
int i;
|
|
@@ -531,7 +541,9 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
}
|
|
|
|
+ timerEntityBaseTick.stopTiming(); // Spigot
|
|
this.c();
|
|
+ timerEntityTickRest.startTiming(); // Spigot
|
|
double d0 = this.locX - this.lastX;
|
|
double d1 = this.locZ - this.lastZ;
|
|
float f = (float) (d0 * d0 + d1 * d1);
|
|
@@ -622,6 +634,7 @@ public abstract class EntityLiving extends Entity {
|
|
|
|
this.world.methodProfiler.b();
|
|
this.aD += f2;
|
|
+ timerEntityTickRest.stopTiming(); // Spigot
|
|
}
|
|
|
|
// CraftBukkit start - delegate so we can handle providing a reason for health being regained
|
|
@@ -1228,6 +1241,7 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
|
|
public void c() {
|
|
+ timerEntityAI.startTiming(); // Spigot
|
|
if (this.bV > 0) {
|
|
--this.bV;
|
|
}
|
|
@@ -1279,9 +1293,11 @@ public abstract class EntityLiving extends Entity {
|
|
this.az = this.yaw;
|
|
}
|
|
}
|
|
+ timerEntityAI.stopTiming(); // Spigot
|
|
|
|
this.world.methodProfiler.b();
|
|
this.world.methodProfiler.a("jump");
|
|
+ timerEntityAIJump.startTiming(); // Spigot
|
|
if (this.bF) {
|
|
if (!this.H() && !this.J()) {
|
|
if (this.onGround && this.bV == 0) {
|
|
@@ -1295,8 +1311,10 @@ public abstract class EntityLiving extends Entity {
|
|
this.bV = 0;
|
|
}
|
|
|
|
+ timerEntityAIJump.stopTiming(); // Spigot
|
|
this.world.methodProfiler.b();
|
|
this.world.methodProfiler.a("travel");
|
|
+ timerEntityAIMove.startTiming(); // Spigot
|
|
this.bC *= 0.98F;
|
|
this.bD *= 0.98F;
|
|
this.bE *= 0.9F;
|
|
@@ -1305,6 +1323,7 @@ public abstract class EntityLiving extends Entity {
|
|
this.aN *= this.bB();
|
|
this.e(this.bC, this.bD);
|
|
this.aN = f;
|
|
+ timerEntityAIMove.stopTiming(); // Spigot
|
|
this.world.methodProfiler.b();
|
|
this.world.methodProfiler.a("push");
|
|
if (!this.world.isStatic) {
|
|
@@ -1313,6 +1332,7 @@ public abstract class EntityLiving extends Entity {
|
|
|
|
this.world.methodProfiler.b();
|
|
this.world.methodProfiler.a("looting");
|
|
+ timerEntityAILoot.startTiming(); // Spigot
|
|
// CraftBukkit - Don't run mob pickup code on players
|
|
if (!this.world.isStatic && !(this instanceof EntityPlayer) && this.canPickUpLoot && !this.bc && this.world.getGameRules().getBoolean("mobGriefing")) {
|
|
List list = this.world.a(EntityItem.class, this.boundingBox.grow(1.0D, 0.0D, 1.0D));
|
|
@@ -1377,6 +1397,7 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
}
|
|
|
|
+ timerEntityAILoot.stopTiming(); // Spigot
|
|
this.world.methodProfiler.b();
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index 43a24f5..7ca0acf 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -25,6 +25,7 @@ import org.bukkit.craftbukkit.util.Waitable;
|
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.CustomTimingsHandler;
|
|
import org.bukkit.event.Event;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.block.SignChangeEvent;
|
|
@@ -68,6 +69,7 @@ public class PlayerConnection extends Connection {
|
|
private double q;
|
|
public boolean checkMovement = true; // CraftBukkit - private -> public
|
|
private IntHashMap s = new IntHashMap();
|
|
+ static private CustomTimingsHandler playerCommandTimer = new CustomTimingsHandler("playerCommand"); // Spigot
|
|
|
|
public PlayerConnection(MinecraftServer minecraftserver, INetworkManager inetworkmanager, EntityPlayer entityplayer) {
|
|
this.minecraftServer = minecraftserver;
|
|
@@ -976,6 +978,7 @@ public class PlayerConnection extends Connection {
|
|
// CraftBukkit end
|
|
|
|
private void handleCommand(String s) {
|
|
+ playerCommandTimer.startTiming(); // Spigot
|
|
// CraftBukkit start
|
|
CraftPlayer player = this.getPlayer();
|
|
|
|
@@ -983,19 +986,23 @@ public class PlayerConnection extends Connection {
|
|
this.server.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
+ playerCommandTimer.stopTiming(); // Spigot
|
|
return;
|
|
}
|
|
|
|
try {
|
|
if (server.logCommands) logger.info(event.getPlayer().getName() + " issued server command: " + event.getMessage()); // Spigot
|
|
if (this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
|
|
+ playerCommandTimer.stopTiming(); // Spigot
|
|
return;
|
|
}
|
|
} catch (org.bukkit.command.CommandException ex) {
|
|
player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
|
|
Logger.getLogger(PlayerConnection.class.getName()).log(Level.SEVERE, null, ex);
|
|
+ playerCommandTimer.stopTiming(); // Spigot
|
|
return;
|
|
}
|
|
+ playerCommandTimer.stopTiming(); // Spigot
|
|
// CraftBukkit end
|
|
|
|
/* CraftBukkit start - No longer needed as we have already handled it in server.dispatchServerCommand above.
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index e2426bc..9b7bc02 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -14,6 +14,7 @@ import java.util.concurrent.Callable;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.craftbukkit.util.LongHashSet;
|
|
import org.bukkit.craftbukkit.util.UnsafeList;
|
|
+import org.bukkit.event.WorldTimingsHandler;
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
|
@@ -114,6 +115,7 @@ public abstract class World implements IBlockAccess {
|
|
final Object chunkLock = new Object();
|
|
private byte chunkTickRadius;
|
|
|
|
+ public WorldTimingsHandler timings; // Spigot
|
|
public CraftWorld getWorld() {
|
|
return this.world;
|
|
}
|
|
@@ -193,6 +195,7 @@ public abstract class World implements IBlockAccess {
|
|
this.a();
|
|
|
|
this.getServer().addWorld(this.world); // CraftBukkit
|
|
+ timings = new WorldTimingsHandler(this); // Spigot
|
|
}
|
|
|
|
protected abstract IChunkProvider j();
|
|
@@ -1204,6 +1207,7 @@ public abstract class World implements IBlockAccess {
|
|
CrashReport crashreport;
|
|
CrashReportSystemDetails crashreportsystemdetails;
|
|
|
|
+ timings.entityBaseTick.startTiming(); // Spigot
|
|
for (i = 0; i < this.i.size(); ++i) {
|
|
entity = (Entity) this.i.get(i);
|
|
// CraftBukkit start - fixed an NPE, don't process entities in chunks queued for unload
|
|
@@ -1258,7 +1262,9 @@ public abstract class World implements IBlockAccess {
|
|
|
|
this.f.clear();
|
|
this.methodProfiler.c("regular");
|
|
+ timings.entityBaseTick.stopTiming(); // Spigot
|
|
|
|
+ timings.entityTick.startTiming(); // Spigot
|
|
for (i = 0; i < this.entityList.size(); ++i) {
|
|
entity = (Entity) this.entityList.get(i);
|
|
|
|
@@ -1311,7 +1317,9 @@ public abstract class World implements IBlockAccess {
|
|
this.methodProfiler.b();
|
|
}
|
|
|
|
+ timings.entityTick.stopTiming(); // Spigot
|
|
this.methodProfiler.c("tileEntities");
|
|
+ timings.tileEntityTick.startTiming(); // Spigot
|
|
this.M = true;
|
|
Iterator iterator = this.tileEntityList.iterator();
|
|
|
|
@@ -1390,6 +1398,7 @@ public abstract class World implements IBlockAccess {
|
|
this.a.clear();
|
|
}
|
|
|
|
+ timings.tileEntityTick.stopTiming(); // Spigot
|
|
this.methodProfiler.b();
|
|
this.methodProfiler.b();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
|
index 842d722..eb268ad 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -157,9 +157,12 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate
|
|
// CraftBukkit start - Only call spawner if we have players online and the world allows for mobs or animals
|
|
long time = this.worldData.getTime();
|
|
if (this.getGameRules().getBoolean("doMobSpawning") && (this.allowMonsters || this.allowAnimals) && (this instanceof WorldServer && this.players.size() > 0)) {
|
|
+ timings.mobSpawn.startTiming(); // Spigot
|
|
SpawnerCreature.spawnEntities(this, this.allowMonsters && (this.ticksPerMonsterSpawns != 0 && time % this.ticksPerMonsterSpawns == 0L), this.allowAnimals && (this.ticksPerAnimalSpawns != 0 && time % this.ticksPerAnimalSpawns == 0L), this.worldData.getTime() % 400L == 0L);
|
|
+ timings.mobSpawn.stopTiming(); // Spigot
|
|
}
|
|
// CraftBukkit end
|
|
+ timings.doTickRest.startTiming(); // Spigot
|
|
this.getWorld().processChunkGC(); // Spigot
|
|
this.methodProfiler.c("chunkSource");
|
|
this.chunkProvider.unloadChunks();
|
|
@@ -187,6 +190,7 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate
|
|
this.V();
|
|
|
|
this.getWorld().processChunkGC(); // CraftBukkit
|
|
+ timings.doTickRest.stopTiming(); // Spigot
|
|
}
|
|
|
|
public BiomeMeta a(EnumCreatureType enumcreaturetype, int i, int j, int k) {
|
|
diff --git a/src/main/java/org/bukkit/event/WorldTimingsHandler.java b/src/main/java/org/bukkit/event/WorldTimingsHandler.java
|
|
new file mode 100644
|
|
index 0000000..bb0c191
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/bukkit/event/WorldTimingsHandler.java
|
|
@@ -0,0 +1,20 @@
|
|
+package org.bukkit.event;
|
|
+
|
|
+import net.minecraft.server.World;
|
|
+
|
|
+public class WorldTimingsHandler {
|
|
+ public CustomTimingsHandler mobSpawn;
|
|
+ public CustomTimingsHandler doTickRest;
|
|
+ public CustomTimingsHandler entityBaseTick;
|
|
+ public CustomTimingsHandler entityTick;
|
|
+ public CustomTimingsHandler tileEntityTick;
|
|
+ public WorldTimingsHandler(World server) {
|
|
+ String name = server.worldData.getName() +" - ";
|
|
+
|
|
+ mobSpawn = new CustomTimingsHandler(name + "mobSpawn");
|
|
+ doTickRest = new CustomTimingsHandler(name + "doTickRest");
|
|
+ entityBaseTick = new CustomTimingsHandler(name + "entityBaseTick");
|
|
+ entityTick = new CustomTimingsHandler(name + "entityTick");
|
|
+ tileEntityTick = new CustomTimingsHandler(name + "tileEntityTick");
|
|
+ }
|
|
+}
|
|
--
|
|
1.8.1-rc2
|
|
|