GARBAGE BAGE CO COLLECTIO LLECTION: N: @EvaAndreasson, @Cloudera - - PowerPoint PPT Presentation

garbage bage co collectio llection n
SMART_READER_LITE
LIVE PREVIEW

GARBAGE BAGE CO COLLECTIO LLECTION: N: @EvaAndreasson, @Cloudera - - PowerPoint PPT Presentation

GARBAGE BAGE CO COLLECTIO LLECTION: N: @EvaAndreasson, @Cloudera AGENDA Garbage Collection (101) The Good The Bad The Ugly The Challenge! 2 GARBAGE COLLECTION "When you have to shoot, shoot - don't talk!" 3


slide-1
SLIDE 1

GARBAGE BAGE CO COLLECTIO LLECTION: N:

@EvaAndreasson, @Cloudera

slide-2
SLIDE 2

AGENDA

2

  • Garbage Collection (101)
  • The Good
  • The Bad
  • The Ugly
  • The Challenge!
slide-3
SLIDE 3

GARBAGE COLLECTION

3

"When you have to shoot, shoot - don't talk!"

slide-4
SLIDE 4

WHAT IS GARBAGE COLLECTION (GC)?

4

  • What is a Java Virtual Machine (JVM)?
  • Runtime code compilation
  • Dynamic memory management
  • What is dynamic memory management?
  • Does not require explicit memory allocation (when programming)
  • Frees up memory no longer referenced
slide-5
SLIDE 5

JAVA HEAP - SPOTLIGHT

5

  • The mythical (?) Java heap
  • Xmx, -Xms
  • Top: RES / RSS --- total memory footprint
  • Full = a thread fails to allocate a new object

Java Heap: Where all Java Objects get allocated JVM Internal Memory:

  • Code cache
  • VM Threads
  • VM & GC Structs
slide-6
SLIDE 6

REFERENCE COUNTING VS. TRACING

6

  • Reference Counting
  • Plus a counter for each reference to an object
  • Subtract for each removed reference to an object
  • When 0, reclaim the heap space occupied by that object
  • Simple to reclaim
  • Hard to maintain counters
  • Difficult (costly) to handle cyclic structures
slide-7
SLIDE 7

REFERENCE COUNTING VS. TRACING

7

  • Tracing
  • Identify roots (thread stacks, …, etc)
  • Trace all references from those objects, recursively
  • Anything not found is garbage
  • Simple to maintain, handles cyclic structures
  • Needs to trace all live objects before reclaiming memory
slide-8
SLIDE 8

SIDE NOTE: WHAT IS FRAGMENTATION?

8

New Object FULL HEAP POST GC FRAGMENTS New Object

slide-9
SLIDE 9

COPYING VS. MARK’N’SWEEP

9

  • Copying
  • Split the Java Heap into sections
  • Allocate only in the one section, until full
  • Stop the world
  • Trace all reachable objects in the section and move (copy) them to another section
  • Reclaim the original section as “free”
  • Prevents fragmentation
  • Wasteful in space
  • Stops the world
slide-10
SLIDE 10

COPYING VS. MARK’N’SWEEP

10

  • Mark’n’sweep
  • Allocate objects in the entire heap space, until full
  • Trace and mark live objects (no moving)
  • When all live objects are marked, sweep all non-marked areas (build free lists)
  • Allocation can now happen at the address spaces of the free lists
  • Allows entire heap for allocation
  • Suffers from fragmentation
  • Over time free list chunks too small to fit new objects
slide-11
SLIDE 11

PARALLEL VS. CONCURRENT

11

  • Parallel
  • Stop the world
  • Allow all available threads to do GC work
  • Allow allocation once the entire GC cycle is complete
  • Concurrent
  • Allow some of the available threads to do as much GC work in the background as

possible, without impacting running applications too much

  • Iterative marking, track areas where running applications have made

modifications and re-mark

  • Needs to start in time…
slide-12
SLIDE 12

GENERATIONAL

12

  • Generational (-Xns)
  • Most objects die young
  • Define a space (could be distributed) on the heap for allocation
  • The rest of the heap is considered “old space” or “old generation”
  • As objects “survive” garbage collection in the young space (a.k.a. nursery), promote

them to the old space

  • Reduces the speed of fragmentation of the heap
  • Can use different algorithm than old space: copying, parallel and copying…
