[GUIDE] Optimizing Spigot - Remove lag, Fix tps & Improve performance!

Discussion in 'Performance Tweaking' started by frash23, Jun 22, 2014.

Thread Status:
Not open for further replies.
  1. Last updated 2016-04-04

    Spigot has a lot of performance improvements disabled by default, as they often alter the server so it no longer replicates vanilla behavior. This guide is supposed to help you tweak the settings for optimal performance while understanding what you are actually changing. If you do not understand a setting I mention here, don't change it. If you are curious, reply to the thread (make sure to @Tag me) and ask me what it does. If you are still having issues with performance, take timings (2-5 minutes) and reply here, or make a new thread.

    I'll list all the config values you can consider tuning to improve performance while doing my best to explain what the setting does and when you do/don't want to change it.

    The guide is currently written for 1.9. Most options appear in 1.8 as well. If they don't, just go to the next option.



    1. paper.yml

    You will need Paper, a fork of Spigot, to have this file available.

    WARNING: Paper is an unofficial version of SpigotMC and not officially supported. It is slightly less stable, but cutting edge / fast.
    If you get issues while using Paper, they should be reported on Paper's issue tracker, not to SpigotMC.
    Additionally, linking to any Paper-related projects in replies to this thread is NOT allowed and will be removed / get the thread locked!

    optimize-explosions
    Default: false
    Suggested: true
    mob-spawner-tick-rate
    Default: 1
    Suggested: 2 - 3
    disable-chest-cat-detection
    Default: false
    Suggested: true
    use-hopper-check
    Default: false
    Suggested: true
    container-update-tick-rate
    Default: 1
    Suggested: 3 - 4
    queue-light-updates
    Default: false
    Suggested: true
    fire-physics-event-for-redstone
    Default: true
    Suggested: false
    grass-spread-tick-rate
    Default: 1

    Suggested: 2 - 4


    2. spigot.yml

    late-bind
    Default: false
    Suggested: true
    mob-spawn-range
    Default: 4
    Suggested: 3
    entity-activation-range
    Default: animals:32, monsters:32, misc:16
    Suggested: animals:6, monsters:16, misc:2
    hopper-transfer, hopper-check, hopper-amount
    Default: transfer:8, check:8, amount:1
    Suggested: transfer:24, check:24, amount:3
    max-entity-collisions
    Default: 8
    Suggested: 1 - 2
    merge-radius
    Default: item:2.5, exp:3.0
    Suggested: item:3.5, exp:6.0
    view-distance
    Default: 10
    Suggested: 3 - 5


    3. bukkit.yml

    spawn-limits
    Default: monsters:70, animals:15, water-animals:5, ambient:15
    Suggested: monsters:50, animals:10, water-animals:3, ambient:4
    chunk-gc
    Default: period-in-ticks:600, load-threshold:0
    Suggested: period-in-ticks:300, load-threshold:300
    ticks-per.monster-spawns
    Default: 1
    Suggested: 2 - 5


    4. server.properties

    network-compression-threshold
    Default: 256
    Suggested (standalone server): 512
    Suggested (behind local Waterfall/BungeeCord): -1


    5. Java & Launch flags

    Always make sure you're on the latest version of Java! (Currently 8)
    Some features are only present in Java 8, as well as being more optimized.
    If you for some reason are stuck on Java 7, you will need to add the -XX:MaxPermSize=128M flag to your launch script.

    Some people will tell you that launch flags are placebo and you should stick to just -Xmx.
    This is for a large part true. However, the garbage collector can play a large role in performance and memory usage. The best way to tweak the garbage collector to our needs is using flags.
    @Aikar has put a lot of time and effort into researching and testing different garbage collection setups, and recommends the following flags:
    Code (Text):
    java -Xmx8G -Xms8G -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=45 -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AggressiveOpts -jar spigot.jar

    Flags are explained in @Aikar's article here.

    Large pages can also improve memory performance a lot:
    Code (Text):
    -XX:LargePageSizeInBytes=2M -XX:+UseLargePages -XX:+UseLargePagesInMetaspace
    However, this requires configuration of your Linux system and can potentially break it. You should only attempt setting up large pages if you understand what they are and how to set them up.
    @Aikar's recommendation on finding the right values to set:
    Note: -XX:+UseLargePagesInMetaspace is Java 8 only!



    You can also consider a plugin like ClearLagg if entities are your problem and none of the above settings are working for you. I do not recommend using the automatic entity clearing provided by ClearLagg. Disable them when you get the plugin. You're interested in features like mob-range and chunk-entity-limiter.



    And you're done! If you are still experiencing issues, feel free to take timings (2 - 5 minutes) and post them here, or create a new thread.
     
    #1 frash23, Jun 22, 2014
    Last edited: Jul 1, 2016
    • Useful x 132
    • Like x 50
    • Winner x 15
    • Agree x 5
    • Informative x 5
    • Friendly x 4
    • Creative x 3
    • Optimistic x 2
    • Funny x 1
  2. joehot200

    Supporter

    =====This guide has been updated, and this comment is no longer correct=====


    I personally do not think that the script goes in-depth enough and IMO does things that I personally do not agree with or do not think are the best option.

    Some things listed here will greatly decrease performance for players, i.e. if they want to have a mob farm.

    Other things will just cause mobs to spawn slowly.

    And other things here will just annoy players.

    Then other things such as activation range to 32 for stuff is not a good idea if you have a lot of lag. In reality, 20 is still acceptable and can save on a lot of lag.

    You are saying what works best for you, but in my opinion you are not giving people enough information on what each thing you are discussing is for them to actually make an informed decision for themselves about it.

    Edit: And hopper ticks? 6? In reality, 20 is still fine and does not annoy players.

    Edit2: Clearlag is a good recommendation, I agree wholly with that.

    Edit3: I do not see what giving high priority is good for unless on shared hosting or a VPS. For a dedi it is useless unless you have other things which may be maxing out the CPU which you do not feel are as important.

    Edit4: If you ask me, your item despawn rate is low. It may take more than 2 minutes for a member to get back to where he died, in which case, his items are gone.

    Edit5: What is with all the detrimental and unhelpful startup flags, some of which will actually make the server run slower? Oh, and what happened to -Xincgc? :(

    Edit6: Misc to 48? Misc is like, XP orbs, etc. Why do they need to be activated 48 blocks from the player? Why not just 10?
     
    #2 joehot200, Jun 22, 2014
    Last edited: Jul 4, 2015
    • Useful x 10
    • Agree x 4
    • Informative x 3
    • Like x 1
    • Optimistic x 1
  3. I know we had a little argument yesterday and Ill say im sorry for getting back at you.

    This really helped, thanks a lot. ;)
     
    • Friendly Friendly x 5
    • Agree Agree x 1
    • Funny Funny x 1
  4. I added details on the script, good point on that.

    It might decrease some gameplay elements, but the smoothness / lag of the server will be better. Read the note after config stuff ;)

    Spawning mobs slower is not always bad - I have had issues with way too many mobs.

    Exactly what will annoy players?

    Well, if you say so. I'll edit that in.

    Argh, I forgot to link to the bukkit.yml and spigot.yml wiki :( Thanks for the reminder!

    You're probably right, I'll edit that in.

    It can help a little, even if you aren't hosting anything else, so there's no real reason to not have it.

    As for item despawn rate, I suppose you're right. This was written a bit in a hurry.

    I have tested most of the flasgs to improve performance. I am adding details for the flags in a min.

    I was unsure what misc did, I'll edit that.
     
    • Like Like x 2
    • Agree Agree x 2
  5. Dmck2b

    Services Staff

    Might be nice to generalise it a bit more then add it as a wiki page.
     
    • Agree Agree x 4
    • Like Like x 1
  6. I might consider doing this, I just have a feeling more people will see it here.
    You probably know more about java than me; which flags would you remove? Any you'd recommend adding?
    I have personally gotten better garbage collection from ConcMarkSweepGC, I believe Sk89q recommended this.

    I believe @vemacs did some garbage collection benchmarking as well?
     
  7. I wonder what would be good for a kitpvp server. Since I own one a lot of stuff probably could be disabled in them configs.
     
  8. Most of the growth settings, disable all mob spawning, use a view-distance of 6-8, make player activation-range very high, all others low.
    Otherwise, use all the tweaks in the main post.
     
    • Like Like x 1
  9. Intentional?
     
    • Winner Winner x 1
  10. Missed that. Thanks!
     
  11. Your welcome, also very nice guide but you may want to explain what all of those JVM options do :).
     
    • Agree Agree x 1
  12. Ok thanks
     
  13. Really nice guide!
    Helped me a lot, good job bro :D
     
  14. At what Factions bug do you mean?
     
  15. It has been reported a few times here - factions can be abused to load a huge amount of chunks (10K+).
     
    • Like Like x 1
    • Informative Informative x 1
  16. Any idea why my server times out? Does it have to dow ith the Spigot config?
     
  17. Did it begin happening after you tweaked the config?

    If not, create your own thread.
     
  18. I was really looking for very long time after a good startup script for my server with Java 8, thanks!
    EDIT://Are you able to explain every flag in that startup script? I can't find any clear explanation to every..
     
    #18 TheMcGuider, Jun 23, 2014
    Last edited: Jun 24, 2014
    • Agree Agree x 1
  19. Hello, do you happen to know the best configuration for a Plot based survival server? I don't believe that PVP is enabled if that helps and I'm hoping that it will help fix our problem (http://www.spigotmc.org/threads/low-tps-block-lag.22026/#post-241707)

    We are reluctant to try all these options given the mention of mob farms earlier which a lot of our players have.

    Many thanks,
    Connor
     
Thread Status:
Not open for further replies.