Can I smoothly run the Minecraft server java requirements?

460    Asked by AryanTandon in Java , Asked on Oct 13, 2022

 I'm looking to run a modded minecraft server (1.12.2) for myself and a friend to play on. There are quite a few mods we're looking to use, and I'd like to know what I can do to make the server run more smoothly. As of right now, it lags quite a lot, even with a freshly-generated world. Looking around online, all the information I can find feels like it's at least a little bit outdated, and sometimes a lot outdated. So while this is looking to get a particular server up and running, I'd also appreciate anything about generally optimizing performance using current versions of java.


According to LagGoggles, the main culprits seem to be mobs, with one or two (which one changes each time I run it) taking ~20-30 ms per tick each time I run the profiler.


According to warmroast, something is making the game spend a significant amount of time doing pathfinding for sheep, and a significant amount of time is spent in UpdateTimeLightAndEntities, about 80% of the server thread's resources.


Is there a mod that optimizes entity calculations? Or perhaps a way to determine which mods are most adversely affecting performance, so I know which ones to focus on removing or fiddling with configs?


The server is running on a computer with a Ryzen 2200G (probably soon to be upgraded to a 3600, though--hopefully that helps) and 16 GB of DDR4-2666 RAM. It also has a GTX 1060-6GB but I'm reasonably certain the graphics card doesn't matter for this. (would be nice if I could offload some computing load onto it, though.... Is there a way to do that?)


I'm using OpenJDK 8, with the OpenJ9 JVM, starting the server with the command "C:Program FilesAdoptOpenJDKjdk-8.0.242.08-openj9binjava.exe" -server -XX:+UseG1GC -Xmx8G -Xms8G -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M -jar forge-1.12.2-14.23.5.2847-universal.jar. I don't actually know what most of these flags do, but I was told they would help. And I think they did, at least a little, but there's still a lot of lag.

Answered by Micahel Jeffs

Well, I eventually ended up finding a solution for the Minecraft server java arguments. Turns out, since most Minecraft mods are made by hobbyists and not experienced coders, there are some bad programming habits that are common to them, and one of those appears to be calling explicit garbage collection, way too frequently, eating massive amounts of CPU time.


As such, adding the -XX:+DisableExplicitGC flag to the java arguments helps a lot, and then various other tweaks to the automatic garbage collector, found on this blog post from someone who knows much more about what they're doing than I do, dropped CPU usage from constantly 60% to as low as 1% when no one's online, and tick time is now fairly constant at 2~10 milliseconds instead of idling at 0.3 ms and spiking to ~400 ms.

For the purpose of not making this effectively a link-only answer, below are the JVM arguments the above blog post proposes using for any minecraft version between 1.8 and 1.15:

java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=8 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=true -Daikars.new.flags=true -jar serverjargoeshere.jar

The source says that you should feel free to change the -Xmx and -Xms arguments to the amount of memory you wish to use, and everything should work fine. Not mentioned in the source is that these flags appear to help client performance as well as server performance, though perhaps not to the same extreme degree.



Your Answer

Interviews

Parent Categories