You are previewing Java EE 7 Performance Tuning and Optimization.
O'Reilly logo
Java EE 7 Performance Tuning and Optimization

Book Description

Boost the efficiency of your enterprise applications by performance tuning and optimization

In Detail

With the expansion of online enterprise services, the performance of an enterprise application has become a critical issue. Even the smallest change to service availability can severely impact customer satisfaction, which can cause the enterprise to incur huge losses. Performance tuning is a challenging topic that focuses on resolving tough performance issues.

In this book, you will explore the art of performance tuning from all perspectives using a variety of common tools, while studying many examples.

This book covers performance tuning in Java enterprise applications and their optimization in a simple, step-by-step manner. Beginning with the essential concepts of Java, the book covers performance tuning as an art. It then gives you an overview of performance testing and different monitoring tools. It also includes examples of using plenty of tools, both free and paid.

What You Will Learn

  • Master the art of performance tuning and become a performance tuning expert
  • Create and execute enterprise performance tests
  • Understand the fundamentals of Java needed for performance tuning
  • Use a number of profiling tools to diagnose common performance issues
  • Understand the basic aspects of the Java virtual machine and application server performance tuning
  • Design guidelines for better enterprise application performance
  • Discover different Java optimization tips and tricks
  • Tune a real-world sample application
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Java EE 7 Performance Tuning and Optimization
      1. Table of Contents
      2. Java EE 7 Performance Tuning and Optimization
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      9. 1. Getting Started with Performance Tuning
        1. Understanding the art of performance tuning
        2. Understanding performance issues
          1. Classifying performance issues by the discovery phase
            1. Requirement phase and design-time issues
            2. Development-time issues
            3. Testing-time issues
            4. Production-time issues
          2. Classifying performance issues by the root phase
            1. Requirement phase issues
            2. Design/architecture phase issues
            3. Development phase issues
            4. Testing phase issues
            5. Operational and environmental-specific issues
          3. Performance-handling tactics
          4. Proactive measures (preventive)
          5. Reactive measures (curative)
            1. Understanding the different layers of an enterprise application
            2. The three pillars required for performance tuning
              1. Define the performance process
              2. Getting ready with the required performance tools
              3. Being ready to deal with performance issues at any time
          6. The cycle of learning
          7. Tuning yourself before tuning the application
            1. Be a true leader
            2. Use your power
            3. Be responsible
            4. Trust your team
            5. Keep it simple
            6. Respect roles and responsibilities
            7. Understand the application domain and context
            8. Protect your reputation
        3. Standalone applications versus web applications
          1. The standalone application
          2. Thick client application – client-server model
          3. Thin client application – web-based model
        4. Dealing with web applications' performance tuning
          1. The two dimensions of web applications' performance tuning
            1. Horizontal dimension (node-to-node)
            2. Vertical dimension (intranode)
          2. Exploring vertical dimension nodes in horizontal dimension nodes
            1. Client side
            2. Network components
            3. HTTP servers (web servers)
            4. Application servers
            5. Database servers
            6. Middleware integration servers
            7. Operating system and hardware
            8. CPU utilization
            9. Network traffic
            10. Memory usage
            11. Storage I/O performance
        5. Summary
      10. 2. Understanding Java Fundamentals
        1. Discussing the new Java EE 7 features
          1. Bean Validation 1.1 (JSR 349)
          2. Java API for JSON processing – JSON-P 1.0 (JSR 353)
          3. Java API for RESTful web services – JAX-RS 2.0 (JSR 339)
          4. Java Servlet 3.1 (JSR 340)
          5. Context and Dependency Injection – CDI 1.1 (JSR 346)
          6. Interceptors 1.2 (JSR 318)
          7. Enterprise JavaBeans – EJB 3.2 (JSR 345)
          8. Java Message Service – JMS 2.0 (JSR 343)
          9. Concurrency Utilities 1.0 (JSR 236)
          10. Batch Applications 1.0 (JSR 352)
          11. Java Persistence APIs – JPA 2.1 (JSR 338)
          12. JavaServer Faces – JSF 2.2 (JSR 344)
          13. Expression language 3.0 (JSR 341)
          14. Java Transaction APIs – JTA 1.2 (JSR 907)
          15. Java API for WebSocket 1.0 (JSR 356)
        2. Understanding memory structure in the JVM
          1. The JVM specifications
            1. Heap area
            2. Method area and runtime constant pool
            3. JVM stack
            4. Native method stacks (C stacks)
            5. PC registers
          2. Memory structure in the Java HotSpot virtual machine
            1. Generational memory structure
            2. The Java HotSpot virtual machine generations
        3. Understanding the Java garbage collection policies
          1. Different GC options
            1. Concurrent versus stop-the-world
            2. Serial versus parallel collector
            3. Compacting versus non-compacting
              1. Summary phase
              2. Compacting phase
            4. The Garbage-first collector – G1
        4. Different application scopes
        5. Understanding concurrency in Java
          1. Process versus thread
          2. Exploring an object monitor
        6. Using the Java concurrency utilities
          1. Creating a thread pool
          2. Using explicit locking with the Lock interface
          3. Concurrent resources and utilities
            1. The ManagedExecutorService class
            2. The ManagedScheduledExecutorService class
            3. The ManagedThreadFactory class
        7. The important Java EE concurrency features
          1. The SingleThreadModel interface
          2. Asynchronous servlet and filter
          3. The new Java EE non-blocking I/O APIs
          4. Session beans asynchronous method invocation
          5. A singleton session bean
          6. Sending asynchronous JMS messages
        8. More information about Java EE 7
        9. Summary
      11. 3. Getting Familiar with Performance Testing
        1. Dissecting performance testing
          1. Exploring performance testing aspects
            1. Selecting the performance test environment
            2. Project milestones and performance
            3. Defining different rules and responsibilities
            4. Performance testing types
              1. Load testing
              2. Stress testing
              3. Capacity testing
            5. Performance testing components
              1. Test data
              2. Test users
              3. Test scenarios
              4. Preparing the test environment prior to test execution
              5. Test automation
              6. Test quality assurance
            6. Performance testing tools
            7. Performance benchmarking and baseline
            8. Isolation testing
            9. Performance fixing cycle
            10. When to stop tuning?
        2. Performance testing terminologies
        3. Performance testing in a cloud environment
        4. Starting with Apache JMeter
          1. Different components of the JMeter test plan
            1. The execution order of components
        5. Testing with JMeter
          1. Using JMeter to test web services
            1. Creating a thread group
            2. Creating the SOAP sampler
            3. Creating listeners
              1. Adding an assertion on response
              2. Adding the CSV dataset configuration
              3. Getting the final results
          2. Using JMeter to test a web application
            1. Recording our testing scenarios
              1. Creating thread groups
              2. Creating a configuration element
              3. Creating a recording controller
              4. Creating a workbench server (HTTP(s) Test Script Recorder)
              5. Updating browser settings
              6. Start recording our journeys/scenarios
              7. Adding cookie control
              8. Adding a CSV dataset
              9. Adding variables to our requests
              10. Adding suitable thinking time
              11. Adding response assertions
              12. Adding results view
              13. Executing our test plan and getting the results
          3. Using JMeter to test database scripts
            1. Configuring the JDBC connection
            2. Adding a JDBC request sampler
            3. Adding a CSV dataset configuration
            4. Adding listeners to capture test results
        6. Summary
      12. 4. Monitoring Java Applications
        1. Exploring the Java monitoring tools
          1. The operating system monitoring tools
            1. The Microsoft Windows tools
            2. The Unix/Linux tools
              1. An example of high CPU utilization
          2. The Java monitoring tools
            1. The JDK monitoring tools
            2. The monitoring tools for application servers
            3. The IDE monitoring tools
            4. The standalone monitoring tools
            5. The multifunction monitoring tools
        2. Understanding the profiling tools
          1. Profilers modes
          2. JVM TI
          3. Profiler agent
            1. The command-line options
            2. Agent start-up
          4. Different profiling patterns
            1. What we need to know from this section
        3. Understanding the different JDK tools
          1. The monitoring tool for Java virtual machine statistics
          2. The JVM memory map tool
          3. The Java heap analysis tool
          4. The Java monitoring and management console tool
          5. Java VisualVM
          6. Oracle Java Mission Control
        4. Starting with the NetBeans profiler
          1. The NetBeans profiler calibration
          2. Using the NetBeans profiler
        5. The Eclipse tools/plugins
          1. The JVM monitor
          2. The Test and Performance Tools Platform
        6. Advanced profiler – JProfiler
        7. Using the offline profiling mode
          1. Building our script using JProfiler triggers
          2. Further reading
        8. Summary
      13. 5. Recognizing Common Performance Issues
        1. Going through a slow response time umbrella
          1. Isolating the issue
            1. Client side
            2. HTTP server side (web servers)
            3. Application server issue
            4. Database server issue
            5. Integrated systems
            6. Networking components
            7. Code and script analysis
            8. Profiling the application
          2. Common performance issues
            1. Threading performance issues
            2. Memory performance issues
            3. Algorithmic performance issues
            4. Work as designed performance issues
            5. Interfacing performance issues
            6. Miscellaneous performance issues
            7. Fake performance issues
        2. Threading performance issues
          1. Blocking threads
            1. Performance symptoms
            2. An example of thread blocking
          2. Thread deadlock
        3. Memory performance issues
          1. Memory leakage
            1. Performance symptoms
            2. An example of memory leakage
          2. Improper data caching
            1. Improper caching issue types
              1. No caching (disabled caching)
              2. Too small caching size
              3. Too big caching size
              4. Using the wrong caching policy
            2. Performance symptoms
            3. An example of improper caching techniques
        4. Work as designed performance issues
          1. Synchronous where asynchronous is required
            1. Performance symptoms
            2. An example of improper synchronous code
          2. Neglecting remoteness
            1. Performance symptoms
            2. An example of using remote calls as local calls
          3. Excessive serialization performance impact
            1. Performance symptoms
            2. An example of excessive serialization
              1. Object size impact
              2. Web services granularity impact
        5. Selected performance issues
          1. Unnecessary application logic
          2. Excessive application logging
          3. Database performance issues
          4. Missing proactive tuning
        6. Client-side performance issues
          1. Chrome developer tools
            1. Network analysis
            2. JavaScript profiling
            3. Speed Tracer
          2. Internet Explorer developer tools
          3. Firefox developer tools
          4. Navigating time specifications
        7. Summary
      14. 6. CPU Time Profiling
        1. When to use CPU profiling
        2. Different CPU profiling options
          1. Using a NetBeans profiler
            1. Profiling a Java application
            2. Profiling a web application
          2. Using Java Mission Control (JMC)
          3. Using JProfiler
        3. Reading and interpreting CPU profiling results
          1. The call tree view
          2. The HotSpots view
        4. Analyzing the method time versus the method invocation count
          1. The hot spot method types
            1. Methods with high self-time
            2. Methods with high invocation events
            3. Methods with high self-time and invocation events
          2. Identifying a hot spot type
        5. Identifying potential performance issues
          1. Algorithmic/logic issues
          2. Caching issues
          3. Resourcing issues
          4. Threading issues
        6. Fixing algorithmic/logic performance
          1. Simple algorithmic evaluation
          2. Evaluating an algorithm's complexity
        7. Our first performance fixing strategy
          1. Fixing the application logic/algorithm
          2. Adding support for caching
          3. Optimizing the performance of resources
          4. Implementing concurrency or multithreading
          5. Using asynchronous methods
        8. Summary
      15. 7. Thread Profiling
        1. Determining when to use thread profiling
        2. Exploring the different thread profiling options
          1. Thread monitoring using NetBeans
          2. Thread monitoring using JProfiler
          3. Thread monitoring using Java Mission Control
        3. Reading the thread profiling results
        4. Dealing with thread dumps
          1. Taking a thread dump using the operating system commands
            1. Using the keyboard shortcut Ctrl + Pause Break
            2. Sending SIGQUIT to the Java process
          2. Taking a thread dump using the JDK tools
            1. Thread dump using jstack
            2. Thread dump using the Java VisualVM
          3. Taking thread dumps using an application's server admin console/tools
          4. Taking a thread dump using profiler tools
        5. Reading and analyzing the thread dumps
          1. Understanding the thread dump structure
          2. Analyzing the thread dumps
          3. Using Thread Dump Analyzer
        6. Exploring potential threading issues
          1. Threading performance issues
            1. Threading deadlock
            2. Blocked/starving/stuck threads
            3. Low/over threading
            4. Threading memory issues
            5. Using unmanaged threads
          2. Detecting the root cause of a hung application
            1. Detecting the hang location using thread dumps
            2. Detecting the hang location using profilers
        7. Enhancing our fixing strategy
          1. Fixing thread deadlocks and thread blocking
        8. Summary
      16. 8. Memory Profiling
        1. When to use memory profiling?
        2. Different memory profiling options
          1. Memory profiling using NetBeans
          2. Memory profiling using JProfiler
        3. Analyzing memory profiling results
          1. Analyzing memory space graphs
          2. Analyzing detailed object statistics
          3. Analyzing garbage collection activity logs (HotSpot JVM)
            1. Reading garbage collection activity logs (HotSpot VM)
            2. Visualizing the garbage collection activity
        4. Dealing with memory heap dumps
          1. Taking heap dumps on the occurrence of JVM OutOfMemoryError
          2. Taking heap dumps using the JDK tools
            1. Taking heap dump using jmap
            2. Taking heap dumps using Java VisualVM
            3. Taking heap dumps using the JRockit command utility
          3. Taking heap dumps using the profiler tools
            1. Taking heap dumps using the NetBeans profiler
            2. Taking heap dumps using Eclipse Memory Analyzer Tool (MAT)
            3. Taking heap dumps using JProfiler
        5. Analyzing the heap dump
          1. Navigating inside a heap dump using visual tools
          2. Query heap dumps using OQL
            1. Using simple OQL queries
            2. Using OQL built-in objects and functions
              1. Using a built-in heap object
              2. Using built-in functions on individual objects
        6. Potential memory performance issues
          1. Application memory leakage (session leakage versus global leakage)
          2. Improper caching implementation
          3. Memory issues of objects that contain the finalize() method
          4. Invalid contract for the equals() and hashCode() methods
          5. Different reasons for OOME
        7. Adding memory performance issues to our fixing strategy
          1. Fixing memory leakage issues
        8. Summary
      17. 9. Tuning an Application's Environment
        1. Understanding environment tuning
        2. Tuning the JVM
          1. Tuning the Java HotSpot virtual machine
            1. Understanding the different types of the JVM parameters
            2. Selecting the HotSpot JVM type
            3. Tuning memory size
            4. Tuning garbage collection
              1. Using proper garbage collection policy
              2. Setting GC performance targets
          2. Tuning the JRockit virtual machine
            1. Tuning JRockit memory size
            2. Tuning JRockit garbage collection
        3. Tuning application servers
          1. Tuning the Oracle GlassFish application server
            1. Deployment tuning options
            2. Web container tuning options
            3. EJB container tuning options
            4. Thread pool tuning options
            5. JDBC connection pool tuning options
            6. Tuning file cache components
            7. Tuning DNS caching
            8. Tuning logging information
          2. Tuning the Oracle Weblogic application server
            1. Tuning the internal applications' deployment
            2. Tuning network components
            3. Tuning stuck thread configuration
        4. Tuning web servers (HTTP servers)
          1. Tuning the Apache web server (Apache HTTP server)
          2. Tuning the Oracle web server (Oracle HTTP server)
        5. Tuning the operating system and hardware
          1. Capacity planning and hardware optimization
          2. Operating system configurations optimization
        6. Summary
      18. 10. Designing High-performance Enterprise Applications
        1. Potential performance impact of different design decisions
          1. Potential performance impact of the application layer's decisions
          2. Potential performance impact of a component's selection decisions
          3. Potential performance impact of integration decisions
          4. Potential performance impact of security decisions
          5. Potential performance impact of framework and UI decisions
          6. Potential performance impact of application interaction decisions
          7. Potential performance impact of regulatory decisions
          8. Potential performance impact of some miscellaneous decisions
        2. Avoiding performance anti-patterns
        3. Performance aspects of Service Oriented Architecture (SOA)
        4. Performance aspects of Resource Oriented Architecture (ROA)
        5. Dissecting performance aspects of data caching
          1. Data caching versus no caching
          2. Caching concurrency and performance
          3. Different levels of application data caching
          4. Caching an invalidation/expiration algorithm
          5. Caching data store interaction
          6. Caching replacement policies
          7. Data caching performance evaluation
        6. Performance considerations in cloud deployment
        7. Summary
      19. 11. Performance Tuning Tips
        1. Performance and development processes
          1. Agile and performance
          2. Performance and test-driven development (TDD)
          3. Manual and automated code review
        2. Java EE performance tuning tips
          1. Web service (WS) performance tuning tips
          2. EJB performance tuning tips
          3. Servlets and JSP performance tuning tips
          4. JSF performance tuning tips
          5. JPA performance tuning tips
        3. Java performance tuning tips
          1. String manipulation performance tuning tips
            1. String creation tips
            2. String concatenation tips
            3. The JVM String tuning parameters
          2. Java collections and performance
          3. Using synchronized blocks
          4. The I/O operations and performance
          5. Exception handling and performance
          6. Application logging and performance
        4. Using the javap tool to understand micro-optimizations
        5. Database performance tuning tips
        6. Client-side optimization
        7. Summary
      20. 12. Tuning a Sample Application
        1. Reaching our final destination
        2. Setting up the ExcellentSurvey application
        3. Functional overview of the ExcellentSurvey application
        4. ExcellentSurvey performance assessment
        5. Performance investigation plan
        6. Profiling our ExcellentSurvey application
          1. Getting CPU profiling results
          2. Getting memory and thread profiling results
          3. Getting database CPU profiling results
        7. Profiling performance findings
          1. Detected HotSpot methods
          2. Detected HotSpot database statements
          3. Potential wrong logic issues
        8. ExcellentSurvey issues and possible resolutions
          1. Fixing the EmailSender.sendEmail() HotSpot method
          2. Fixing the DAOHelper.createNewSurvey() HotSpot method
          3. Fixing the LoginFilter.log() HotSpot method
          4. Fixing the HotSpot autogen table update statement
          5. Fixing HotSpot statements to insert questions and survey questions
          6. Fixing HotSpot queries that get the notification templates/question rating types
          7. Fixing the HotSpot query that counts user surveys
        9. Performance code review
        10. Testing the application after our fixes
        11. Result and conclusion
        12. Summary
      21. Index