性能调优

警告

这些文档是为 SpongeAPI 7 编写的,可能已经过时。 如果你觉得你可以帮助更新它们,请提交一个 PR!

Sponge提供了一些性能优化和其他一些额外选项,可帮助你的服务器可以在高负载下流畅运行。

备注

虽然我们想让所有服务器都流畅无比,但这还要取决于你是否正确配置服务器。下面来测试一下你的服务器是否达到了最强性能!

实体活动范围

该选项将会影响玩家周围实体加载的行为。降低该数值将导致只有靠近玩家的实体才会加载;升高该数值则会让离玩家较远的实体也得以加载。降低该数值可提升服务器性能,尤其是在有大量实体和玩家的场景下。若需要禁止某种实体的活动,可直接将其设定为 0

小技巧

当然,你也可以针对某个 特定生物 设定其活动范围。你还大可以选择将 auto-populate 设定为 true ,这样 Sponge 就会帮你自动设定所有生物的活动范围,惟需注意,我们建议你在自动设定完成后关闭此选项(即重新设定为 false )。若有新的生物种类,只需重复此步骤即可。

entity-activation-range {
    # If enabled, newly discovered entities will be added to this config with a default value.
    auto-populate=false
    # Default activation ranges used for all entities unless overridden.
    defaults {
        ambient=32
        aquatic=32
        creature=32
        misc=16
        monster=32
    }
}

异步亮度计算

这一设置将会在一个异步的线程里进行亮度的检查和计算,从而提升性能。

optimizations {
    # Runs lighting updates async.
    async-lighting {
        # If enabled, runs lighting updates async.
        enabled=true
        # The amount of threads to dedicate for async lighting updates. (Default: 2)
        num-threads=2
    }
}

缓存可驯服动物的主人

启用后,所有可驯化动物的主人的UUID都会缓存起来,以节约 DataWathcer 查询时的时间。

optimizations {
    # Caches tameable entities owners to avoid constant lookups against data watchers. If mods cause issue, disable.
    cache-tameable-owners=true
}

预合并掉落物品

启用后,新生成的掉落物将会尽可能合并在一起,藉由此避免在短时间内刷新大量实体,以及此后合并掉落物引发的大量计算。

optimizations {
    # If enabled, block item drops are pre-processed to avoid
    # having to spawn extra entities that will be merged post spawning.
    # Usually, Sponge is smart enough to determine when to attempt an item pre-merge
    # and when not to, however, in certain cases, some mods rely on items not being
    # pre-merged and actually spawned, in which case, the items will flow right through
    # without being merged.
    drops-pre-merge=true
}

Panda 红石算法

An alternative Redstone update algorithm, leads to less block updates when Redstone changes.

optimizations {
    # If enabled, uses Panda4494's Redstone implementation which improves performance.
    # See https://bugs.mojang.com/browse/MC-11193 for more information.
    # Note: This optimization has a few issues which is explained in the bug report. We are not responsible for any issues this may cause.
    panda-redstone=false
}

自动调整保存时间

Minecraft官方服务器每900Tick(即45秒)就会保存一次地图。如果你想要调整这个值,可在 global.conf 文件里修改:

world {
    # The auto-save tick interval used when saving global player data.
    # Set to 0 to disable. (Default: 900) Note: 20 ticks is equivalent to 1 second.
    auto-player-save-interval=900

    # The auto-save tick interval used to save all loaded chunks in a world.
    # Set to 0 to disable. (Default: 900) Note: 20 ticks is equivalent to 1 second.
    auto-save-interval=900
}

时间间隔越低,意味着保存频率越快,因此服务器的CPU负载和硬盘占用也会随之上升,但频繁的备份对服务器断电后的回档有帮助;与之相对的是,时间间隔越高,服务器的负载也会随之降低,但当服务器出现问题导致存档丢失后,进度损失有可能会十分巨大。

实时更新

启用后将能且只能改善玩家在服务器 TPS 低时的游戏体验。此选项并不能提高性能。仅有一部分实体和方块实体,以及世界时间,将会因此从原版的固定刷新转向使用实时更新。

modules {
    # Use real (wall) time instead of ticks as much as possible
    realtime=false
}

举例:幼年动物通常需要 20 分钟成年。当服务器的 TPS 低时,每个动物获得的刷新机会会因此变少,使得成年的时间变相加长。启用此选项后,它们的一部分逻辑将会基于现实世界的时间来刷新。破坏方块的动作也能从中受益——此选项会让“反复破坏方块”的现象消失。

拒绝区块请求

警告

这是一个旨在改善性能的实验性选项,我们建议你不要在 Mod 服中启用此选项,同时建议你在使用此功能但遇到 TileEntity 加载问题时优先禁用此选项。

world {
    # If enabled, any request for a chunk not currently loaded will be denied (exceptions apply for things like world gen and player movement).
    # Note: As this is an experimental setting for performance gain, if you encounter any issues then we recommend disabling it.
    deny-chunk-requests=false
}

启用此选项后,任何试图加载当前未加载区块并执行各种操作的行为都会被拒绝。只有玩家操作及某些世界生成器允许触发区块加载。