mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 19:46:21 +01:00
Execute spark tasks during tick sleep (#11525)
This commit is contained in:
parent
29bf7beba9
commit
9e35192360
@ -21,10 +21,10 @@ index 9966576652ed6007d2228237f292c1dc83ede485..9b3a6b336cb1344d4e74e0e4f7c50ffd
|
||||
paperweight {
|
||||
diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..2955b7ec9832a5752ea4aff9fc9d34ae2f9ee83e
|
||||
index 0000000000000000000000000000000000000000..62e2d5704c348955bc8284dc2d54c933b7bcdd06
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/SparksFly.java
|
||||
@@ -0,0 +1,201 @@
|
||||
@@ -0,0 +1,211 @@
|
||||
+package io.papermc.paper;
|
||||
+
|
||||
+import io.papermc.paper.configuration.GlobalConfiguration;
|
||||
@ -34,6 +34,7 @@ index 0000000000000000000000000000000000000000..2955b7ec9832a5752ea4aff9fc9d34ae
|
||||
+import io.papermc.paper.util.MCUtil;
|
||||
+import java.util.Collection;
|
||||
+import java.util.List;
|
||||
+import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
+import java.util.logging.Level;
|
||||
+import java.util.logging.Logger;
|
||||
+import me.lucko.spark.paper.api.Compatibility;
|
||||
@ -59,11 +60,13 @@ index 0000000000000000000000000000000000000000..2955b7ec9832a5752ea4aff9fc9d34ae
|
||||
+
|
||||
+ private final Logger logger;
|
||||
+ private final PaperSparkModule spark;
|
||||
+ private final ConcurrentLinkedQueue<Runnable> mainThreadTaskQueue;
|
||||
+
|
||||
+ private boolean enabled;
|
||||
+ private boolean disabledInConfigurationWarningLogged;
|
||||
+
|
||||
+ public SparksFly(final Server server) {
|
||||
+ this.mainThreadTaskQueue = new ConcurrentLinkedQueue<>();
|
||||
+ this.logger = Logger.getLogger(ID);
|
||||
+ this.logger.log(Level.INFO, "This server bundles the spark profiler. For more information please visit https://docs.papermc.io/paper/profiling");
|
||||
+ this.spark = PaperSparkModule.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() {
|
||||
@ -74,7 +77,7 @@ index 0000000000000000000000000000000000000000..2955b7ec9832a5752ea4aff9fc9d34ae
|
||||
+
|
||||
+ @Override
|
||||
+ public void executeSync(final Runnable runnable) {
|
||||
+ MCUtil.ensureMain(this.catching(runnable, "synchronous"));
|
||||
+ SparksFly.this.mainThreadTaskQueue.offer(this.catching(runnable, "synchronous"));
|
||||
+ }
|
||||
+
|
||||
+ private Runnable catching(final Runnable runnable, final String type) {
|
||||
@ -111,6 +114,13 @@ index 0000000000000000000000000000000000000000..2955b7ec9832a5752ea4aff9fc9d34ae
|
||||
+ });
|
||||
+ }
|
||||
+
|
||||
+ public void executeMainThreadTasks() {
|
||||
+ Runnable task;
|
||||
+ while ((task = this.mainThreadTaskQueue.poll()) != null) {
|
||||
+ task.run();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public void enableEarlyIfRequested() {
|
||||
+ if (!isPluginPreferred() && shouldEnableImmediately()) {
|
||||
+ this.enable();
|
||||
@ -269,7 +279,7 @@ index 6b8ed8a0baaf4a57d20e57cec3400af5561ddd79..48604e7f96adc9e226e034054c5e2bad
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 7a671772760152f26e5bb60ea2f2a7765c017c37..3fc6e7cb5e02792e5e87beb7525cde96bc45df1c 100644
|
||||
index 7a671772760152f26e5bb60ea2f2a7765c017c37..8a45960de3fd890991a1c75a103fec1adb03c0cb 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -765,6 +765,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@ -297,7 +307,21 @@ index 7a671772760152f26e5bb60ea2f2a7765c017c37..3fc6e7cb5e02792e5e87beb7525cde96
|
||||
org.spigotmc.WatchdogThread.tick();
|
||||
// Paper end - Improved Watchdog Support
|
||||
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
|
||||
@@ -1638,6 +1642,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -1627,17 +1631,21 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
|
||||
if (this.emptyTicks >= j) {
|
||||
+ this.server.spark.tickStart(); // Paper - spark
|
||||
if (this.emptyTicks == j) {
|
||||
MinecraftServer.LOGGER.info("Server empty for {} seconds, pausing", this.pauseWhileEmptySeconds());
|
||||
this.autoSave();
|
||||
}
|
||||
|
||||
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
|
||||
+ this.server.spark.executeMainThreadTasks(); // Paper - spark
|
||||
this.tickConnection();
|
||||
+ this.server.spark.tickEnd(((double)(System.nanoTime() - lastTick) / 1000000D)); // Paper - spark
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,7 +329,13 @@ index 7a671772760152f26e5bb60ea2f2a7765c017c37..3fc6e7cb5e02792e5e87beb7525cde96
|
||||
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events
|
||||
++this.tickCount;
|
||||
this.tickRateManager.tick();
|
||||
@@ -1660,6 +1665,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -1655,11 +1663,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||
|
||||
this.runAllTasks(); // Paper - move runAllTasks() into full server tick (previously for timings)
|
||||
+ this.server.spark.executeMainThreadTasks(); // Paper - spark
|
||||
// Paper start - Server Tick Events
|
||||
long endTime = System.nanoTime();
|
||||
long remaining = (TICK_TIME - (endTime - lastTick)) - catchupTime;
|
||||
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
|
||||
// Paper end - Server Tick Events
|
||||
|
@ -5,7 +5,7 @@ Subject: [PATCH] Incremental chunk and player saving
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 3fc6e7cb5e02792e5e87beb7525cde96bc45df1c..27a50ce8f9ed5a6024f16444be5585f61062c2e9 100644
|
||||
index 8a45960de3fd890991a1c75a103fec1adb03c0cb..c1e8d2679083516040e9d1768d79f5e4d71bf0a6 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1008,7 +1008,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@ -17,7 +17,7 @@ index 3fc6e7cb5e02792e5e87beb7525cde96bc45df1c..27a50ce8f9ed5a6024f16444be5585f6
|
||||
flag3 = this.saveAllChunks(suppressLogs, flush, force);
|
||||
} finally {
|
||||
this.isSaving = false;
|
||||
@@ -1653,9 +1653,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -1656,9 +1656,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
|
||||
--this.ticksUntilAutosave;
|
||||
|
@ -8,7 +8,7 @@ Areas affected by lag comepnsation:
|
||||
- Eating food items
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 27a50ce8f9ed5a6024f16444be5585f61062c2e9..1636c4347bb6e5a0b4c2e08c7ed9c49587769a2b 100644
|
||||
index c1e8d2679083516040e9d1768d79f5e4d71bf0a6..af7c6f56444c0e495fd39da872f8030199afc634 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -331,6 +331,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@ -19,7 +19,7 @@ index 27a50ce8f9ed5a6024f16444be5585f61062c2e9..1636c4347bb6e5a0b4c2e08c7ed9c495
|
||||
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
||||
AtomicReference<S> atomicreference = new AtomicReference();
|
||||
@@ -1838,6 +1839,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -1842,6 +1843,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
|
||||
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
|
||||
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers
|
||||
|
Loading…
Reference in New Issue
Block a user