Java™ Performance Tuning, 2Nd Edition by Jack Shirazi
Total Page:16
File Type:pdf, Size:1020Kb
[ Team LiB ] • Table of Contents • Index • Reviews • Examples • Reader Reviews • Errata Java™ Performance Tuning, 2nd Edition By Jack Shirazi Publisher : O'Reilly Pub Date : January 2003 ISBN : 0-596-00377-3 Pages : 588 Java Peformance Tuning, 2nd edition provides a comprehensive and indispensable guide to eliminating all types of performance problems. Using many real-life examples to work through the tuning process in detail, JPT shows how tricks such as minimizing object creation and replacing strings with arrays can really pay off in improving your code's performance. Tuning J2EE applications bears many similarities to tuning J2SE apps, but important and specific considerations apply. For this reason, Java Performance Tuning, Second Edition includes four new chapters: a new chapter on J2EE application tuning in general followed by chapters on tuning JDBC, servlets and JSPs, and EJBs. [ Team LiB ] • Table of Contents • Index • Reviews • Examples • Reader Reviews • Errata Java™ Performance Tuning, 2nd Edition By Jack Shirazi Publisher : O'Reilly Pub Date : January 2003 ISBN : 0-596-00377-3 Pages : 588 Copyright Preface Contents of This Book New in the Second Edition Virtual Machine (VM) Versions Conventions Used in This Book Comments and Questions Acknowledgments Chapter 1. Introduction Section 1.1. Why Is It Slow? Section 1.2. The Tuning Game Section 1.3. System Limitations and What to Tune Section 1.4. A Tuning Strategy Section 1.5. Perceived Performance Section 1.6. Starting to Tune Section 1.7. What to Measure Section 1.8. Don't Tune What You Don't Need to Tune Section 1.9. Performance Checklist Chapter 2. Profiling Tools Section 2.1. Measurements and Timings Section 2.2. Garbage Collection Section 2.3. Method Calls Section 2.4. Object-Creation Profiling Section 2.5. Monitoring Gross Memory Usage Section 2.6. Client/Server Communications Section 2.7. Performance Checklist Chapter 3. Underlying JDK Improvements Section 3.1. Garbage Collection Section 3.2. Tuning the Heap Section 3.3. Gross Tuning Section 3.4. Fine-Tuning the Heap Section 3.5. Sharing Memory Section 3.6. Replacing JDK Classes Section 3.7. Faster VMs Section 3.8. Better Optimizing Compilers Section 3.9. Sun's Compiler and Runtime Optimizations Section 3.10. Compile to Native Machine Code Section 3.11. Native Method Calls Section 3.12. Uncompressed ZIP/JAR Files Section 3.13. Performance Checklist Chapter 4. Object Creation Section 4.1. Object-Creation Statistics Section 4.2. Object Reuse Section 4.3. Reference Objects Section 4.4. Avoiding Garbage Collection Section 4.5. Initialization Section 4.6. Early and Late Initialization Section 4.7. Performance Checklist Chapter 5. Strings Section 5.1. The Performance Effects of Strings Section 5.2. Compile-Time Versus Runtime Resolution of Strings Section 5.3. Conversions to Strings Section 5.4. Strings Versus char Arrays Section 5.5. String Comparisons and Searches Section 5.6. Sorting Internationalized Strings Section 5.7. Performance Checklist Chapter 6. Exceptions, Assertions, Casts, and Variables Section 6.1. Exceptions Section 6.2. Assertions Section 6.3. Casts Section 6.4. Variables Section 6.5. Method Parameters Section 6.6. Performance Checklist Chapter 7. Loops, Switches, and Recursion Section 7.1. Loops Section 7.2. Tuning a Loop Section 7.3. Exception-Terminated Loops Section 7.4. Switches Section 7.5. Recursion Section 7.6. Recursion and Stacks Section 7.7. Performance Checklist Chapter 8. I/O, Logging, and Console Output Section 8.1. Replacing System.out Section 8.2. Logging Section 8.3. From Raw I/O to Smokin' I/O Section 8.4. Serialization Section 8.5. Clustering Objects and Counting I/O Operations Section 8.6. Compression Section 8.7. NIO Section 8.8. Performance Checklist Chapter 9. Sorting Section 9.1. Avoiding Unnecessary Sorting Overhead Section 9.2. An Efficient Sorting Framework Section 9.3. Better Than O(nlogn) Sorting Section 9.4. Performance Checklist Chapter 10. Threading Section 10.1. User-Interface Thread and Other Threads Section 10.2. Race Conditions Section 10.3. Deadlocks Section 10.4. Synchronization Overhead Section 10.5. Timing Multithreaded Tests Section 10.6. Atomic Access and Assignment Section 10.7. Thread Pools Section 10.8. Load Balancing Section 10.9. Threaded Problem-Solving Strategies Section 10.10. Performance Checklist Chapter 11. Appropriate Data Structures and Algorithms Section 11.1. Collections Section 11.2. Java 2 Collections Section 11.3. Hashtables and HashMaps Section 11.4. Optimizing Queries Section 11.5. Comparing LinkedLists and ArrayLists Section 11.6. The RandomAccess Interface Section 11.7. Cached Access Section 11.8. Caching Examples Section 11.9. Finding the Index for Partially Matched Strings Section 11.10. Search Trees Section 11.11. Performance Checklist Chapter 12. Distributed Computing Section 12.1. Tools Section 12.2. Message Reduction Section 12.3. Comparing Communications Layers Section 12.4. Caching Section 12.5. Batching I Section 12.6. Application Partitioning Section 12.7. Batching II Section 12.8. Low-Level Communication Optimizations Section 12.9. Distributed Garbage Collection Section 12.10. Databases Section 12.11. Web Services Section 12.12. Performance Checklist Chapter 13. When to Optimize Section 13.1. When Not to Optimize Section 13.2. Tuning Class Libraries and Beans Section 13.3. Analysis Section 13.4. Design and Architecture Section 13.5. Tuning After Deployment Section 13.6. More Factors That Affect Performance Section 13.7. Performance Planning Section 13.8. Performance Checklist Chapter 14. Underlying Operating System and Network Improvements Section 14.1. Hard Disks Section 14.2. CPU Section 14.3. RAM Section 14.4. Network I/O Section 14.5. Performance Checklist Chapter 15. J2EE Performance Tuning Section 15.1. Performance Planning Section 15.2. J2EE Monitoring and Profiling Tools Section 15.3. Measurements: What, Where, and How Section 15.4. Load Testing Section 15.5. User Perception Section 15.6. Clustering and Load Balancing Section 15.7. Tuning JMS Section 15.8. Performance Checklist Chapter 16. Tuning JDBC Section 16.1. Measuring JDBC Performance Section 16.2. Tuning JDBC Section 16.3. Performance Checklist Chapter 17. Tuning Servlets and JSPs Section 17.1. Don't Use SingleThreadModel Section 17.2. Efficient Page Creation and Output Section 17.3. Body Tags Section 17.4. Cache Tags Section 17.5. HttpSession Section 17.6. Compression Section 17.7. More Performance Tips Section 17.8. Case Study: Ace's Hardware SPECmine Tool Section 17.9. Performance Checklist Chapter 18. Tuning EJBs Section 18.1. Primary Design Guidelines Section 18.2. Performance-Optimizing Design Patterns Section 18.3. The Application Server Section 18.4. More Suggestions for Tuning EJBs Section 18.5. Case Study: The Pet Store Section 18.6. Case Study: Elite.com Section 18.7. Performance Checklist Chapter 19. Further Resources Section 19.1. The Primary Resource Section 19.2. Books Section 19.3. Magazines Section 19.4. URLs Section 19.5. Profilers Section 19.6. Optimizers Colophon Index [ Team LiB ] Copyright Copyright © 2003, 2000 O'Reilly & Associates, Inc. Printed in the United States of America. Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly & Associates books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. The association between the image of a serval and the topic of Java performance tuning is a trademark of O'Reilly & Associates, Inc. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. [ Team LiB ] Preface Performance has been an important issue with Java™ since the first version hit the Web years ago. Making those first interpreted programs run fast enough was a huge challenge for many developers. Since then, Java performance has improved enormously, and any Java program can now be made to run fast enough provided you avoid the main performance pitfalls. This book provides all the details a developer needs to performance-tune any type of Java program. I give step-by-step instructions on all aspects of the performance-tuning process, from early considerations such as setting goals, measuring performance, and choosing a compiler, to detailed examples on using profiling tools and applying the results to tune the code. This is not an entry-level book about Java, but you do not need any previous tuning knowledge to benefit from reading it. Many of the tuning techniques presented in this book lead to an increased maintenance cost, so they should not be applied arbitrarily. Change your code only when a bottleneck has been identified, and never change the design of your application for minor performance gains. [ Team LiB ] Contents of This Book Chapter 1 gives general guidelines on how to tune. If you do not yet have a tuning strategy, this chapter provides a methodical tuning process. Chapter 2 covers the tools you need to use while tuning. Chapter 3 looks at the SDK, including Virtual Machines (VMs) and compilers.