Skip to content

Commit 1f31ee5

Browse files
committed
Do not record task execution time as TickTime individually
The number of recorded instances may be high and subsequently cause calculations of MSPT or TPS to be abnormally high. Instead, we record task execution time as a sum on TickTime itself. Task execution time is tracked for the next tick.
1 parent a41043f commit 1f31ee5

File tree

8 files changed

+61
-180
lines changed

8 files changed

+61
-180
lines changed

paper-server/patches/features/0001-Moonrise-optimisation-patches.patch

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23067,7 +23067,7 @@ index 13424bce076493f146bdc5fd0b1f2e09805bd5e7..2de7072c8ccc005e514673bba494b64d
2306723067
thread1 -> {
2306823068
DedicatedServer dedicatedServer1 = new DedicatedServer(
2306923069
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
23070-
index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e627770ed 100644
23070+
index ab95014e66a7e217024ad9845669cc77fbbb13c2..40730d5775ed81bd715960b2c7dd710ca11dcb0e 100644
2307123071
--- a/net/minecraft/server/MinecraftServer.java
2307223072
+++ b/net/minecraft/server/MinecraftServer.java
2307323073
@@ -177,7 +177,7 @@ import net.minecraft.world.phys.Vec2;
@@ -23079,7 +23079,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2307923079
private static MinecraftServer SERVER; // Paper
2308023080
public static final Logger LOGGER = LogUtils.getLogger();
2308123081
public static final net.kyori.adventure.text.logger.slf4j.ComponentLogger COMPONENT_LOGGER = net.kyori.adventure.text.logger.slf4j.ComponentLogger.logger(LOGGER.getName()); // Paper
23082-
@@ -392,6 +392,93 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23082+
@@ -393,6 +393,93 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2308323083
return minecraftServer;
2308423084
}
2308523085

@@ -23173,7 +23173,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2317323173
public MinecraftServer(
2317423174
// CraftBukkit start
2317523175
joptsimple.OptionSet options,
23176-
@@ -824,7 +911,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23176+
@@ -825,7 +912,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2317723177
serverLevel.setSpawnSettings(serverLevel.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && serverLevel.getGameRules().getBoolean(GameRules.RULE_SPAWN_MONSTERS)); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
2317823178
this.updateEffectiveRespawnData();
2317923179
this.forceTicks = false; // CraftBukkit
@@ -23182,7 +23182,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2318223182
new org.bukkit.event.world.WorldLoadEvent(serverLevel.getWorld()).callEvent(); // Paper - call WorldLoadEvent
2318323183
}
2318423184

23185-
@@ -847,6 +934,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23185+
@@ -848,6 +935,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2318623186
public abstract boolean shouldRconBroadcast();
2318723187

2318823188
public boolean saveAllChunks(boolean suppressLogs, boolean flush, boolean force) {
@@ -23194,7 +23194,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2319423194
boolean flag = false;
2319523195

2319623196
for (ServerLevel serverLevel : this.getAllLevels()) {
23197-
@@ -854,7 +946,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23197+
@@ -855,7 +947,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2319823198
LOGGER.info("Saving chunks for level '{}'/{}", serverLevel, serverLevel.dimension().location());
2319923199
}
2320023200

@@ -23203,7 +23203,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2320323203
flag = true;
2320423204
}
2320523205

23206-
@@ -944,7 +1036,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23206+
@@ -945,7 +1037,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2320723207
}
2320823208
}
2320923209

@@ -23212,7 +23212,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2321223212
this.nextTickTimeNanos = Util.getNanos() + TimeUtil.NANOSECONDS_PER_MILLISECOND;
2321323213

2321423214
for (ServerLevel serverLevelx : this.getAllLevels()) {
23215-
@@ -954,18 +1046,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23215+
@@ -955,18 +1047,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2321623216

2321723217
this.waitUntilNextTick();
2321823218
}
@@ -23238,7 +23238,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2323823238

