10. Pros and Cons
Pros
- Programmer does not need to worry about memory (de-)allocation
(leading to fewer memory leaks)
Cons
- Performance overhead
- Can lead to more complex programming language design
10
13. Garbage Collection
Algorithms
13
Tracing Reference Counting
Collection Style Batch Incremental
Cost Per Mutation None High
Throughput High Low
Pause Times Long Short
Real Time? No Yes
Collects Cycles? Yes No
40. Fun with JVM Options
Most important
-server
Crucial for all long-running server applications.
http://stackoverflow.com/questions/198577/real-differences-between-
java-server-and-java-client
40
41. Fun with JVM Options
Most important (cont’d)
-Xms (-XX:InitialHeapSize)
-Xmx (-XX:MaxHeapSize)
Setting Xms = Xmx (slightly) saves some overhead.
41
42. Fun with JVM Options
Enable GC logs
-Xloggc:logs/gc-<app>.log
-XX:+PrintGCCause
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintHeapAtGC
-XX:+PrintTenuringDistribution
-XX:+PrintGCApplicationStoppedTime
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=2
-XX:GCLogFileSize=128M
42
43. Fun with JVM Options
Enable JMX remoting
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=<port>
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
43
44. Think about your program
https://flink.apache.org/news/2015/05/11/Juggling-with-Bits-and-Bytes.html
44
46. Best practices
“Good” JVM options to start with
-server
-Xms1g
-Xmx1g
-XX:+AlwaysPreTouch
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:+DisableExplicitGC
46
47. Best practices
Notes on G1GC
-XX:+UseG1GC
http://www.oracle.com/technetwork/articles/java/
g1gc-1984535.html
(G1GC shall become the default collector in Java 9)
47
48. Best practices
“Good” JVM options to start with (G1GC)
-server
-Xms1g
-Xmx1g
-XX:+AlwaysPreTouch
-XX:+UseG1GC
-XX:+DisableExplicitGC
48
49. Best practices
Keep the heap size below 30 GB if possible.
Why? Compressed oops.
https://wiki.openjdk.java.net/display/HotSpot/
CompressedOops
http://docs.oracle.com/javase/7/docs/technotes/guides/vm/
performance-enhancements-7.html
(enabled by default since Java 7 for 64-bit)
49
50. Best practices
Look out for specific tuning guides /
recommendations.
https://www.elastic.co/guide/en/elasticsearch/guide/
current/heap-sizing.html
50