2018-10-01 02:34:05 +02:00
|
|
|
From 4ea0d21a910e0b43daefd58d3f4c477d9ca703fa Mon Sep 17 00:00:00 2001
|
2018-07-21 23:24:18 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 1 Jan 2018 16:10:24 -0500
|
|
|
|
Subject: [PATCH] Configurable Max Chunk Gens per Tick
|
|
|
|
|
|
|
|
Limit the number of generations that can occur in a single tick, forcing them
|
|
|
|
to be spread out more.
|
|
|
|
|
|
|
|
Defaulting to 10 as an average generation is going to be 3-6ms, which means 10 will
|
|
|
|
likely cause the server to lose TPS, but constrain how much.
|
|
|
|
|
|
|
|
This should result in no noticeable speed reduction in generation for servers not
|
|
|
|
lagging, and let larger servers reduce this value according to their own desires.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2018-09-26 06:57:59 +02:00
|
|
|
index af69342e6c..ca7efc9175 100644
|
2018-07-21 23:24:18 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2018-09-26 06:57:59 +02:00
|
|
|
@@ -388,4 +388,15 @@ public class PaperWorldConfig {
|
2018-07-21 23:24:18 +02:00
|
|
|
}
|
|
|
|
log("Max Chunk Sends Per Tick: " + maxChunkSendsPerTick);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public int maxChunkGensPerTick = 10;
|
|
|
|
+ private void maxChunkGensPerTick() {
|
|
|
|
+ maxChunkGensPerTick = getInt("max-chunk-gens-per-tick", maxChunkGensPerTick);
|
|
|
|
+ if (maxChunkGensPerTick <= 0) {
|
|
|
|
+ maxChunkGensPerTick = Integer.MAX_VALUE;
|
|
|
|
+ log("Max Chunk Gens Per Tick: Unlimited (NOT RECOMMENDED)");
|
|
|
|
+ } else {
|
|
|
|
+ log("Max Chunk Gens Per Tick: " + maxChunkGensPerTick);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
|
2018-10-01 02:34:05 +02:00
|
|
|
index abf5a7554d..84896d6f6b 100644
|
2018-07-21 23:24:18 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
|
|
|
|
@@ -28,6 +28,7 @@ public class PlayerChunk {
|
|
|
|
// CraftBukkit start - add fields
|
|
|
|
// You know the drill, https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse
|
|
|
|
// All may seem good at first, but there's deeper issues if you play for a bit
|
|
|
|
+ boolean chunkExists; // Paper
|
|
|
|
private boolean loadInProgress = false;
|
|
|
|
private Runnable loadedRunnable = new Runnable() {
|
|
|
|
public void run() {
|
2018-10-01 02:34:05 +02:00
|
|
|
@@ -58,6 +59,7 @@ public class PlayerChunk {
|
2018-08-26 20:11:49 +02:00
|
|
|
|
|
|
|
chunkproviderserver.a(i, j);
|
|
|
|
this.chunk = chunkproviderserver.getChunkAt(i, j, true, false);
|
2018-07-21 23:24:18 +02:00
|
|
|
+ this.chunkExists = this.chunk != null || ChunkIOExecutor.hasQueuedChunkLoad(playerChunkMap.getWorld(), i, j); // Paper
|
|
|
|
markChunkUsed(); // Paper - delay chunk unloads
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2018-09-23 04:48:30 +02:00
|
|
|
index 54f31349e9..d1a443ca8d 100644
|
2018-07-21 23:24:18 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
@@ -140,6 +140,7 @@ public class PlayerChunkMap {
|
|
|
|
// Spigot start
|
|
|
|
org.spigotmc.SlackActivityAccountant activityAccountant = this.world.getMinecraftServer().slackActivityAccountant;
|
|
|
|
activityAccountant.startActivity(0.5);
|
|
|
|
+ int chunkGensAllowed = world.paperConfig.maxChunkGensPerTick; // Paper
|
|
|
|
// Spigot end
|
|
|
|
|
|
|
|
Iterator iterator1 = this.h.iterator();
|
|
|
|
@@ -149,6 +150,11 @@ public class PlayerChunkMap {
|
|
|
|
|
|
|
|
if (playerchunk1.f() == null) {
|
|
|
|
boolean flag = playerchunk1.a(PlayerChunkMap.b);
|
|
|
|
+ // Paper start
|
|
|
|
+ if (flag && !playerchunk1.chunkExists && chunkGensAllowed-- <= 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
if (playerchunk1.a(flag)) {
|
|
|
|
iterator1.remove();
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java b/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java
|
2018-09-29 01:31:59 +02:00
|
|
|
index 7ffb8f6172..33d5fc7d5e 100644
|
2018-07-21 23:24:18 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java
|
2018-09-29 01:31:59 +02:00
|
|
|
@@ -34,4 +34,10 @@ public class ChunkIOExecutor {
|
2018-07-21 23:24:18 +02:00
|
|
|
public static void tick() {
|
|
|
|
instance.finishActive();
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ public static boolean hasQueuedChunkLoad(World world, int x, int z) {
|
|
|
|
+ return instance.hasTask(new QueuedChunk(x, z, null, world, null));
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
|
2018-08-06 01:46:43 +02:00
|
|
|
index 193c3621c6..cf1258c559 100644
|
2018-07-21 23:24:18 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/AsynchronousExecutor.java
|
|
|
|
@@ -351,4 +351,10 @@ public final class AsynchronousExecutor<P, T, C, E extends Throwable> {
|
|
|
|
public void setActiveThreads(final int coreSize) {
|
|
|
|
pool.setCorePoolSize(coreSize);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ public boolean hasTask(P parameter) throws IllegalStateException {
|
|
|
|
+ return tasks.get(parameter) != null;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
--
|
2018-09-23 04:48:30 +02:00
|
|
|
2.19.0
|
2018-07-21 23:24:18 +02:00
|
|
|
|