This is the 27th day of my participation in Gwen Challenge

GC classification and performance indicators

classification

  • By thread: serial garbage collector and parallel garbage collector.
    • Serial: Only one CPU is allowed to perform garbage collection at a time, and the worker thread is suspended.
    • Parallel: Allows multiple cpus to perform garbage collection, increasing program throughput.
  • According to the working mode: can be divided into parallel garbage collector and exclusive garbage collector.
    • Parallelism: The garbage collector works alternately with program threads to minimize program pause time.
    • Exclusive: Once run, stop all user threads in the program until garbage collection is complete.
  • According to the fragmentation treatment: can be divided into compressed garbage collector and non-compressed garbage collector.
    • Compressed garbage collection: After the collection is complete, the surviving objects are compressed and collated to remove the recovered debris. Use pointer collisions to redistribute object space usage.
    • Uncompressed garbage collection: There are no steps for a compressed garbage collector. Use the free list to redistribute object space usage.
  • According to the working memory space: can be divided into young generation and old generation garbage collector.

Performance indicators

  • Throughput: The percentage of total time spent running user code. Total run time = program run time + garbage collection time
  • Garbage collection overhead: the complement of throughput, the ratio of the time spent garbage collection to the total elapsed time.
  • Pause time (STW) : The amount of time a program worker thread is suspended while garbage collection is being performed.
  • Collection frequency: The frequency with which collection operations occur, corresponding to the execution of the application.
  • Memory usage: The size of the memory occupied by the Java heap.
  • Fast: The time from birth to collection of an object.

The main metrics are throughput, pause time, and memory footprint, and often not all three, and a good garbage collector meets at most two of them. Pause times become increasingly important because as hardware memory expands, throughput increases, but with the negative effect of low latency. Therefore, throughput and pause times are the main indicators.

Throughput and pause times

High throughput is good because the end user of the application feels that only application threads are working, and intuitively, the higher the throughput, the faster the application runs.

Low pause times (low latency) are better because it is not enough from the end user’s point of view. It is always bad whether GC or some other reason causes an application to hang. For an interactive application, it is important to have low pause times.

But high throughput and low pause times compete with each other:

  • If you choose throughput first, the frequency of memory collection is necessarily reduced, but this can cause the GC to pause longer to perform the collection.
  • If low-latency priority is selected, then in order to reduce the pause time of each collection, memory collection can only be performed frequently, which leads to memory reduction and throughput degradation in the young generation.

A garbage collection algorithm can only work on one or the other, or find a compromise. The G1 garbage collector in use today features reduced pause times when maximum throughput is first.