Server RAM Allocation, Java Flags / Arguments

Discussion in 'Spigot Discussion' started by VideoklipBG, Apr 26, 2017.

Thread Status:
Not open for further replies.
  1. Hello!

    In many places and situations I've seen a lot of different opinions and allegations.

    I think everyone should know the use of -Xmx and -Xms flags (Especially in Server startup scripts / memory allocation)

    My question is that - Is it correct / incorrect and what are the influences of setting the maximum memory allocation [-XmxXXXM] and the starting memory allocation [-XmsXXXM] (X = RAM memory in megabytes, for example 128M, 1024M or 2048M) equally?

    My opinion is that when setting for example -Xms128M or 256M and -Xmx1024M (For starting memory heap size 128 and maximum 1024 which is 1GB or RAM) is more 'efficient'? I am sure that I'm wrong but I make that post because of this. :D

    I've hear that for example -Xms1024M and -Xmx1024M is more un-efficient but gives a little bit more performance and reducing the lags / stutters from Java changing the Heap Size?

    And another thing: Do -Xms and -Xmx posittions have matter? I mean -Xms to be before -Xmx flag and vice versa.

    And what are Your recommendations for "Vanilla - Spigot" Server (Spigot for more optimizations and performance, but wihtout any plugins. Just for SMP Community Survival with 10-20 People) for Memory / RAM? Do we will need some sort of 2 Gigs or 3? Because a long time ago we had Clean (Vanilla 100%) Server which supports 8-9 People with 2GB or RAM, 1GB was not enough and the Server was lagging.

    So.. Yeah. :D That is for now, if I have more questions about Arguments / Flags and cannot understand something I'll make another post or just reply bellow. Give all your opinions and reccomendations. I appreciate it a lot! :D :)
  2. electronicboy

    IRC Staff

    order of the flags doesn't matter, so long as they're before -jar whatever.jar

    Xms and Xmx should be equal to each other, otherwise you'll most likely trigger heap expansion anyways, makes more sense to preallocate the memory so that java actually has it and doesn't try to expand later (which, would be a performance hit while the process of heap expansion occurs as it generally goes alongside a full GC (Garbage Collection) which WILL hit your performance.). the "un-efficient" statement is somewhat stupid, if you're not going to be using that much memory, don't allocate that much memory.

    how much ram you allocate is really dependant on the specifics of your setup, however; 1GB of ram is generally enough, however for various reasons I generally recommend not going any lower than 2GB

    It's worth noting, 99% of people on the forums have no idea how this mechanism works, even as somebody who has tried to get an in-depth understanding of certain aspects of it, it perplexes me as to how complicated and unpredictable the system can be in certain scenarios. There are many flags that you can throw at Java in order to control certain aspects of how it handles memory, this has and will continue to be a long-standing argument in the community, especially when no set of flags are going to be 100% perfect for every setup, however; this generally goes beyond the realms of what most people can and are willing to investigate
    • Like Like x 1
  3. MiniDigger


    adding the electronicboy's last paragraph:
    somebody who did do extensive research is aikar, he wrote a small guide/explanation here:

    but if you only run a vanilla like server with ~20 players, nothing of that should bother you too much. just set xms=xmx and allocate 2 gigs and you should be fine.
    • Agree Agree x 1
  4. Yeah, but then the server is using the max memory allocated. If I set equals 2048M (2 Gigs) for -Xms and -Xms the Server is using around 2050+ - 2060+ Memory from starting. All the time.

    Can this prevent all things from normal work? Because actually the Server (Java) says that is using all the allocated memory and I don't know is this Ok.

    And I'm using some flags, especially some of these recommended by Aikar, I've readed almost all from his posts and he is very in-depth with the things.

    -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=50 -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AggressiveOpts -XX:+UseLargePages

    And overall my best launching (by opinion) line is:

    java -Djline.terminal=jline.UnsupportedTerminal -d64 -Xms1024M -Xmx1024M -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=50 -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AggressiveOpts -XX:+UseLargePages -jar MyJarFile.jar nogui

    *Edit: I mean starting the Server without players is using all memory, when someone joins the memory is the same. Don't tested for lag yet.*

    *Edit - Edit: When using 1024M or 2048M for the both minimum and maximum memory flags - The server starts using more and more memory, more than maximum allocated. Example: Starting server with -Xms1024M -Xmx1024M, from start server is using 1050 ~ 1100 MB RAM. Player joins - going up 1200 MB +, joins one or two more players - The memory goes up to 1400-1500MB +
    #4 VideoklipBG, Apr 26, 2017
    Last edited: Apr 26, 2017
  5. electronicboy

    IRC Staff

    Because the amount of memory you allocate is used only to set the size of the heap memory size in Java (The area where object instances and other information exists), Java itself needs ram in order to store additional data and runtime info (e.g. where is stuff in the heap, what is it actually doing)
    • Useful Useful x 1
  6. So the full - used memory is not 'wasted' memory? It's used for the heap size? And after some more reading to Aikar's post I've done one more little bit - changed line which do you thing is good?

    java -Djline.terminal=jline.UnsupportedTerminal -d64 -Xms2048M -Xmx2048M -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+UseLargePages -XX:+UseLargePagesInMetaspace -XX:+AggressiveOpts -XX:+AlwaysPreTouch -jar paperspigot-b1090.jar nogui

    Because he recommends to not use:
    • -XX:G1MaxNewSizePercent=60

    • -XX:G1NewSizePercent=35

    • -XX:InitiatingHeapOccupancyPercent=15
    For servers with lower than 10GB RAM. I don't know is these all flags good, but there's no way to be something 'bad'. LoL I don't know what I'm saying.. :D
  7. Sorry for this again, I am not sure / understanding is this good or not.. But actually if the Server is using without players (Empty) full amount of allocated memory (-Xms2048 -Xms2048 for example) is this Ok to be that or not?

    Don't tested yet for lag with other players or how much over the limit the memory can go.

    I understand that why the Server is using the full amount of memory (Because of the Heap Size), but don't know whether it's needed to be that.
  8. electronicboy

    IRC Staff

    The memory allocation to Java is going to grow to fill the heap, maybe not at first due to the low amount of work generally occurring (e.g. virtually no chunks loaded/no-low entity activation) but the memory will virtually always grow to the full allocation when you're talking about reasonably small allocations, it's a simple case of: If you don't want the server to use that memory, don't allocate it.

    there will be no performance impact on the server from allocating the full heap at first, the only real disadvantage is that you can't use that memory on your computer for other applications (however, you shouldn't be allocating memory you need to java anyways).
  9. DanielNaaman


    I believe that the order of the flags doesn't really matter, just make sure to keep them before the following: (JAR file)
    Code (Text):
    -jar spigot.jar
Thread Status:
Not open for further replies.