2323923239
this.isSaving = false;
2324023240
this.resources.close();
23241-
@@ -985,6 +1073,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23241+
@@ -986,6 +1074,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2324223242
this.services().nameToIdCache().save(false); // Paper - Perf: Async GameProfileCache saving
2324323243
}
2324423244
// Spigot end
@@ -23253,7 +23253,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2325323253
// Paper start - Improved watchdog support - move final shutdown items here
2325423254
Util.shutdownExecutors();
2325523255
try {
23256-
@@ -1077,16 +1173,31 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23256+
@@ -1080,16 +1176,31 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2325723257
// execute small amounts of other tasks just in case the number of tasks we are
2325823258
// draining is large - chunk system and packet processing may be latency sensitive
2325923259

@@ -23288,7 +23288,7 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2328823288
profiler.pop(); // moonrise:run_all_chunk
2328923289
profiler.pop(); // moonrise:run_all_tasks
2329023290

23291-
@@ -1227,11 +1338,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23291+
@@ -1222,11 +1333,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2329223292
ProfilerFiller profilerFiller = Profiler.get();
2329323293
profilerFiller.push("tick");
2329423294
this.tickFrame.start();
@@ -23307,15 +23307,15 @@ index 61e4ddb9665fb3bc4900c865ad8887d344ff7f7c..8afe24c382e18e799101662ccf87022e
2330723307
this.tickFrame.end();
2330823308
this.recordEndOfTick(); // Paper - improve tick loop
2330923309
profilerFiller.popPush("nextTickWait");
23310-
@@ -1404,6 +1519,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23310+
@@ -1399,6 +1514,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2331123311

2331223312
private boolean pollTaskInternal() {
2331323313
if (super.pollTask()) {
2331423314
+ this.moonrise$executeMidTickTasks(); // Paper - rewrite chunk system
2331523315
return true;
2331623316
} else {
2331723317
boolean ret = false; // Paper - force execution of all worlds, do not just bias the first
23318-
@@ -2579,6 +2695,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23318+
@@ -2574,6 +2690,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2331923319
}
2332023320
}
2332123321

paper-server/patches/features/0002-Rewrite-dataconverter-system.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32910,10 +32910,10 @@ index 71b8bbeda2fecf930870a9b6e856e20639d31645..91650a92a21fcaac65a5dfcac0cc856b
3291032910
return structureTemplate.save(new CompoundTag());
3291132911
}
3291232912
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
32913-
index 8afe24c382e18e799101662ccf87022e627770ed..a31ef450a0c8f2929065a3c10e47c14bf5eb30f2 100644
32913+
index 40730d5775ed81bd715960b2c7dd710ca11dcb0e..3228e6c886b62325c3c47a860fcf3d04ea53f764 100644
3291432914
--- a/net/minecraft/server/MinecraftServer.java
3291532915
+++ b/net/minecraft/server/MinecraftServer.java
32916-
@@ -378,6 +378,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
32916+
@@ -379,6 +379,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
3291732917
// Paper end - improve tick loop
3291832918

3291932919
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {

paper-server/patches/features/0021-Incremental-chunk-and-player-saving.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Subject: [PATCH] Incremental chunk and player saving
55

66

77
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
8-
index a31ef450a0c8f2929065a3c10e47c14bf5eb30f2..d5f3083354d70c4da3c39e2f909ce4c7e170295c 100644
8+
index 3228e6c886b62325c3c47a860fcf3d04ea53f764..ff6fc300e9e7d1dbf4b0fa1e59bffe94e1f51259 100644
99
--- a/net/minecraft/server/MinecraftServer.java
1010
+++ b/net/minecraft/server/MinecraftServer.java
11-
@@ -970,7 +970,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
11+
@@ -971,7 +971,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
1212
boolean var4;
1313
try {
1414
this.isSaving = true;
@@ -17,7 +17,7 @@ index a31ef450a0c8f2929065a3c10e47c14bf5eb30f2..d5f3083354d70c4da3c39e2f909ce4c7
1717
var4 = this.saveAllChunks(suppressLogs, flush, force);
1818
} finally {
1919
this.isSaving = false;
20-
@@ -1627,9 +1627,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
20+
@@ -1622,9 +1622,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2121
}
2222

2323
this.ticksUntilAutosave--;

paper-server/patches/features/0026-Optimise-EntityScheduler-ticking.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ index a2fbc13105673e926cbaed69221826ebd392140f..a42938e1abd371dba6806e65552fde71
2020

2121
@Override
2222
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
23-
index d5f3083354d70c4da3c39e2f909ce4c7e170295c..4b1ffb5396138fc0d165ac647797b83f11d039ac 100644
23+
index ff6fc300e9e7d1dbf4b0fa1e59bffe94e1f51259..d58ee455467b2c8307ea20f8a9d88f0f18053fc1 100644
2424
--- a/net/minecraft/server/MinecraftServer.java
2525
+++ b/net/minecraft/server/MinecraftServer.java
26-
@@ -1741,33 +1741,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
26+
@@ -1736,33 +1736,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2727
}
2828
}
2929

