Skip to content

Instantly share code, notes, and snippets.

@spullara
Created March 30, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spullara/88ebeeac3ab5db5fa2484d58afd76c39 to your computer and use it in GitHub Desktop.
Save spullara/88ebeeac3ab5db5fa2484d58afd76c39 to your computer and use it in GitHub Desktop.
Java Settings
-Xmx
Set the maximum heap size. Beware going between 32G and 50G if you have a lot of objects since CompressedOops will not be after 32G.
-XX:+UseG1GC
It works now for us by default.
-XX:+UseStringDeduplication
This can usefully reduce your footprint if you have a lot of duplicate strings in your application. There is little benefit to
not enabling it.
-Djdk.xml.entityExpansionLimit=0
When parsing XML the JVM will go out and try and expand entities like DTDs. You don't want this to happen.
-Dsun.net.inetaddr.ttl=60
Generally you don't want the default TTL of forever for DNS lookups in production applications.
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/mnt/dumps
-XX:ErrorFile=/mnt/dumps/hs_err_pid_%p.log
If your JVM runs out of memory, rather than just throwing an OOME it instead does a complete heap dump that can be later analyzed
with jhat to see exactly what was using the heap. Make sure you have at least the max memory size available on disk.
-verbosegc
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-XX:+PrintTenuringDistribution
-XX:+PrintHeapAtGC
-XX:+PrintStringDeduplicationStatistics
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=3
-XX:GCLogFileSize=10M
-Xloggc:\/mnt\/logs\/${appName}-gc.log
I heard you were interested in what was going on in GC.
-XX:+OptimizeStringConcat
Avoids even creating a StringBuilder in many cases. https://groups.google.com/forum/#!topic/jvm-languages/KtVBYfeT83g
-XX:+UseCompressedOops
With heaps that are less than 32GB, you can save 4 bytes per pointer by enabling this.
-XX:+UnlockDiagnosticVMOptions
-XX:ParGCCardsPerStrideChunk=32768
Ideal for large heaps.
-XX:+AlwaysPreTouch
Intializes memory upfront rather than at runtime.
-XX:-OmitStackTraceInFastThrow
Can be quite painful when debugging. We turn it off.
-XX:+ScavengeBeforeFullGC
Can improve the performance of a full GC in the sad case that you run one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment