Optimizing Cloud Native Java, 2nd Edition

Book description

Performance tuning is an experimental science, but that doesn't mean engineers should resort to guesswork and folklore to get the job done. Yet that's often the case. With this practical book, intermediate to advanced Java technologists working with complex platforms will learn how to tune Java cloud applications for performance using a quantitative, verifiable, and repeatable approach.

In response to the ubiquity of cloud computing, this updated edition of Optimizing Cloud Native Java addresses topics that are key to high performance of Java applications in the cloud. Many resources on performance tend to focus on the theory and internals of Java virtual machines, but this book discusses the low-level technical aspects within the context of performance-tuning practicalities and examines a wide range of aspects.

With this book, you will:

  • Learn how Java principles and technology make the best use of modern hardware, operating systems, and cloud stacks
  • Examine the pitfalls of measuring Java performance numbers and the drawbacks of microbenchmarking
  • Understand how to package, deploy, operate, and debug Java/JVM applications in modern cloud environments
  • Apply emerging observability approaches to obtain deep understanding of cloud native applications
  • Use Java language performance techniques including concurrent and distributed forms

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Why Did We Write This Book?
    2. Why Should You Read This Book?
    3. Who This Book Is For
    4. What You Will Learn
    5. What This Book Is Not
    6. Conventions Used in This Book
    7. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  3. 1. Optimization and Performance Defined
    1. Java Performance the Wrong Way
    2. Java Performance Overview
    3. Performance as an Experimental Science
    4. A Taxonomy for Performance
      1. Throughput
      2. Latency
      3. Capacity
      4. Utilization
      5. Efficiency
      6. Scalability
      7. Degradation
      8. Correlations Between the Observables
    5. Reading Performance Graphs
    6. Performance in Cloud Systems
    7. Summary
  4. 2. Performance Testing Methodology
    1. Types of Performance Tests
      1. Latency Test
      2. Throughput Test
      3. Stress Test
      4. Load Test
      5. Endurance Test
      6. Capacity Planning Test
      7. Degradation Test
    2. Best Practices Primer
      1. Top-Down Performance
      2. Creating a Test Environment
      3. Identifying Performance Requirements
      4. Performance Testing as Part of the SDLC
      5. Java-Specific Issues
    3. Causes of Performance Antipatterns
      1. Boredom
      2. Résumé Padding
      3. Social Pressure
      4. Lack of Understanding
      5. Misunderstood/Nonexistent Problem
    4. Statistics for JVM Performance
      1. Types of Error
      2. Non-Normal Statistics
    5. Interpretation of Statistics
      1. Spurious Correlation
      2. The Hat/Elephant Problem
    6. Cognitive Biases and Performance Testing
      1. Reductionist Thinking
      2. Confirmation Bias
      3. Fog of War (Action Bias)
      4. Risk Bias
    7. Summary
  5. 3. Overview of the JVM
    1. Interpreting and Classloading
    2. Executing Bytecode
    3. Introducing HotSpot
    4. Introducing Just-in-Time Compilation
    5. JVM Memory Management
    6. Threading and the Java Memory Model
    7. Monitoring and Tooling for the JVM
    8. Java Implementations, Distributions, and Releases
      1. Choosing a Distribution
      2. The Java Release Cycle
    9. Summary
  6. 4. Understanding Garbage Collection
    1. Introducing Mark and Sweep
    2. Garbage Collection Glossary
    3. Introducing the HotSpot Runtime
      1. Representing Objects at Runtime
      2. GC Roots
    4. Allocation and Lifetime
    5. Weak Generational Hypothesis
    6. Production GC Techniques in HotSpot
      1. Thread-Local Allocation
      2. Hemispheric Collection
      3. The “Classic” HotSpot Heap
    7. The Parallel Collectors
      1. Young Parallel Collections
      2. Old Parallel Collections
      3. Serial and SerialOld
      4. Limitations of Parallel Collectors
    8. The Role of Allocation
    9. Summary
  7. 5. Advanced Garbage Collection
    1. Tradeoffs and Pluggable Collectors
    2. Concurrent GC Theory
      1. JVM Safepoints
      2. Tri-Color Marking
      3. Forwarding Pointers
    3. G1
      1. G1 Heap Layout and Regions
      2. G1 Collections
      3. G1 Mixed Collections
      4. Remembered Sets
      5. Full Collections
      6. JVM Config Flags for G1
    4. Shenandoah
      1. Concurrent Evacuation
      2. JVM Config Flags for Shenandoah
      3. Shenandoah’s Evolution
    5. ZGC
    6. Balanced (Eclipse OpenJ9)
      1. OpenJ9 Object Headers
      2. Large Arrays in Balanced
      3. NUMA and Balanced
    7. Niche HotSpot Collectors
      1. CMS
      2. Epsilon
    8. Summary
  8. 6. Code Execution on the JVM
    1. Lifecycle of a Traditional Java Application
    2. Overview of Bytecode Interpretation
      1. Introduction to JVM Bytecode
      2. Simple Interpreters
      3. HotSpot-Specific Details
    3. JIT Compilation in HotSpot
      1. Profile-Guided Optimization
      2. Klass Words, Vtables, and Pointer Swizzling
      3. Compilers Within HotSpot
      4. The Code Cache
      5. Logging JIT Compilation
      6. Simple JIT Tuning
    4. Evolving Java Program Execution
      1. Ahead-of-Time (AOT) Compilation
      2. Quarkus
      3. GraalVM
    5. Summary
  9. 7. Hardware and Operating Systems
    1. Introduction to Modern Hardware
    2. Memory
    3. Memory Caches
    4. Modern Processor Features
      1. Translation Lookaside Buffer
      2. Branch Prediction and Speculative Execution
      3. Hardware Memory Models
    5. Operating Systems
      1. The Scheduler
      2. The JVM and the Operating System
      3. Context Switches
    6. A Simple System Model
      1. Utilizing the CPU
      2. Garbage Collection
      3. I/O
      4. Mechanical Sympathy
    7. Summary
  10. 8. Components of the Cloud Stack
    1. Java Standards for the Cloud Stack
    2. Cloud Native Computing Foundation
      1. Kubernetes
      2. Prometheus
      3. OpenTelemetry
    3. Virtualization
      1. Choosing the Right Virtual Machines
      2. Virtualization Considerations
    4. Images and Containers
      1. Image Structure
      2. Building Images
      3. Running Containers
    5. Networking
    6. Introducing the Fighting Animals Example
    7. Summary
  11. 9. Deploying Java in the Cloud
    1. Working Locally with Containers
      1. Docker Compose
      2. Tilt
    2. Container Orchestration
      1. Deployments
      2. Sharing Within Pods
      3. Container and Pod Lifecycles
      4. Services
      5. Connecting to Services on the Cluster
      6. Challenges with Containers and Scheduling
      7. Working with Remote Containers Using “Remocal” Development
    3. Deployment Techniques
      1. Blue/Green Deployments
      2. Canary Deployments
      3. Evolutionary Architecture and Feature Flagging
    4. Java-Specific Concerns
      1. Containers and GC
      2. Memory and OOMEs
    5. Summary
  12. 10. Introduction to Observability
    1. The What and the Why of Observability
      1. What Is Observability?
      2. Why Observability?
    2. The Three Pillars
      1. Metrics
      2. Logs
      3. Traces
      4. The Pillars as Data Sources
      5. Profiling—A Fourth Pillar?
    3. Observability Architecture Patterns and Antipatterns
      1. Architectural Patterns for Metrics
      2. Manual Versus Automatic Instrumentation
      3. Antipattern: Shoehorn Data into Metrics
      4. Antipattern: Abusing Correlated Logs
    4. Diagnosing Application Problems Using Observability
      1. Performance Regressions
      2. Unstable Components
      3. Repartitioning and “Split-Brain”
      4. Thundering Herd
      5. Cascading Failure
      6. Compound Failures
    5. Vendor or OSS Solution?
    6. Summary
  13. 11. Implementing Observability in Java
    1. Introducing Micrometer
      1. Meters and Registries
      2. Counters
      3. Gauges
      4. Meter Filters
      5. Timers
      6. Distribution Summaries
      7. Runtime Metrics
    2. Introducing Prometheus for Java Developers
      1. Prometheus Architecture Overview
      2. Using Prometheus with Micrometer
    3. Introducing OpenTelemetry
      1. What Is OpenTelemetry?
      2. Why Choose OTel?
      3. OTLP
      4. The Collector
    4. OpenTelemetry Tracing in Java
      1. Manual Tracing
      2. Automatic Tracing
      3. Sampling Traces
    5. OpenTelemetry Metrics in Java
    6. OpenTelemetry Logs in Java
    7. Summary
  14. 12. Profiling
    1. Introduction to Profiling
    2. GUI Profiling Tools
      1. VisualVM
      2. JDK Mission Control
    3. Sampling and Safepointing Bias
    4. Modern Profilers
      1. perf
      2. Async Profiler
    5. JDK Flight Recorder (JFR)
    6. Operational Aspects of Profiling
      1. Using JFR As an Operational Tool
      2. Red Hat Cryostat
      3. JFR and OTel Profiling
      4. Choosing a Profiler
    7. Memory Profiling
      1. Allocation Profiling
      2. Heap Dumps
    8. Summary
  15. 13. Concurrent Performance Techniques
    1. Introduction to Parallelism
      1. Amdahl’s Law
      2. Fundamental Java Concurrency
    2. Understanding the JMM
    3. Building Concurrency Libraries
      1. Method and Var Handles
      2. Atomics and CAS
      3. Locks and Spinlocks
    4. Summary of Concurrent Libraries
      1. Locks in java.util.concurrent
      2. Read/Write Locks
      3. Semaphores
      4. Concurrent Collections
      5. Latches and Barriers
    5. Executors and Task Abstraction
      1. Introducing Asynchronous Execution
      2. Selecting an ExecutorService
      3. Fork/Join and Parallel Streams
      4. Actor-Based Techniques
    6. Virtual Threads
      1. Introduction to Virtual Threads
      2. Virtual Thread Concurrency Patterns
    7. Summary
  16. 14. Distributed Systems Techniques and Patterns
    1. Basic Distributed Data Structures
      1. Clocks, IDs, and Write-Ahead Logs
      2. Two-Phase Commit
      3. Object Serialization
      4. Data Partitioning and Replication
      5. CAP Theorem
    2. Consensus Protocols
      1. Paxos
      2. Raft
    3. Distributed Systems Examples
      1. Distributed Database—Cassandra
      2. In-Memory Data Grid—Infinispan
      3. Event Streaming—Kafka
    4. Enhancing Fighting Animals
      1. Introducing Kafka to Fighting Animals
      2. A Simple Hospital Service
      3. An Active Hospital
    5. Summary
  17. 15. Modern Performance and The Future
    1. New Concurrency Patterns
      1. Structured Concurrency
      2. Scoped Values
    2. Panama
    3. Leyden
      1. Images, Constraints, and Condensers
      2. Leyden Premain
    4. Valhalla
    5. Conclusions
  18. A. Microbenchmarking
    1. Introduction to Measuring Low-Level Java Performance
    2. Introduction to JMH
      1. Don’t Microbenchmark If You Can Help It (A True Story)
      2. Heuristics for When to Microbenchmark
      3. The JMH Framework
      4. Executing Benchmarks
  19. B. Performance Antipatterns Catalog
    1. Distracted by Shiny
      1. Example Comments
      2. Reality
      3. Discussion
      4. Resolutions
    2. Distracted by Simple
      1. Example Comments
      2. Reality
      3. Discussion
      4. Resolutions
    3. Performance Tuning Wizard
      1. Example Comment
      2. Reality
      3. Discussion
      4. Resolutions
    4. Tuning by Folklore
      1. Example Comment
      2. Reality
      3. Discussion
      4. Resolutions
    5. The Blame Donkey
      1. Example Comment
      2. Reality
      3. Discussion
      4. Resolutions
    6. Missing the Bigger Picture
      1. Example Comments
      2. Reality
      3. Discussion
      4. Resolutions
    7. UAT Is My Desktop
      1. Example Comment
      2. Reality
      3. Discussion
      4. Resolutions
    8. Production-Like Data Is Hard
      1. Example Comments
      2. Reality
      3. Discussion
      4. Resolutions
  20. Index
  21. About the Authors

Product information

  • Title: Optimizing Cloud Native Java, 2nd Edition
  • Author(s): Benjamin J. Evans, James Gough
  • Release date: October 2024
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098149345