You are previewing Java Performance: The Definitive Guide.
O'Reilly logo
Java Performance: The Definitive Guide

Book Description

Coding and testing are often considered separate areas of expertise. In this comprehensive guide, author and Java expert Scott Oaks takes the approach that anyone who works with Java should be equally adept at understanding how code behaves in the JVM, as well as the tunings likely to help its performance.

Table of Contents

  1. Preface
    1. Who Should (and Shouldn’t) Read This book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  2. 1. Introduction
    1. A Brief Outline
    2. Platforms and Conventions
      1. JVM Tuning Flags
    3. The Complete Performance Story
    4. Summary
  3. 2. An Approach to Performance Testing
    1. Test a real application
      1. Microbenchmarks
        1. Microbenchmarks must use their results
        2. Microbenchmarks must not include extraneous operations
        3. Microbenchmarks must measure the correct input
      2. Macrobenchmarks
      3. Mesobenchmarks
      4. Common Code Examples
    2. Understand Throughput, Batching, and Response Time
      1. Elapsed Time (Batch) Measurements
      2. Throughput Measurements
      3. Response Time Tests
    3. Understand Variability
    4. Test Early, Test Often
    5. Summary
  4. 3. A Java Performance Toolbox
    1. Operating System Tools and Analysis
      1. CPU Usage
        1. Java and Single-CPU usage
        2. Java and Multi-CPU usage
      2. The CPU Run Queue
      3. Disk Usage
      4. Network Usage
    2. Java Monitoring Tools
      1. Basic VM information
        1. Working with tuning flags
      2. Thread Information
      3. Class Information
      4. Live GC Analysis
      5. Heap Dump Post Processing
    3. Profiling Tools
      1. Sampling Profilers
      2. Instrumented Profilers
      3. Blocking Methods and Thread Timelines
      4. Native Profilers
    4. Java Mission Control
      1. Java Flight Recorder
        1. JFR Overview
        2. JFR Memory View
        3. JFR Code View
        4. Overview of JFR Events
      2. Enabling JFR
        1. Enabling JFR via Mission Control
        2. Enabling JFR via the command line
      3. Selecting JFR events
    5. Summary
  5. 4. Working with the JIT Compiler
    1. Just-In-Time Compilers: An Overview
      1. Hotspot Compilation
    2. Basic Tunings: Client or Server (or both)
      1. Optimizing Start-up
      2. Optimizing Batch Operations
      3. Optimizing Long-Running Applications
    3. Java and JIT compiler versions
    4. Intermediate Tunings for the Compiler
      1. Tuning the Code Cache
      2. Compilation Thresholds
      3. Inspecting the Compilation Process
    5. Advanced Compiler Tunings
      1. Compilation Threads
      2. Inlining
      3. Escape Analysis
    6. Deoptimization
      1. Not Entrant Code
      2. Deoptimizing Zombie Code
    7. Tiered Compilation Levels
    8. Summary
  6. 5. Introduction to Garbage Collection
    1. Garbage Collection Overview
      1. Generational Garbage Collectors
      2. GC Algorithms
        1. The Serial Garbage Collector
        2. The Throughput Collector
        3. The CMS Collector
        4. The G1 Collector
      3. Choosing a GC Algorithm
        1. GC Algorithms and Batch Jobs
        2. GC Algorithms and Throughput Tests
        3. GC Algorithms and Response Time Tests
        4. Choosing between CMS and G1
    2. Basic GC Tuning
      1. Sizing the Heap
      2. Sizing the Generations
      3. Sizing PermGen and Metaspace
      4. Controlling Parallelism
      5. Adaptive Sizing
    3. GC Tools
    4. Summary
  7. 6. Garbage Collection Algorithms
    1. Understanding the Throughput Collector
      1. Adaptive and Static Heap Size Tuning
    2. Understanding the CMS Collector
      1. Tuning to solve Concurrent Mode Failures
        1. Running the background thread more often
        2. Adjusting the CMS background threads
      2. Tuning CMS for Permgen
      3. Incremental CMS
    3. Understanding the G1 Collector
      1. Tuning G1
        1. Tuning the G1 Background Threads
        2. Tuning G1 to run more (or less) frequently
        3. Tuning G1 Mixed GC cycles
    4. Advanced Tunings
      1. Tenuring and Survivor Spaces
      2. Allocating Large Objects
        1. Thread Local Allocation Buffers
        2. Sizing TLABs
        3. Humongous Objects
        4. G1 Region Sizes
        5. Humongous Objects
      3. AggressiveHeap
      4. Full Control over Heap Size
    5. Summary
  8. 7. Heap Memory Best Practices
    1. Heap Analysis
      1. Heap Histograms
      2. Heap Dumps
      3. Out of Memory Errors
        1. Out of Native Memory
        2. Out of Permgen or Metaspace Memory
        3. Out of Heap Memory
        4. GC Overhead Limit Reached
    2. Using less memory
      1. Reducing Object Size
      2. Lazy Initialization
        1. Eager De-initialization
      3. Immutable and Canonical Objects
        1. Creating Canonical Objects
      4. String Interning
    3. Object Lifecycle Management
      1. Object Reuse
        1. Object Pools
        2. Thread Local Variables
      2. Weak, Soft, and Other References
        1. Soft References
        2. Weak References
        3. Finalizers and Final References
    4. Summary
  9. 8. Native Memory Best Practices
    1. Footprint
      1. Measuring Footprint
      2. Minimizing Footprint
      3. Native NIO Buffers
      4. Native Memory Tracking
        1. NMT over time
    2. JVM tunings for the Operating System
      1. Large Pages
        1. Linux Huge (Large) Pages
        2. Linux Transparent Huge Pages
        3. Windows Large Pages
        4. Large Page Sizes
      2. Compressed oops
    3. Summary
  10. 9. Threading and Synchronization Performance
    1. Thread Pools and ThreadPoolExecutors
      1. Setting the Maximum Number of Threads
      2. Setting the Minimum Number of Threads
      3. Thread Pool Task Sizes
      4. Sizing a <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">ThreadPoolExecutor</code>
    2. The <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg" class="literal">ForkJoinPool</code>
      1. Automatic Parallelization
    3. Thread Synchronization
      1. Costs of synchronization
        1. Synchronization and Scalability
        2. Costs of Locking Objects
      2. Avoiding synchronization
      3. False Sharing
    4. JVM Thread Tunings
      1. Tuning Thread Stack Sizes
      2. Biased Locking
      3. Lock Spinning
      4. Thread Priorities
    5. Monitoring Threads and Locks
      1. Thread Visibility
      2. Blocked Thread Visibility
        1. Blocked Threads and JFR
        2. Blocked Threads and JStack
    6. Summary
  11. 10. Java Enterprise Edition Performance
    1. Basic Web Container Performance
      1. HTTP Session State
        1. HTTP Session State Memory
        2. Highly-Available HTTP Session State
    2. Thread Pools
    3. Enterprise Java Session Beans
      1. Tuning EJB pools
      2. Tuning EJB Caches
      3. Local and Remote Instances
    4. XML and JSON Processing
      1. Data Size
      2. An Overview of Parsing and Marshalling
      3. Choosing a parser
        1. Pull Parsers
        2. Push Parsers (SAX)
        3. Alternate Parsing Implementations and Parser Factories
      4. XML Validation
      5. Document Models
      6. Java Object Models
    5. Object Serialization
      1. Transient Fields
      2. Overriding Default Serialization
      3. Compressing Serialized Data
      4. Keeping Track of Duplicate Objects
    6. Java EE Networking APIs
      1. Sizing Data Transfers
    7. Summary
  12. 11. Database Performance Best Practices
    1. JDBC
      1. JDBC Drivers
      2. Prepared Statements and Statement Pooling
        1. Setting up the statement pool
        2. Managing Statement Pools
      3. JDBC Connection Pools
      4. Transactions
        1. JDBC Transaction Control
        2. Transaction Isolation and Locking
      5. Result Set Processing
    2. JPA
      1. Transaction Handling
      2. Optimizing JPA Writes
      3. Optimizing JPA Reads
        1. Reading less data
        2. Using JOIN in queries
        3. Batching and queries
      4. JPA Caching
        1. Default Caching (Lazy Loading)
        2. Caching and Eager Loading
        3. Join Fetch and Caching
        4. Avoiding Queries
        5. Sizing the JPA cache
      5. JPA Read-Only Entities
    3. Summary
  13. 12. Java SE API Tips
    1. Buffered I/O
    2. Class Loading
    3. Random numbers
    4. JNI
    5. Exceptions
    6. String Performance
    7. Logging
    8. Java Collections API
      1. Synchronized vs. Unsynchronized
      2. Collection Sizing
      3. Collections and Memory Efficiency
    9. AggressiveOpts
      1. Alternate Implementations
      2. Miscellaneous Flags
    10. Lambdas and Anonymous Classes
      1. Lambda and Anonymous Classloading
    11. Stream and Filter Performance
      1. Lazy Traversal
    12. Summary
  14. A. Summary of Tuning Flags
  15. Index
  16. About the Author
  17. Colophon
  18. Copyright