Performance tuning is one of the biggest challenges in dealing with the Java Enterprise applications, where each delay in response to the customer might cause the enterprise to lose valuable customers. In particular, during marketing campaigns, such as launching a new product, the load over the application jumps to a peak. It is common to see some enterprise applications that do not respond to customers! If such a thing happens and the application cannot withstand such load, it will not only lead to a loss of the expected sales, but also destroy the reputation of the enterprise.
During years of working in many large companies with different enterprise applications, which are usually composed of many integrated applications that are provided by different vendors, many challenges have contributed to the performance tuning of these applications, such as how to design a high performing application, how to minimize the occurrences of performance issues, how to build a performance team, how to test the application performance efficiently, how to create an investigation plan, and many other questions that need to be answered correctly. We tried to address these questions and others in this book, aiming to help establish a clear, organized, and smooth way of dealing with performance tuning of enterprise applications.
We have focused, in particular, on simplicity and clarity to remove any mystery around the art of performance tuning. This book is designed in a progressive pattern where each chapter represents a step forward towards completing the complete process of handling the performance issues from end-to-end in any enterprise application, starting from the requirement phase to the production support phase.
Performance tuning activities happen usually in the most stressful times in the enterprise application's life! When I started my work in performance tuning, it was the task that I needed to accomplish as soon as possible. This led to an unnecessary increase in stress and tension. Later, I learned the best way to deal with performance tuning; dealing with it as an art and enjoying the work in performance tasks (just like painting a picture or completing a puzzle). It is an art that we need to respect and enjoy. In this book, we will try to cover all the required details to understand performance tuning and the best way to deal with this art.
Dealing with performance tuning as an art and organizing our thoughts are the most important concepts here, and are also the most helpful factors (other than the person's luck!). Spending months to write this book and organizing its different sections was a very challenging procedure, in particular, to establish a well-defined, organized way of dealing with performance tuning—starting from the knowledge, which is considered as our solid foundation here, up to the strategic thinking. While dealing with these issues, establishing and finding this thinking strategy is much more important than having a look-up book that describes each problem and the possible resolution. This thinking strategy along with the required skills and mastery of different tools will provide the best way to guarantee the resolution of any new performance issues whenever this strategy is strictly followed.
In addition to that, Java Enterprise Edition 7 (Java EE 7) platform introduced a lot of new features and improvements that enterprise applications can benefit from performance perspective. This is a part of our essential knowledge to work in performance tuning of Java EE 7 applications.
Because of all of this, I encourage you to go through this book chapter by chapter, be patient and read the book to the end, download the required tools, and practice all the examples to gain the maximum value from this book.
Chapter 1, Getting Started with Performance Tuning, takes you through the art of performance tuning with its different components and shows you how to think when we face any performance issue. It focuses on preparing you to deal with the world of performance tuning and defining the handling tactics.
Chapter 2, Understanding Java Fundamentals, lays the foundation of required knowledge of the new features in Java Enterprise Edition 7 and different important Java concepts, including the JVM memory structure and Java concurrency. It also focuses on the different Java Enterprise Edition concurrency capabilities.
Chapter 3, Getting Familiar with Performance Testing, discusses performance testing with its different components, defines useful terminologies that you need to be aware of, and then gives hands-on information about using Apache JMeter to create your performance test plans for different components and get the results.
Chapter 4, Monitoring Java Applications, dissects the different monitoring tools that will be used in performance tuning, starting from the operating system tools, different IDE tools, JDK tools, and standalone tools. It covers JProfiler as an advanced profiling tool with its offline profiling capabilities.
Chapter 5, Recognizing Common Performance Issues, discusses the most common performance issues, classifies them, describes the symptoms, and analyzes the possible root causes.
Chapter 6, CPU Time Profiling, focuses on the details of getting the CPU and time profiling results, ways to interpret the results, and ways to handle such issues. It discusses the application logic performance and ways to evaluate different application logics. It provides the initial performance fixing strategy.
Chapter 7, Thread Profiling, discusses thread profiling with details on how to read and interpret thread profiling results and how to handle threading issues. It also highlights the ways to get, use, and read the thread dumps.
Chapter 8, Memory Profiling, discusses how to perform memory profiling, how to read and interpret the results, and how to identify and handle possible issues. It also shows how to read and query memory heap dumps and analyze the different out of memory root causes. The chapter finishes your draft performance fixing strategy.
Chapter 9, Tuning an Application's Environment, focuses on tuning the application environment, starting from the JVM and passing through other elements such as the application servers, web servers, and OS. We will focus on selected examples for each layer and discuss the best practices for tuning them.
Chapter 10, Designing High-performance Enterprise Applications, discusses design and architecture decisions and the performance impact. This includes SOA, REST, cloud, and data caching. It also discusses the performance anti-patterns.
Chapter 11, Performance Tuning Tips, highlights the performance considerations when using the Agile or Test-driven Development methodologies. This chapter also discusses some performance tuning tips that are essential during the designing and development stages of the Java EE applications, including database interaction, logging, exception handling, dealing with Java collections, and others. The chapter also discusses the javap
tool that will help you to understand the compiled code in a better way.
Chapter 12, Tuning a Sample Application, includes hands-on, step-by-step tuning of a sample application that has some performance issues. We will measure the application performance and tune the application issues, and re-evaluate the application performance.
The following tools should be downloaded and installed on your machine, as we will be using them throughout the book. You can have the mentioned versions or later versions. Some additional tools will also be required in some chapters:
Java JDK jdk1.7.0_45 (or later)
NetBeans 7.4 (or later)
Glassfish Version 4.0 (packaged with NetBeans 7.4)
You can download the JDK, NetBeans, and GlassFish from the following URL: http://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-432126.html
MySQL Server 5.5 (or later)
You can download this from the following URL: http://dev.mysql.com/downloads/mysql/
Eclipse bundled with TPTP
You can download this from the following URL: http://www.eclipse.org/tptp/home/downloads/
Apache JMeter 2.10
You can download this from the following URL: http://jmeter.apache.org/download_jmeter.cgi
JProfiler 8.x
You can download this from the following URL: http://www.ej-technologies.com/download/jprofiler/files
If you do not have a license, you can get a trial evaluation license from the following URL: http://www.ej-technologies.com/download/jprofiler/trial
This book is for experienced Java developers, architects, team leaders, consultants, support engineers, and all people working in the performance tuning in the Java applications, and particularly in Java Enterprise applications.
This book represents a strong entry point for the persons without any performance tuning experience and who want to work in the performance tuning in the Java applications.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The code example will select data from the Employees
table."
A block of code is set as follows:
@NotNull @Size(min=1, max=12) private String name; @ValidEmail public String getEmailAddress() { return emailAddress; }
Any command-line input or output is written as follows:
apache-jmeter-2.10\bin\jmeter.bat (for windows) Or jmeter.sh (for non-windows)
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes, for example, appear in the text like this: "By adding it at the Thread Group level, we ensure that all HTTP requests share the same cookies/session."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>
, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
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.
We also provide you a PDF file that has color images of the screenshots used in this book. You can download this file from https://www.packtpub.com/sites/default/files/downloads/6428EN_ColorGraphics.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.