Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Chris Newland & James Gough & Benjamin J Evans

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 technology stacks will learn how to tune Java applications for performance using a quantitative, verifiable approach. Most resources on performance tend to discuss the theory and internals of Java virtual machines, but this book focuses on the practicalities of performance tuning by examining a wide range of aspects. There are no simple recipes, tips and tricks, or algorithms to learn. Performance tuning is a process of defining and determining desired outcomes. And it requires diligence. Learn how Java principles and technology make the best use of modern hardware and operating systems Explore several performance tests and common anti-patterns that can vex your team Understand the pitfalls of measuring Java performance numbers and the drawbacks of microbenchmarking Dive into JVM garbage collection logging, monitoring, tuning, and tools Explore JIT compilation and Java language performance techniques Learn performance aspects of the Java Collections API and get an overview of Java concurrency

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Optimizing Java ## 【One-Line Pitch】 A practical, experiment-driven guide to Java performance tuning that replaces guesswork and folklore with quantitative, verifiable methods—essential reading for intermediate to advanced Java developers working on complex, performance-sensitive systems. ## 【Book Arc】 - **Opening (~0%–10%)**: Establishes performance tuning as an experimental science, defines core metrics (throughput, latency, capacity, utilization, efficiency, scalability, degradation), and explains how Java maps onto modern hardware—CPU caches, memory hierarchies, and OS-level concerns like the process scheduler and context switching. - **Early (~10%–23%)**: Covers performance testing as an integral part of the SDLC, introduces common anti-patterns (like blindly tweaking JVM flags without profiling), and warns against the dangers of microbenchmarking without statistical rigor. - **Early–Middle (~23%–39%)**: Dives deep into measurement methodology—treating benchmarks as scientific experiments, understanding statistical distributions, avoiding spurious correlations, and interpreting real-world observables like allocation rates and response-time histograms. - **Middle (~39%–48%)**: Explores garbage collection fundamentals: mark-and-sweep theory, allocation rate and object lifetime as primary GC drivers, tri-color marking invariants, and the tradeoffs inherent in collectors like CMS, G1, and IBM's Balanced collector. - **Late (~48%–end)**: Moves into JIT compilation internals—using PrintCompilation and LogCompilation flags to observe compiler decisions, understanding inlining constraints, and applying this knowledge to practical Java language performance techniques. ## 【Key Takeaways】 - **Performance tuning is an experimental science, not folklore** (Opening): Define quantitative objectives using metrics like throughput, latency, and scalability before making any changes; optimizing one metric often degrades another. (Early) - **Understand your hardware before tuning software** (Early): CPU caches (L1/L2/L3), memory access patterns, and OS scheduling directly impact Java performance—fighting against hardware realities wastes effort. (Early) - **Microbenchmarking is notoriously difficult to get right** (Early): Treat benchmarks as scientific experiments with controlled inputs and outputs; beware of spurious correlations and the "Hat/Elephant" problem where complex-looking data hides simple underlying patterns. (Early) - **JVM flags are a trap for the unwary** (Early): The JVM has hundreds of switches, but defaults and self-management are usually sufficient—blind changes combine in unexpected ways and rarely improve performance without profiling. (Early) - **Allocation rate and object lifetime drive GC behavior** (Middle): Allocation rate is measurable (MB/s), but object lifetime is harder to estimate yet more fundamental—short-lived objects are the key assumption enabling efficient memory reclamation. (Middle) - **GC tuning always involves tradeoffs** (Middle): Collectors like CMS exist to showcase the compromises required—lower pause times often mean more overhead or floating garbage; there is no free lunch. (Middle) - **JIT logging reveals compiler decisions** (Late): PrintCompilation and LogCompilation (with JITWatch for parsing) expose what the JIT compiler is doing—inlining, on-stack replacement, and optimization choices—making JVM behavior observable rather than mysterious. (Late) ## 【Reading Tips】 - **Skim the hardware/OS chapters** (~0%–13%) if you're already comfortable with CPU caches and scheduling; they're foundational but review-level for experienced developers. - **Deep-read the measurement and statistics sections** (~23%–39%)—this is where the book's core philosophy lives, and it will save you from wasting hours on meaningless benchmarks. - **Pay special attention to the GC chapters** (~39%–48%): The tradeoffs between collectors (parallel, CMS, G1, Balanced) are nuanced, and understanding them requires careful reading rather than skimming. - **Use the JIT chapters** (~48%–end) as a reference when you encounter mysterious performance issues—the logging flags and interpretation techniques are practical tools to apply immediately. - **Don't expect recipes**: The book explicitly avoids simple tips and tricks; instead, internalize the methodology of defining outcomes, measuring, and iterating. ## 【Coverage Limits】 This guide synthesizes the book's core methodology, hardware foundations, measurement practices, GC fundamentals, and JIT logging techniques. Excerpts do not cover the book's later sections on Java Collections API performance, concurrency patterns (executors, fork/join, parallel streams), or detailed case studies—readers should consult the full text for those topics. ##
Excerpt 1
Modern Java Concurrency i. Streams and Parallel Streams It’s an exciting time to be a Java developer, and there have never been so many opportunities to buil...
View in text
Excerpt 2
analyst to see the real-time effect of context switching. A process that is failing to achieve 100% userland CPU usage and is also displaying a high context...
View in text
Excerpt 3
of Java as a blue-collar language for getting things done. In this chapter, we will meet some of the basic theory that underpins Java garbage collection, and...
View in text
Excerpt 4
ten, due to the greater volume of objects being promoted to Tenured, causing it to fill up more quickly. As always, you should not alter the switch without a...
View in text
Excerpt 5
ovide some behavior. The JavaDoc describes this as follows: Called by the garbage collector on an object when garbage collection determines that there are no...
View in text
Excerpt 6
o the target JVM brings up a configuration dialog, as shown in Figure 13-5. Note that the profiler is already warning of performance Figure 13-16. Honest Pro...
View in text
Excerpt 7
Compilation -XX:+PrintFlagsFinal switch, Confirmation Bias Bytecode-Introduction to JVM Bytecode simple interpreters, Simple Interpreters code cache, The Cod...
View in text
Excerpt 8
arn more about how you can help, go to animals.oreilly.com. The cover image is from Riverside Natural History. The cover fonts are URW Typewriter and Guardia...
View in text
Tags
AI categories
Programming LanguageJavaBackend
Publish Year: 2018
Language: English
File Format: PDF
File Size: 8.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…