slide-13
SLIDE 13

COMPACTING

13

  • Compaction
  • The operation of moving objects on the heap together
  • Opens up larger consecutive spaces of free memory
  • Mitigates fragmentation
  • Compaction area size
  • Incremental
  • Intelligent
  • Parallel mark’n’sweep and copying implementations usually do this during their normal

stop the world phase

  • Concurrent mark’n’sweep needs to handle this somehow, eventually…
slide-14
SLIDE 14

14

slide-15
SLIDE 15

GARBAGE IS GOOD!

15

  • Wait…what now?!?
slide-16
SLIDE 16

THE GOOD

16

  • Garbage means you are using Java the way it was intended – truly object oriented!!
  • Without GC, the world would have looked differently
  • Java helped software (and hardware) innovation
  • Programming became “mainstream” (no offence…)
  • Coding could be done faster
  • More jobs were created
  • More products and businesses popped up
  • If tuned “right”…
slide-17
SLIDE 17

17

slide-18
SLIDE 18

THE DESERT OF TUNING

18

  • Endless tuning and re-tuning
  • Rant-warning!
  • Ok for some application profiles
  • Time window applications
  • Client applications
  • Specially architected applications (new-objects only)
  • Applications not sensitive to latency
slide-19
SLIDE 19

A DESERT SURVIVAL KIT

19

  • Chose the right GC algorithm for your application
  • Understand your application allocation rate (in production) and allocate enough heap
  • Measure the right thing!!
  • Test != Production
  • Not average or std dev – latency is not a standard distribution!
  • Check out: Gil Tene’s jHiccup tool (and his talk) – a great new approach!
slide-20
SLIDE 20

20

slide-21
SLIDE 21

RECOGNIZE THIS?

21

  • Initially everything is fine, GCs are happening without much impact
  • Over time application seems to freeze up on occasion, or starts responding slower and

slower

  • Soon, the entire application hangs, affecting other servers to start firing up
  • Eventually the JVM gives up and “crashes”
  • GC logs show back-to-back GCs and in the end some sort of Out Of Memory, Allocation,
  • r Promotion Error
slide-22
SLIDE 22

WHAT REALLY HAPPENS

22

  • When allocation fails, GC is triggered
  • GC is doing its job, but no memory opens up (everything is live)
  • Back-to-back GCs, still no new memory => OOME..
  • OOME indicates not enough heap for your allocation rate
slide-23
SLIDE 23

WHY NOT CONFIGURE A LARGER HEAP?

23

slide-24
SLIDE 24

“GC PAUSES”

24

slide-25
SLIDE 25

REMEMBER FRAGMENTATION?

25

New Object FULL HEAP POST x GCs FRAGMENTS New Object …IF multiple GCs later…

slide-26
SLIDE 26

REMEMBER COMPACTION?

26

  • Most GC implementations do not handle compaction well
  • Moving objects is costly – stop the world is easy
  • Generational added
  • Tuning options and heuristics added
  • Only one JVM that I know of that does compaction concurrently today (Zing)
slide-27
SLIDE 27

PREPARE FOR THE REAL VILLAIN…

27

"There are two kinds of people in the world my friend, those with a rope around their neck and the people that have the job of doing the cutting!"

slide-28
SLIDE 28

STOP THE WORLD OPERATIONS!!!

28

slide-29
SLIDE 29

STOP THE WORLD OPERATIONS

29

  • Prevents efficient memory utilization
  • Creates complex JVM deployments
  • Sends you out in the tuning desert…
slide-30
SLIDE 30

SUMMARY

30

  • Garbage is GOOD
  • The need to tune is BAD
  • Stop the world operations are UGLY
slide-31
SLIDE 31

I CHALLENGE THEE

31

“You see in this world, there’s two kinds of people my friend… …those with loaded guns and those who dig…you dig!”

slide-32
SLIDE 32

JOIN THE FUTURE OF JAVA!

32

  • Open JDK is a great opportunity for innovation - join the community!
  • Have all GC algorithms been invented yet?
  • How do we enable a better world of self-tuning, adaptive JVMs?
  • Relieve the admin of the pain of the tuning!
  • How about fixing the core problem?
  • Implement concurrent compaction
  • Be creative around allocation / dynamic allocation rates!
slide-33
SLIDE 33

33

slide-34
SLIDE 34

Q&A

34

@EvaAndreasson