Java EE 8 High Performance

Book description

Get more control of your applications performances in development and production and know how to meet your Service Level Agreement on critical microservices.

About This Book

  • Learn how to write a JavaEE application with performance constraints (Service Level Agreement—SLA) leveraging the platform
  • Learn how to identify bottlenecks and hotspots in your application to fix them
  • Ensure that you are able to continuously control your performance in production and during development

Who This Book Is For

If you're a Java developer looking to improve the performance of your code or simply wanting to take your skills up to the next level, then this book is perfect for you.

What You Will Learn

  • Identify performance bottlenecks in an application
  • Locate application hotspots using performance tools
  • Understand the work done under the hood by EE containers and its impact on performance
  • Identify common patterns to integrate with Java EE applications
  • Implement transparent caching on your applications
  • Extract more information from your applications using Java EE without modifying existing code
  • Ensure constant performance and eliminate regression

In Detail

The ease with which we write applications has been increasing, but with this comes the need to address their performance. A balancing act between easily implementing complex applications and keeping their performance optimal is a present-day need. In this book, we explore how to achieve this crucial balance while developing and deploying applications with Java EE 8.

The book starts by analyzing various Java EE specifications to identify those potentially affecting performance adversely. Then, we move on to monitoring techniques that enable us to identify performance bottlenecks and optimize performance metrics. Next, we look at techniques that help us achieve high performance: memory optimization, concurrency, multi-threading, scaling, and caching. We also look at fault tolerance solutions and the importance of logging. Lastly, you will learn to benchmark your application and also implement solutions for continuous performance evaluation.

By the end of the book, you will have gained insights into various techniques and solutions that will help create high-performance applications in the Java EE 8 environment.

Style and approach

