mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Execute spark tasks during tick sleep (#11525)
This commit is contained in:
parent
ad03975163
commit
8f7bce1e31
@ -34,6 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+import io.papermc.paper.util.MCUtil;
|
+import io.papermc.paper.util.MCUtil;
|
||||||
+import java.util.Collection;
|
+import java.util.Collection;
|
||||||
+import java.util.List;
|
+import java.util.List;
|
||||||
|
+import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
+import java.util.logging.Level;
|
+import java.util.logging.Level;
|
||||||
+import java.util.logging.Logger;
|
+import java.util.logging.Logger;
|
||||||
+import me.lucko.spark.paper.api.Compatibility;
|
+import me.lucko.spark.paper.api.Compatibility;
|
||||||
@ -59,11 +60,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ private final Logger logger;
|
+ private final Logger logger;
|
||||||
+ private final PaperSparkModule spark;
|
+ private final PaperSparkModule spark;
|
||||||
|
+ private final ConcurrentLinkedQueue<Runnable> mainThreadTaskQueue;
|
||||||
+
|
+
|
||||||
+ private boolean enabled;
|
+ private boolean enabled;
|
||||||
+ private boolean disabledInConfigurationWarningLogged;
|
+ private boolean disabledInConfigurationWarningLogged;
|
||||||
+
|
+
|
||||||
+ public SparksFly(final Server server) {
|
+ public SparksFly(final Server server) {
|
||||||
|
+ this.mainThreadTaskQueue = new ConcurrentLinkedQueue<>();
|
||||||
+ this.logger = Logger.getLogger(ID);
|
+ 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.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() {
|
+ this.spark = PaperSparkModule.create(Compatibility.VERSION_1_0, server, this.logger, new PaperScheduler() {
|
||||||
@ -74,7 +77,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void executeSync(final Runnable runnable) {
|
+ 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) {
|
+ private Runnable catching(final Runnable runnable, final String type) {
|
||||||
@ -111,6 +114,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ });
|
+ });
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ public void executeMainThreadTasks() {
|
||||||
|
+ Runnable task;
|
||||||
|
+ while ((task = this.mainThreadTaskQueue.poll()) != null) {
|
||||||
|
+ task.run();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ public void enableEarlyIfRequested() {
|
+ public void enableEarlyIfRequested() {
|
||||||
+ if (!isPluginPreferred() && shouldEnableImmediately()) {
|
+ if (!isPluginPreferred() && shouldEnableImmediately()) {
|
||||||
+ this.enable();
|
+ this.enable();
|
||||||
@ -299,6 +309,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
|
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
|
||||||
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
@@ -0,0 +0,0 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ this.server.spark.tickStart(); // Paper - spark
|
+ this.server.spark.tickStart(); // Paper - spark
|
||||||
@ -306,6 +330,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
++this.tickCount;
|
++this.tickCount;
|
||||||
this.tickRateManager.tick();
|
this.tickRateManager.tick();
|
||||||
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
@@ -0,0 +0,0 @@ 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;
|
long remaining = (TICK_TIME - (endTime - lastTick)) - catchupTime;
|
||||||
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
|
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
|
||||||
// Paper end - Server Tick Events
|
// Paper end - Server Tick Events
|
||||||
|
Loading…
Reference in New Issue
Block a user