@@ -67,7 +67,7 @@ index d5f3083354d70c4da3c39e2f909ce4c7e170295c..4b1ffb5396138fc0d165ac647797b83f
6767
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
6868
profilerFiller.push("commandFunctions");
6969
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
70-
index fea14f27503369185c867d269c5b8b416ce76eda..80dce02ac088eccaff71ab7fa85516036177a804 100644
70+
index 7ab250350027543adc3926632b0d68a2254c6ad3..2e3e038874757049445a91bf590d5a1a427a3f6d 100644
7171
--- a/net/minecraft/world/entity/Entity.java
7272
+++ b/net/minecraft/world/entity/Entity.java
7373
@@ -5190,6 +5190,11 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name

paper-server/patches/features/0029-Optimize-Hoppers.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ index 0000000000000000000000000000000000000000..24a2090e068ad3c0d08705050944abdf
4848
+ }
4949
+}
5050
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
51-
index 4b1ffb5396138fc0d165ac647797b83f11d039ac..dd05a184919dd4737dd0a0194b83eadb1adc4699 100644
51+
index d58ee455467b2c8307ea20f8a9d88f0f18053fc1..f63a5567a2e845de904c2dacfbb875049e3e0c65 100644
5252
--- a/net/minecraft/server/MinecraftServer.java
5353
+++ b/net/minecraft/server/MinecraftServer.java
54-
@@ -1796,6 +1796,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
54+
@@ -1791,6 +1791,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
5555
serverLevel.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
5656
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
5757
serverLevel.updateLagCompensationTick(); // Paper - lag compensation

paper-server/patches/sources/net/minecraft/server/MinecraftServer.java.patch

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
private int playerIdleTimeout;
4242
private final long[] tickTimesNanos = new long[100];
4343
private long aggregatedTickTimesNanos = 0L;
44-
@@ -278,10 +_,108 @@
44+
@@ -278,10 +_,109 @@
4545
private final DiscontinuousFrame tickFrame;
4646
private final PacketProcessor packetProcessor;
4747

@@ -81,6 +81,7 @@
8181
+ private long lastTickStart;
8282
+ private long currentTickStart;
8383
+ private long scheduledTickStart;
84+
+ private long taskExecutionTime;
8485
+ private final Object statsLock = new Object();
8586
+ private @Nullable double[] tps;
8687
+ private @Nullable ca.spottedleaf.moonrise.common.time.TickData.MSPTData msptData5s;
@@ -630,7 +631,7 @@
630631
this.running = false;
631632
if (waitForShutdown) {
632633
try {
633-
@@ -730,6 +_,124 @@
634+
@@ -730,6 +_,118 @@
634635
}
635636
}
636637

@@ -663,9 +664,11 @@
663664
+ 0L,
664665
+ now,
665666
+ 0L,
666-
+ false,
667-
+ true
667+
+ this.taskExecutionTime,
668+
+ 0L,
669+
+ false
668670
+ );
671+
+ this.taskExecutionTime = 0L;
669672
+
670673
+ this.addTickTime(time);
671674
+ }
@@ -723,15 +726,7 @@
723726
+ final long now = Util.getNanos();
724727
+
725728
+ // record execution time
726-
+ this.addTickTime(
727-
+ new ca.spottedleaf.moonrise.common.time.TickTime(
728-
+ ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool.DEADLINE_NOT_SET, ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool.DEADLINE_NOT_SET,
729-
+ start, 0L,
730-
+ now, 0L,
731-
+ false,
732-
+ false
733-
+ )
734-
+ );
729+
+ this.taskExecutionTime += (now - start);
735730
+
736731
+ // wait for unpark or deadline
737732
+ final long toWait = deadline - now;

0 commit comments

Comments
 (0)