This book will cover vital concepts implemented through a sample application built throughout the book. This will enable you to apply these concepts to suit your software requirements.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  2. Money – The Quote Manager Application
    1. Setting up the environment
    2. The application architecture
    3. Application project highlights
      1. The build
      2. The persistence layer
      3. The service layer
      4. The JAX-RS layer
      5. The WebSocket layer
      6. Provision some data
    4. Application summary
      1. The application business
      2. The application design
    5. The application server
    6. Testing the application
      1. Get a quote price the JAX-RS way
      2. Get the price, the WebSocket way
    7. Setting up MySQL
    8. Conclusion
    9. Summary
  3. Looking Under the Cover – What is This EE Thing?
    1. Context and Dependency Injection – what did you do to my beans?
      1. IoC – a pretty simple example
      2. The main features of CDI
        1. Injections
        2. Scopes
        3. Interceptors/decorators
        4. Events
        5. Dynamic lookups
    2. JAX-RS – the servlet router
      1. The router
      2. Marshalling
      3. Filter and interceptors
      4. @Suspended or asynchronous operation
    3. JPA – the database link
      1. From JPA to the database
      2. Model and implications
    4. The Java Transaction API
    5. Server resources
      1. DataSource configuration
    6. Java EE and performances
      1. Ensure you know the server
      2. Ensure you know your application
      3. Ensure you know your resources
    7. Summary
  4. Monitor Your Application
    1. Java tools to know what my application is doing
      1. The jcmd command – the small command line utility that does a lot
        1. Thread.print
        2. Memory
      2. JVisualVM – the UI for JVM monitoring
        1. How to connect remotely
      3. Java Mission Control
    2. GlassFish ad hoc monitoring
    3. Libraries monitor your application
      1. Counters, gauges, timers, and more
      2. Instrumenting the code
      3. CDI instrumentation
        1. Implementing your own configurable monitoring interceptor
      4. Javaagent – a complex but powerful instrumentation
        1. Sirona javaagent
      5. SQL Monitoring
      6. Data aggregation
      7. Tracing
      8. APM
    4. Summary
  5. Application Optimization – Memory Management and Server Configuration
    1. Java and the memory
      1. Garbage collector
        1. Garbage collector algorithms
          1. The serial collector
          2. Parallel and parallel compacting collectors
          3. Concurrent Mark Sweep (CMS)
          4. Garbage First (G1)
        2. Common memory settings
        3. Debugging GC behavior
      2. Heap dump
    2. Java EE and the resources
      1. DataSource
      2. Java EE and pools
      3. Java EE and HTTP pools
      4. Java EE implicit features
    3. Summary
  6. Scale Up – Threading and Implications
    1. Java EE threading model
    2. Thread data and consistency
      1. Concurrent data access
      2. Java and thread safety
        1. Synchronized
        2. Locks
        3. java.util.concurrent
        4. The volatile data
    3. Java EE and threads
      1. CDI asynchronous events
      2. EJB @Asynchronous
      3. EE concurrency utilities for Java EE
        1. ManagedExecutorService
        2. ManagedScheduledExecutorService
        3. Java EE threads
        4. ContextService
      4. EJB @Lock
      5. HTTP threads
        1. Server side
        2. Client side
    4. Reactive programming and Java EE
      1. Message passing and Java EE
    5. Summary
  7. Be Lazy; Cache Your Data
    1. Caching challenges
      1. How does the cache work?
        1. The cache key
        2. Eviction policy
          1. Least Recently Used (LRU)
          2. First In First Out (FIFO)
          3. Random
          4. Least Frequently Used (LFU)
          5. Cache eviction trigger
        3. Cache storage – memory or not
      2. Consistency of the data
    2. HTTP and caching
      1. Cache-Control
      2. ETag
      3. Vary
      4. HTTP caching and the Java EE API
      5. HTTP 2 promise
    3. JCache – the standard cache of Java EE
      1. Setting up JCache
      2. Programmatic API
        1. JCache configuration
      3. CDI integration
        1. Cache configuration
          1. @CacheDefaults
        2. Cache key
    4. Cache once
    5. Summary
  8. Be Fault-Tolerant
    1. It will fail, no doubt!
    2. Load balancing – pick the best one
      1. Transparent load balancing – client versus server
      2. Common strategies
        1. The round-robin algorithm
        2. Random load balancing
        3. Link to failover
        4. Sticky session
        5. The scheduling algorithm
      3. Load balancing or proxy – additional features
    3. Failover
      1. Switching to another system
      2. Local fallback
        1. Fallback code structure
          1. Microprofile to the rescue
          2. Failover extension
        2. Fallback handling – caching, an alternative solution
      3. Circuit breaker
    4. Bulk head
    5. Timeouts
      1. Timeouts for code without timeouts
    6. Summary
  9. Loggers and Performances – A Trade-Off
    1. I log, you log, they log
    2. Logging frameworks and concepts
      1. Logger
      2. Logger Factory
      3. LogRecord
      4. Handler
      5. Filter
      6. Formatter
      7. Level
    3. Logging invocations
      1. Filters
      2. Formatters
      3. Using handlers
      4. Logging components and Java EE
    4. Logging patterns
      1. Testing your level
      2. Using templates in your messages
      3. Asynchronous or not?
    5. Logging implementations – which one to pick
      1. Logging facade – the good bad idea
      2. Logging frameworks
        1. Log4j
        2. Log4j2
        3. Logback
        4. JUL
      3. Choosing an implementation
    6. Summary
  10. Benchmarking Your Application
    1. Benchmarking – validating your application against your SLA
      1. Benchmark, benchmark, benchmark
    2. Preparing your benchmark
      1. Defining the benchmark criteria
        1. Defining the metric
        2. Defining acceptance criteria
        3. Defining the scenario
      2. Defining the environment
        1. The machines
        2. The network
        3. Databases and remote services
        4. The server
      3. Automatize your scenarios
        1. JMeter
        2. Gatling
        3. Other tools
      4. Ensuring you have support
      5. Time boxing your optimization benchmark
      6. Installing and resetting procedures
    3. Benchmark iterations
      1. Iterating
      2. Changing a single setting at a time
      3. Resetting any state between runs
      4. Warming up your system
    4. After your benchmark
      1. Writing a report
      2. Updating your default configurations
      3. Reviewing the conclusions
      4. Enriching your project backlog
    5. Summary
  11. Continuous Performance Evaluation
    1. Writing performance tests – the pitfalls
    2. Writing performance tests
      1. JMH – the OpenJDK tool
        1. Writing a benchmark with JMH
          1. The state
          2. Creating your first JMH benchmark
          3. BlackHole to be a star
        2. Running the benchmarks
        3. Integrating JMH with JUnit
      2. ContiPerf
        1. Arquillian and ContiPerf – the diabolic pair
      3. JMeter and build integration
      4. Gatling and continuous integration
      5. Deploying your (benchmark) application
    3. Continuous integration platform and performance
    4. Summary
  12. Another Book You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Java EE 8 High Performance
  • Author(s): Romain Manni-Bucau
  • Release date: January 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788473064