[GUIDE] Server Optimization⚡

Discussion in 'Performance Tweaking' started by Celebrimbor, Nov 6, 2017.

  1. Celebrimbor


    In memory of frash23

    Spigot and Paper offer settings that greatly improve performance. This guide breaks down suggested values that get the most out of your server without compromising gameplay.

    Guide Updates
    - Updated for the latest 1.16.5
    - Last Update: Feb-19-2021
    - Change Log

    New server owner? Read my
    Lag Guide to understand your lag.

    Mᴀᴘ Pʀᴇ-Gᴇɴ
    Map pre-generation is critical to lag removal. Do it before you even touch your server files.
    1. Get the plugin Chunky (it's free!)
    2. Set a reasonable border distance and generate your map using the plugin commands.
    3. Wait...this may take hours depending on the map size.
    4. Leave the border (or set a vanilla world border) so new chunks never generate.
    Default: monsters:70, animals:10, water-animals:15, water-ambient:20, ambient:15
    Optimized: monsters:50, animals:8, water-animals:7, water-ambient:10, ambient:1
    Performance Impact: Heavy

    ➫ While there is more to this than "mobs per player" (explained here), lower values mean less mobs. Avoid going too low or the mob shortages will be noticeable. Subsequent values in the guide will make the reduction less noticeable.

    Def: 600
    Opt: 400
    Impact: Medium

    ➫ This unloads vacant chunks faster. Ticking fewer chunks means less TPS consumption.

    Def: monster:1, water:1, water-ambient:1, ambient:1
    Opt: monster:5, water:11, water-ambient:21, ambient:31
    Impact: Medium

    ➫ This sets how often (in ticks) the server attempts to spawn entities. Increasing the time between spawn attempts should not impact gameplay. Offsetting the tick rates spreads them out more.

    Note: Only go higher if you have significant tick loss to the mobSpawn task.

    Def: 6000 (usually)
    Opt: 6000
    Impact: N/A

    ➫ This enables Bukkit's world saving and how often it runs (in ticks). It should be 6000 by default, just double check it is not 0 (disabled).

    Note: If you use your server or a plugin to run saves, STOP! They just run the very obsolete /save-all command.

    Worldsave Lag: Lag spikes from Worldsave? You might consider Paper's lag-free saving.
    Default: false
    Optimized: true
    Performance Impact: Medium

    ➫ Should the server constantly save user data (false) or delay that task until a stop/restart (true)? This is nice TPS savings on Spigot (less on Paper since it's more efficient).

    Note: Take regular backups to avoid data loss in the rare event of a fatal crash.

    Def: tile:50, entity:50
    Opt: tile:1000, entity:1000
    Impact: N/A

    ➫ 1000 disables this feature. The small TPS savings is not worth the potential damage.
    Damage? (click here)

    Def: 8
    Opt: 6
    Impact: N/A

    ➫ This sets the max mob spawning distance (in chunks) from players. After limiting spawns in Bukkit, this will condense mobs to mimic the appearance of normal rates.

    Warning: If your view-distance is 6 or smaller, set a spawn range 1 below that value (ex. If view-distance is 5, set mob-spawn-range to 4)

    Def: animals:32, monsters:32, raiders: 48, misc:16
    Opt: animals:16, monsters:24, raiders: 48, misc:8
    Impact: Medium

    ➫ Entities past this range will be ticked less often. Avoid setting this too low or you might break mob behavior (mob aggro, raids, etc).

    Note: Villagers should be left alone (if possible) to protect mechanics.

    Def: true
    Opt: false
    Impact: Medium

    ➫ Enabling this prevents the server from ticking villagers outside the activation range.

    Note: Vanilla behavior ticks all villagers in loaded chunks. Enable villagers-active-for-panic to save some iron farms from breaking.

    Def: item:2.5, exp:3.0
    Opt: item:4.0, exp:6.0
    Impact: Medium

    ➫ Merging items means less ground item ticking. Higher values allow more items to be swept into piles.

    Note: Merging will lead to the illusion of items disappearing as they merge together. A minor annoyance.

    Def: false
    Opt: true
    Impact: Medium

    ➫ When enabled, mobs from spawners will not have AI (will not swim/attack/move). This is big TPS savings for massive mob farms, but also messes with behavior. A farm limiter plugin might be a better solution.

    Note: Paper has an option to force nerfed mobs to jump/swim. This fixes water push farms.

    Def: 6000 (5 minutes)
    Opt: less?
    Impact: Situational

    ➫ The time (in ticks) before a ground item is removed. While the TPS savings can be significant if reduced, it also impacts gameplay on servers where returning to dropped items is critical.

    Note: See Paper's alt-item-despawn-rate so you can target trash items (cobblestone) without clearing valuable items.

    Def: 1200
    Opt: 300
    Impact: Minor

    ➫ Similar to item-despawn-rate, but for arrows. Some servers may want to keep arrows on the ground longer, but most will have no complaints if removed faster.

    Note: Paper has settings to reduce the gameplay impact of arrow removal. Leave this near default if you use Paper's arrow options.
    Still have lag after optimizing? Maybe try Paper.

    Warning: Paper is an unofficial fork and is not supported on Spigot forums. If you have issues related to Paper, report them on Paper's issue tracker, not on Spigot!

    Default: 24
    Optimized: 6
    Performance Impact: Heavy

    ➫ This slows down incremental chunk saving during the world save task. This is incredibly important for modern servers (world saving sucks).

    Note: Setting this too low might result in unsaved chunks, so avoid going lower.

    Default: false
    Optimized: true
    Impact: Minor

    ➫ Paper has a very efficient algorithm for explosions with no impact to gameplay.

    Def: 1
    Opt: 2
    Impact: Minor

    ➫ This is the delay (in ticks) before an active spawner attempts spawns. Doubling the delay will not impact spawn rates. Only go higher if you have significant tick loss from ticking spawners.

    Def: false
    Opt: true
    Impact: Minor

    ➫ Chests scan for a cat on top of it when opened by a player. While enabling this eliminates vanilla behavior (cats block chests), do you really need this mechanic?

    Def: 1
    Opt: 3
    Impact: Minor

    ➫ This changes how often (in ticks) inventories are refreshed while open. Do not exceed 4 to avoid visual issues.

    max-entity-collisions (in Spigot.yml in some builds)
    Def: 8
    Opt: 2
    Impact: Medium

    ➫ Crammed entities (grinders, farms, etc.) will collide less and consume less TPS in the process.

    Def: 1
    Opt: 4
    Impact: Medium

    ➫ The time (in ticks) before the server tries to spread grass in chunks. This will have no gameplay impact on most game types.

    Def: soft: 32, hard: 128
    Opt: soft: 28, hard: 96
    Impact: Minor

    Soft = The distance (in blocks) from a player where mobs will be periodically removed.
    Hard = Distance where mobs are removed instantly.

    ➫ Lower ranges clear background mobs and allow more to be spawned in areas with player traffic. This further reduces the gameplay impact of reduced spawning (bukkit.yml).

    Def: false
    Opt: true
    Impact: Heavy

    ➫ This will significantly reduce hopper lag by preventing InventoryMoveItemEvent being called for EVERY slot in a container.

    Warning: Plugins that listen for InventoryMoveItemEvent will break.

    Def: -1 (uses Spigot arrow-despawn-rate)
    Opt: 60 (3 seconds)
    Impact: Minor

    ➫ Similar to Spigot's arrow-despawn-rate, but targets skeleton-fired arrows. Since players cannot retrieve mob arrows, this is only a cosmetic change.

    Def: -1 (Spigot arrow-despawn-rate)
    Opt: 60 (3 seconds)
    Impact: Minor

    ➫ Like the setting above, but for player-fired arrows that cannot be retrieved (infinity bows).

    Def: false
    Opt: true
    Impact: Medium

    ➫ Prevents players from entering an unloaded chunk (due to lag), which causes more lag. The true setting will set them back to a safe location instead.

    Note: If you did not pre-generate your world (what's wrong with you?!) this setting is critical.

    Def: false
    Opt: true
    Impact: Heavy

    ➫ This setting reduces redundant redstone updates by as much as 95% without breaking vanilla devices. Empirical testing shows a speedup by as much as 10x!

    Note: If you use a plugin to change redstone algorithms, consider replacing them with this option as plugins tend to break redstone behavior.

    Def: true
    Opt: false
    Impact: Minor

    ➫ Some items are viewed as entities (require ticking) since they interact with the world. Unticked armor stands will not get pushed by water (do you care?)

    Note: Paper also offsets item frame ticking instead of ticking all frames at once. This is not configurable, just enjoy the TPS savings with no gameplay impact.

    Def: false
    Opt: true
    Impact: Minor

    ➫ This implements singleplayer spawning behavior instead of Bukkit's random algorithms. This prevents the actions of others (i.e. Massive farms) from impacting the server's spawn rates.

    Note: If you lowered spawn-limits in Bukkit and notice shortages of animals and monsters, consider bumping those back up until you find a happy place.

    Def: false
    Opt: true
    Impact: Medium

    ➫ Remove certain item drops faster (or slower) than the item-despawn-rate set in Spigot. This lets you avoid ticking massive piles of garbage.

    Example of despawning cobblestone and netherrack in 15 seconds:
    Code (Text):
          enabled: true
            COBBLESTONE: 300
            NETHERRACK: 300
    Note: Use the Spigot material list when adding items.

    Def: -1
    Opt: # > view-distance setting
    Impact: N/A

    ➫ This is the distance at which chunks are loaded, but will still not be ticked outside your view-distance.

    Note: If you had to set your view-distance really low (like 3 or 4), you might set this at 5 or 6 to improve your gameplay experience.

    Def: false
    Opt: true
    Impact: N/A

    ➫ While this setting will actually cost TPS, Paper's anti-xray is the most efficient in existence! Engine 1 might be less heavy (mainly for clients), but mode 2 is by far more effective.
    Def: 10
    Opt: 4-8
    Impact: Heavy

    ➫ This is the most impactful setting in all your files as it caps the chunk render distance. Open world servers (like Survival) should strive to use 6+, but others on shared hosts, low specs, or huge player counts might consider 4-5 if chunk gen causes lag.

    Warning: See note in mob-spawn-range (spigot.yml) if you set your view distance lower than 7.

    Default: 256
    Optimized: Standalone(512) BungeeCord(-1)
    Impact: Minor

    ➫ This option caps the size of a packet before the server attempts to compress it. Setting it higher can save some resources at the cost of bandwidth, setting it to -1 disables it.

    Note: If your server is in a network with the proxy on localhost or the same datacenter (<2 ms ping), disabling this (-1) will be beneficial.
    Save precious resources by running/disabling tasks per world! Learn how here (PDF).
    Jᴀᴠᴀ Sᴛᴀʀᴛᴜᴘ Fʟᴀɢs

    The guide below is by a core Spigot/Paper developer and the creator of the timings program. It is applicable to 99% of servers.

    Note: Most shared hosts do not allow changes to flags. Try asking for that feature.

    For assistance outside the parameters of this guide, you are best served posting your issue/question in the Performance Tweaking forum so the entire community can help.

    Attached Files:

    #1 Celebrimbor, Nov 6, 2017
    Last edited: Mar 17, 2021
    • Like x 165
    • Useful x 76
    • Winner x 42
    • Agree x 17
    • Informative x 13
    • Friendly x 13
    • Optimistic x 5
    • Creative x 4
    • Funny x 1
  2. Celebrimbor


    Lᴀɢ Tʏᴘᴇs

    TPS - Server Lag

    TPS stands for Ticks Per Second. It is also the only lag type a server owner has direct control over. The guide above is exclusively intended to improve TPS.

    A server processes all tasks at a rate of 20 TPS. Tasks like mob movement, crop growth, and player interactions with blocks need to be ticked by the server to function properly. A TPS below 20 means the server is running behind and must skip tasks in order to keep important tasks on time. Significant TPS loss usually presents itself with minor annoyances like intermittent mob freezing and block break resets. Severe cases could result in server-wide freezes or even crashes.

    TPS Ratings
    20.0 = Flawless - Well done.
    19.95-19.99 = Great - Unnoticeable TPS loss. Most servers live here.
    18.5-19.94 = Fair - Maybe some annoyances, but nothing game-ruining.
    16.0-18.4 = Poor - You definitely need to fix this if this is your average.
    <16.0 = Unplayable...

    Ping - Connection Lag
    Ping (aka latency) reflects how long (in milliseconds) data takes to process and travel between the client and server host. The further a client is geographically separated from the server, the longer this transfer might take. Other common influences on ping are congested or slow connections.

    As a server owner (assuming you have a choice) you should host your server in a region where you prefer to have your player base or one that appeases a broad range of players.

    Example: Eastern US is good for most of the US, CA, and UK, while Central US is more ideal for just US and CA.

    Ping Ratings
    1-90 = Great!
    91-179 = Good - Maybe a slight disadvantage in PvP.
    180-299 = Poor - Regular lag while interacting with blocks/players/entities.
    300-499 = Bad - Nearly unplayable.
    500+ = Assuming your bandwidth is solid, it's time to find a server closer to you.

    FPS - Client Lag
    Do not confuse TPS with FPS (Frames Per Second). FPS reflects a client's ability to process and display what the game/server wants to render. FPS is 100% client side and has nothing to do with server performance.

    The only thing a server can do to help FPS is cut server features so dinosaur PCs can keep up, but even that is unlikely to make a big difference. Instead of reducing server features, recommend a popular client mod called Optifine to players.

    FPS Ratings
    Note: These rates assume your standing average in a non-graphic-intense location.
    60+ = Perfect - Anything over 60 FPS is overkill for Minecraft. Consider capping FPS below 80 to avoid unnecessary stress on hardware.
    40-59 = Great - Should have no issues.
    25-39 = Good - Occasional rendering lag. Issues if you enter graphic-intense areas.
    15-24 = Poor - Constant rendering glitches. Probably freeze in GI area.
    1-10 = Bad - Client should significantly reduce graphic settings.

    Timing Reports
    Invest time in watching this informative video guide on the Timings program. The video breaks down Timings v1(Spigot) and v2(Paper). The video length is intimidating, but any serious server owner should know how to identity their server's issues.

    If you prefer reading, the Timings guide is explained at length here.
    #2 Celebrimbor, Nov 6, 2017
    Last edited: Jan 8, 2021
    • Informative x 37
    • Useful x 31
    • Like x 24
    • Winner x 12
    • Agree x 9
    • Friendly x 2
  3. Extremely interesting reading everything here. Well written and useful!
    • Agree Agree x 23
    • Like Like x 5
    • Friendly Friendly x 3
    • Funny Funny x 1
  4. For Australia and you cannot get an Aussie VPS/Dedi then West Coast USA.

    For Linode best is fremont

    Code (Text):
    ping -c 5 speedtest.fremont.linode.com
    PING speedtest.fremont.linode.com ( 56 data bytes
    64 bytes from icmp_seq=0 ttl=56 time=243.9 ms
    64 bytes from icmp_seq=1 ttl=56 time=243.6 ms
    64 bytes from icmp_seq=2 ttl=56 time=243.5 ms
    64 bytes from icmp_seq=3 ttl=56 time=243.3 ms
    64 bytes from icmp_seq=4 ttl=56 time=243.1 ms

    --- speedtest.fremont.linode.com ping statistics ---
    5 packets transmitted, 5 packets received, 0% packet loss
    round-trip min/avg/max = 243.1/243.4/243.9 ms
    • Winner Winner x 1
    • Optimistic Optimistic x 1
  5. Celebrimbor


    Everyone knows that an Australian server with decent player pings is a mythological creature.

    On a serious note, thanks for the input. I am not trying to get too deep into minutia of individual server types/locations or into the dissection of lag variables. The focus is the yml options and the general basics for new server owners. :)
    • Funny Funny x 7
    • Like Like x 1
  6. Celebrimbor


    I appreciate the feedback. I really do obsess over perfection and I wanted to make sure I did this right considering the origins of the idea... this comment was uplifting :)
    • Like Like x 4
  7. This is fantastic. Thanks for also considering paper users <3 Keep up the great work @Celebrimbor
    • Friendly Friendly x 3
  8. electronicboy

    IRC Staff

    Hai, just wanted to clarify a few things;

    regarding autosaving, this isn't entirely async, the writing to the disk is queued, but the actual process of live world -> NBT is sync for reasons of safety, the major difference between autosaving and /save-all is the fact that save-all actually forces all chunks to save, whereas the mechanism in the server that bukkit exposes is incremental, only saving 24 chunks per tick. Spigot modifies this, and no longer limits the number of chunks that can save per tick, but attempts to save all chunks which haven't been saved in so long. Paper has a few patches that brings back the limit (prevents filling the queue up with NBT, which can take a fair amount of memory), and only saves chunks which either have entities or have been modified (as opposed to just modified chunks), and allows you to configure it all per world (do you really need your spawn to save?).

    max-entity-collisions was actually removed from spigot when 1.11 added the maxEntityCramming; Paper has added this patch back and tries to pull the config back from spigot (which as a side effect causes the setting to appear back in spigot.yml, doh)

    with the entity activation range stuff and merging, item despawn isn't a major concern, the impact is situational, of course, there is still some level of evaluation, the server has to check if it's been marked as activated or not. Only on servers where a lot of entities are dropped, e.g. mass PvP servers, should there really be a need to drop this from the default. (This is one of the many overlooked features of the server config...)

    disable-cat-chest-protection this only effects opening chests, the server does not scan for cats sitting ontop of chests every tick, it only does it when you open a chest; as it does a bounding box lookup for the chest itself and the paired chest, which isn't very ideal when you have lots of players running around opening chests.

    min-chunkload-threads is a bit of an iffy one, I would really not advice playing with this unless you determine that you'd actually benefit from this, increasing this value increases the disk load and the cpu load, this all has to go back to the main thread, increasing this setting can actually hurt TPS needlessly.

    pushbased-hoppers is an amazing performance boost, but currently broken in various ways. Fixing this is on my todo list, but it might be a while before I can look at it properly. I would not recommend using this at this current moment in time.

    Updating the paper documentation is on the todo list, however tooling issues and everbody just being crazy busy kinda got in the way.
    • Like Like x 4
    • Agree Agree x 1
    • Useful Useful x 1
  9. Celebrimbor


    Autosaving- Changed some wording, but still trying to keep it simplistic for new owners.

    Collisions- I think I will keep this in there(for now) since it applies to most actively used versions and is still an option(if you use Paper). It's harmless to modify on 1.11+ unless I missed something.

    Activation, merging and despawn- I think I am clear enough that despawn is a desperate change and situational, but activation and merging are a general safe change with almost all positive returns. I will add a note suggesting that owners should only apply the max "optimized" values if they have a notable load from activated/dropped entities.

    Chunk loading- I have left this situational with notes that it only applies to custom/amplified maps because I have done extensive testing on those map types on 3 and 4 threads. 3, while minimal, had a notable improvement for chunk loading. 4 saw no change. My notes are pretty clear that most should leave this alone, but I will stress this more.

    Cat chests- Clarified event to be accurate.

    Hoppers- I added a note to warn against usage. I hope you can fix, this is a biggie...

    Thanks for your input!

    Edit: If you take the time to re-review, please let me know if I missed something well-worth mentioning.
    #9 Celebrimbor, Nov 7, 2017
    Last edited: Nov 7, 2017
    • Like Like x 1
  10. @Celebrimbor you're always helping the community out, good on you man. Many people will benefit from this, and @frash23 will never be forgotten.
    • Friendly Friendly x 3
  11. Celebrimbor


    Thank you for the kind comment. I put a lot of time into this making sure it was done right.

    I remember back in the day benefiting from the original guide(along with hundreds if not thousands of others) and it killed me watching the locked thread slip into the abyss.
    • Agree Agree x 2
    • Friendly Friendly x 1
  12. This is great thread.
    I liked this. Thanks for your info for Server-Performance!!!
    • Friendly Friendly x 1
  13. Question: This optimize is for 1.12.x or only 1.12.2? Because my server version is 1.12-1.12.1 and 1.12.2 (With ViaVersion).
  14. Celebrimbor


    This thread is based on the options available in Spigot/Paper 1.12.2. If your server type is Paper 1.12.0, then the only option you will not see is the anti-xray(it was just added recently). If you are on Spigot 1.12.0, then you will also not see the max-entity-collisions option(which is removed on 1.11+). Paper mistakenly forced it back in for 1.11+ servers (oops).

    Keep in mind that basically all these options are available in 1.8-1.12, so it's not specifically optimized for a specific version. Newer versions just might have more tools. :)
    • Like Like x 1
  15. Celebrimbor


    I added a PDF document further explaining the Bukkit.yml spawn-limits numbers...for those that really need to know how it works. Be prepared to do math...

    The PDF is in the original post. Enjoy!
    #15 Celebrimbor, Nov 9, 2017
    Last edited: Nov 9, 2017
    • Like Like x 2
    • Winner Winner x 1
  16. How nice of you in frash’s memory!
    • Like Like x 1
    • Friendly Friendly x 1
  17. Celebrimbor


    It shouldn't be done any other way. Guy was legendary...
    • Agree Agree x 1
  18. Agreed. It is very nice of you to do this. :p
    • Like Like x 2
  19. Great
    • Like Like x 2
  20. @Celebrimbor Thank you for the attached PDF on bukkit spawns! Big help +1
    • Like Like x 2
    • Funny Funny x 2