Repository navigation
fix(tps): Purpur/Leaf 上三个窗口全错,15 分钟数据彻底消失 - #12
Merged
Merged
Conversation
Purpur 与 Leaf 会在 Bukkit.getServer().getTPS() 的数组最前面插一个 5 秒平均值,
长度从 3 变成 4:
public double[] getTPS() {
return new double[] {
+ tps5s.getAverage(), // Purpur
tps1.getAverage(),
tps5.getAverage(),
tps15.getAverage()
于是 tps[0]/[1]/[2] 读到的是 5s/1m/5m,而不是 1m/5m/15m。三件事同时发生:
告警判据从 1 分钟变成 5 秒(一次 200ms 的 GC 停顿就能把 5 秒 TPS 拉到 15 以下,
在本健康的服上刷 critical);趋势图与日报的「最低 TPS」全是 5 秒口径;15 分钟数据
彻底消失。而这不会报错、不会崩溃、不进 unavailable。
一手证据:Purpur 1.20.1 / 1.20.2 / 1.20.4 / 1.21.4 / 1.21.11 五个分支的 patch
逐字读过,补丁自 2019 年即存在。
修法:按长度取末尾三个。
int off = tps.length - 3;
不按平台名分支——Leaf 的这个行为可由配置开关(misc.including-5s-in-get-tps),
同一个平台既可能返回 3 也可能返回 4。也不写死 [1][2][3]——将来若再前插一个窗口,
length - 3 对 3/4/5 都正确。
三处纠正了我原本的假设:
- Purpur 没有开关,硬编码在补丁里;只有 Leaf 可关
- getTPSIncluding5SecondAverage() 不是 Purpur 的方法(是 Gale/Leaf 的),
用它当判据在 Purpur 上必然漏判——所以本实现完全不用反射
- Purpur 1.21.10+ 把实现从 CraftServer#getTPS() 挪到 MinecraftServer#computeTPS(),
长度与索引不变
/status 现在在窗口数 != 3 时多显示一行说明;标准布局不显示。
顺带包一层 UnsupportedOperationException:Folia 在非 region 线程上调 getTPS() 会抛,
而不是返回空数组。本方法现在在 GlobalRegionScheduler 线程上不会触发,但采集链路将来
被挪到异步线程时,一个未捕获异常会让整个采集周期失败,看起来像「采集器坏了」。
1008 例全绿(新增 8 例)。变异:退回硬读 [0][1][2] -> 3 例红。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Purpur 与 Leaf 会在
Bukkit.getServer().getTPS()返回的数组最前面插一个 5 秒平均值,长度从 3 变成 4:public double[] getTPS() { return new double[] { + net.minecraft.server.MinecraftServer.getServer().tps5s.getAverage(), // Purpur net.minecraft.server.MinecraftServer.getServer().tps1.getAverage(), net.minecraft.server.MinecraftServer.getServer().tps5.getAverage(), net.minecraft.server.MinecraftServer.getServer().tps15.getAverage()于是我们硬读的
tps[0]/[1]/[2]在那些平台上读到的是:后果不是「数字略偏」
三件事同时发生:
/tps里看到的 1m/5m/15m 对不上。而这一条不报错、不崩溃、不进
unavailable—— 正是本项目最怕的「看起来正常但是错的」。一手证据
Purpur 五个分支的补丁逐字读过(1.20.1 / 1.20.2 / 1.20.4 / 1.21.4 / 1.21.11),补丁自 2019 年即存在。
修法
为什么不按平台名分支 —— Leaf 的这个行为可由配置开关(
misc.including-5s-in-get-tps),同一个平台既可能返回 3 也可能返回 4。按长度分支能同时覆盖两种情况。为什么不写死
[1][2][3]—— 若将来某个分支又前插一个窗口(比如 1 秒平均),固定下标会再次读错。length - 3对 3/4/5 个窗口都正确。三处纠正了我原本的假设
getTPSIncluding5SecondAverage()CraftServer#getTPS()→MinecraftServer#computeTPS()),长度与索引不变/status多了一条诊断行(只在非标准布局时出现)标准布局不显示 —— 正常情况多一行噪音没有价值。服主发现面板与
/tps对不上时,这一行直接说明原因,而不是让他怀疑插件坏了。顺带:Folia 的异常不再拖垮整个采集周期
Folia 在非 region 线程上调
getTPS()会直接抛UnsupportedOperationException,而不是返回空数组。本方法目前跑在GlobalRegionScheduler线程上,理论上不会触发;但采集链路将来被挪到异步线程时,一个未捕获异常会让整个采集周期失败,而那看起来像「采集器坏了」,排查方向会完全错。现在包一层,降级成「TPS 未采集」。验证
TpsWindowLayoutTest[0][1][2]1m must be the SECOND element on a 4-window servernull/ 过短数组check-docs/check-i18n --strict/check-sentinels全 PASS需要你实机确认
如果你的后端是 Purpur:升级后
/perfscope status应出现上面那行「TPS 窗口」,且/perfscope tps的 15 分钟数应与/tps的 15m 一致(而不是之前的 5m)。