How can I get a modded Minecraft server java arguments running smoothly on my PC?

4.7K    Asked by IshiiWatanabe in Java , Asked on Oct 6, 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 warm roast, something is making the game spend a significant amount of time doing pathfinding for sheep, and a significant amount of time is spent in Update Time Light And Entities, 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 Ito Yamaguchi

Well, I eventually ended up finding a solution. Turns out, since most Minecraft server java arguments 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

Answer (1)

To get a modded Minecraft server running smoothly on your PC, you need to optimize both the server and the Java Virtual Machine (JVM) arguments. Here are some steps and tips to achieve this:


Step 1: Ensure Your PC Meets the Requirements

Modded Minecraft servers require substantial resources. Ensure your PC has:

A multi-core processor: At least a quad-core CPU.

Sufficient RAM: At least 8GB of RAM, though 16GB or more is preferable if you plan to allocate a lot of memory to the server and still run other tasks.

A solid-state drive (SSD): This significantly improves loading times and performance.

64-bit operating system: To make full use of the memory and performance.

Step 2: Install Java

Ensure you have the latest 64-bit version of Java installed. You can download it from the Oracle website or use OpenJDK from AdoptOpenJDK.

Step 3: Configure JVM Arguments

Configuring the JVM arguments correctly can vastly improve server performance. Here’s a set of JVM arguments optimized for a modded Minecraft server:

java -server -Xms4G -Xmx8G -XX:+UseG1GC -XX:MaxGCPauseMillis=50 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1HeapRegionSize=32M -Dfml.queryResult=confirm -jar forge-1.12.2-14.23.5.2854-universal.jar nogui

  • Explanation of the arguments:
  • -server: Optimizes the JVM for server performance.
  • -Xms4G -Xmx8G: Sets the initial and maximum heap size to 4GB and 8GB, respectively. Adjust these values based on your available RAM.
  • -XX:+UseG1GC: Uses the Garbage-First (G1) garbage collector, which is better for applications with large heaps.
  • -XX:MaxGCPauseMillis=50: Aims to limit the maximum GC pause time.
  • -XX:+UnlockExperimentalVMOptions: Enables experimental JVM options.
  • -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20: Sets the percentage of heap reserved for new objects and total reserve.
  • -XX:InitiatingHeapOccupancyPercent=15: Sets the percentage of heap occupancy to start a concurrent GC cycle.
  • -XX:G1HeapRegionSize=32M: Sets the size of the G1 heap region.
  • -Dfml.queryResult=confirm: Automatically confirms the server running modded content.
  • -jar forge-1.12.2-14.23.5.2854-universal.jar nogui: Specifies the server jar file and disables the GUI for better performance.

6 Months

Interviews

Parent Categories