Get a VPS server with a 15% discount
Sale ends in
00Days
:
00Hours
:
00Minutes
:
00Seconds

Startup parameters

These are special options that allow you to optimize the server startup and its further performance.

 

Let’s start with a small example:

java -jar server.jar

 

This is the most basic script to start the server core, with no additional arguments specified.

 

Now to the parameters themselves

-jar — this argument specifies the type of the Java file being launched.

name.jar — the name of the file to be launched.

nogui — starts the server without a graphical interface, since we simply do not need it.

 

Core flags

-xincgc — enables a "garbage collector" that periodically frees unused RAM. The specific collector type is selected automatically depending on the Java version.

-server — enables the server Java mode, where support for experimental flags is enabled by default. It also speeds up class compilation, which improves performance, but increases server startup time (supported only on 64-bit systems).

 

Allocating RAM

 

The arguments support both "M" for megabytes and "G" for gigabytes. For example, the "Xms2G" argument will start the server with 2 gigabytes of RAM allocated.

-Xmx0000M — the maximum amount of memory that can be allocated to the server.

-Xms0000M — the minimum amount of memory allocated to the server.

-Xmn0000M — the amount of memory allocated for temporary (young generation) objects.

-XX:MaxPermSize=0000M — the amount of memory for the PermGen Space (does not work on Java 8).

-XX:SharedReadOnlySize=0000M — the amount of memory for the read-only area in PermGen.

 

Garbage collectors

 

For single-core CPUs you can use any garbage collector, but do not specify the number of threads for it. At the moment, the best collector is ConcMarkSweepGC. The higher the SurvivorRatio, the better: fewer old objects will clutter RAM. The higher the TargetSurvivorRatio value, the more objects will be cleaned up (it is recommended not to set it above 90). It is best to use MaxGCPauseMillis with G1GC or with a specific garbage collector. AutoGCSelectPauseMillis is used with the collector selected automatically by the system. It is better not to set G1HeapRegionSize manually: Java will choose the optimal value; set it only if you know exactly what you are doing.

 

-XX:+UseSerialGC — enables a garbage collector that runs in a single thread.

-XX:+UseConcMarkSweepGC — enables a garbage collector that uses the power of multiple CPU cores.

-XX:ConcGCThreads=2 — the number of threads allocated to the garbage collector.

-XX:+UseG1GC — enables the new garbage collector that splits the heap into regions and, using multiple cores, collects unused memory across all regions.

-XX:G1HeapRegionSize=32 — the amount of RAM allocated for each region.

-XX:AutoGCSelectPauseMillis=2500 — the time in milliseconds between calls to the automatically selected garbage collector.

-XX:MaxGCPauseMillis=1000 — the pause duration in milliseconds between calls to a specific garbage collector. For G1GC it acts as the maximum allowed pause.

-XX:SurvivorRatio=8 — the ratio that defines the size of the survivor spaces (the smaller the number, the more space). More space allows newly created objects to live longer before being collected.

-XX:TargetSurvivorRatio=90 — the percentage of space reserved for survivor objects, which allows more unused objects to be cleaned up during garbage collection.

-XX:+UseBiasedLocking — speeds up object synchronization on multi-core CPUs.

-XX:+UseFastAccessorMethods — uses optimized versions of accessor method calls.

-XX:+UseFastEmptyMethods — excludes empty methods from compilation.

XX:+UseCompressedOops — reduces the size of pointers, object headers and internal offsets. Depending on the code, this can save 20–60% of RAM.

As a result, we get the following sample script to start the server:

 

java -Xincgc -Xms512M -Xmx4G -XX:MaxPermSize=128M -XX:SharedReadOnlySize=30M -XX:+UseConcMarkSweepGC -XX:+UseBiasedLocking -XX:+UseFastAccessorMethods -XX:+UseCompressedOops -jar server.jar nogui