Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

JBoss AS 5 Performance Tuning
JBoss AS 5 Performance Tuning
JBoss AS 5 Performance Tuning
Ebook604 pages4 hours

JBoss AS 5 Performance Tuning

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Packed with practical examples, this book looks at a different aspect of performance tuning in each chapter and shows the reader how to apply them to their existing Java applications. Written to version 5.1, this book also has information about the upcoming 6.0 release and how you can upgrade your existing applications. This book is for Java architects who design and configure Enterprise applications. It is great for Java developers who want to get into the inner details of the application server and of the correct tuning methodology. Application testers will also find this book useful as they will learn how to monitor the performance of the middleware with the correct instruments.
LanguageEnglish
Release dateDec 3, 2010
ISBN9781849514033
JBoss AS 5 Performance Tuning
Author

Francesco Marchioni

Francesco Marchioni is a Red Hat Certified JBoss Administrator (RHCJA) and a Sun Certified enterprise architect working as a freelancer in Rome, Italy. He started learning Java in 1997, and since then, he has followed the path to the newest application program interfaces released by Sun. In 2000, he joined the JBoss community, when the application server was running the release 2.X. He has spent many years as a software consultant, wherein he envisioned many successful software migrations from vendor platforms to open source products such as JBoss AS, fulfilling the tight budget requirements of current times. Over the past 5 years, he has been authoring technical articles for OReilly Media and running an IT portal focused on JBoss products (http://www.mastertheboss.com). In December 2009, he published JBoss AS 5 Development, which describes how to create and deploy Java Enterprise applications on JBoss AS (http://www.packtpub.com/jboss-as-5-development/book). In December 2010, he published his second title, JBoss AS 5 Performance Tuning, which describes how to deliver fast and efficient applications on JBoss AS (http://www.packtpub.com/jboss-5-performance-tuning/book). In December 2011, he published yet another title, JBoss AS 7 Configuration, Deployment, and Administration, which covers all the aspects of the newest application server release (http://www.packtpub.com/jboss-as-7-configuration-deploymentadministration/book). In June 2013, he authored a new title, JBoss AS 7 Development, which focuses on developing Java EE 6 API applications on JBoss AS 7 (https://www.packtpub.com/application-development/jboss-7-development).

Read more from Francesco Marchioni

Related to JBoss AS 5 Performance Tuning

Related ebooks

Information Technology For You

View More

Related articles

Reviews for JBoss AS 5 Performance Tuning

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    JBoss AS 5 Performance Tuning - Francesco Marchioni

    Table of Contents

    JBoss AS 5 Performance Tuning

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    Why Subscribe?

    Free Access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Errata

    Piracy

    Questions

    1. Performance Tuning Concepts

    Preface

    What you will get from this book?

    What is performance?

    Scalability: the other side of performance

    The tuning process

    Tuning in the software development cycle

    Building the performance test

    Establish a baseline

    Collect data

    How long should data collection last?

    Analyze data

    Configure and test again

    Tuning Java Enterprise applications

    Areas of tuning

    Summary

    2. Installing the Tools for Tuning

    Welcome to scientific tuning

    The rationale behind the choice of the tools

    Profiling the Java Virtual Machine

    Installing the JVM

    Installing VisualVM

    Connecting to a local server

    Connecting to a remote server

    Monitoring your server

    The Monitor tab

    The Threads tab

    The Profiler tab

    Collecting snapshots

    Extending VisualVM

    Profiling your applications with Eclipse Test and Performance Tools Platform (TPTP) Project

    Installing the TPTP suite

    Updating Eclipse

    How to profile an application

    Going beyond the basics of TPTP

    Load testing your application with JMeter

    Building a Test Plan

    Step 1: Create a Thread Group

    Step 2: Create a Sampler

    Step 3: Create a Listener

    Making your test plan a bit more realistic

    How to create a complex Test Plan

    Running JMeter as a shell

    Operating system tools and commands

    Windows users

    Unix users

    Dealing with low CPU utilization

    Dealing with high CPU utilization

    Dealing with high resource contention

    Dealing with high disk utilization

    Summary

    3. Tuning the Java Virtual Machine

    The starting point

    Choosing the JVM settings

    Setting the correct heap size

    The correct amount of memory to grant your application

    Step # 1: Finding the maximum heap (-Xmx)

    Step # 2: Finding the initial heap size (-Xms)

    I cannot allocate enough memory for the JVM!

    Where do I configure JVM settings in JBoss AS?

    Sizing the garbage collector generations

    Which is the correct ratio between the young and old generations?

    The garbage collector algorithms

    Choosing the right garbage collector for your application

    The G1 garbage collector

    Debugging garbage collection

    Making good use of the memory

    Avoid creating large Java objects

    Handling 'Out of Memory' errors

    Finding the memory leak in your code

    A practical example

    Application description

    Setting up a test bed

    Benchmark aftermath

    Consideration #1

    Consideration #2

    Action

    Further optimization

    Summary

    4. Tuning the JBoss AS

    From release 4.x to 5.x, and on

    Comparing server releases

    Creating a custom application server configuration

    JBoss AS pools

    The System thread pool

    Finding out if the System thread pool is a bottleneck

    JDBC connection pool

    Calculating the optimal min-pool-size and max-pool-size

    Using Prepared Statements efficiently

    Two things to be aware of:

    Detecting connection leaks

    Should you reuse connections or acquire new ones from the pool?

    Logging for performance

    Choosing the best logging strategy

    Which is the fastest appender?

    Should I use the AsyncAppender to improve my log throughput?

    Which layout should I choose for my logs?

    Is it enough to increase the log threshold to get rid of log charge?

    How does logging hierarchy influence performance?

    Summary

    5. Tuning the Middleware Services

    Introduction to Enterprise Java Beans

    Session Beans

    How to configure the optimal size for stateless pool?

    How to configure the optimal size of stateful cache?

    Comparing SLSBs and SFSBs performance

    When things get wilder

    Is it possible that Stateful Beans are faster then Stateless Beans?

    Session Beans and Transactions

    Customizing JBoss EJB container policies

    Customizing the single deployment unit

    Introduction to the Java Messaging system

    Entering the JBoss Messaging system

    Tuning JBoss JMS provider

    Tuning JBoss Messaging (JBoss AS 5.x)

    How do you tune the JBoss Messaging Connection factory?

    How do you tune JBoss Messaging destinations?

    Tuning HornetQ (JBoss AS 6.x)

    How to configure HornetQ journal for optimal performance?

    How do you configure HornetQ transport for optimal performance?

    Basic JMS tuning

    An example use case with HornetQ

    Summary

    6. Tuning the Persistence Layer

    Designing a good database

    Reducing the space needed by your database

    Partitioning the database

    Using indexes

    Tuning JDBC

    Using a Connection Pool

    Setting the proper fetch size

    Use batch updates for bulk insert/updates

    Use Prepared Statements instead of Statements

    Tuning JDBC networking

    Tuning Hibernate and JPA

    Optimizing object retrieval

    Limiting the amount of data fetched with pages

    Fetching parent and child items with a single query

    Combining join fetches and paging

    Speeding up your Hibernate queries with batches

    Using named queries to speed up your queries

    Improving the performance of bulk SQL statements

    Evaluating using caches to speed up your queries

    Hibernate caches

    The first-level cache

    The second-level cache

    Configuring the second-level cache on JBoss AS

    The query cache

    Entity cache versus query cache

    Optimizing data synchronization

    A sample use case

    Summary

    7. JBoss AS Cluster Tuning

    Introduction to JBoss clustering

    Configuring JGroups transport

    How to optimize the UDP transport configuration

    How to optimize the JGroups' Protocol stack

    Tuning JBoss Cache

    Understanding JBoss Cache configuration

    Configuring cacheMode

    Configuring cache concurrency

    Configuring the isolationLevel

    Tuning session replication

    Override SFSB's isModified method

    Use buddy replication

    Advanced buddy replication

    Buddy replication and session affinity

    Configure replication granularity and replication trigger

    How to configure the replication-trigger

    How to configure the replication-granularity

    Tuning cache storage

    Where does cache data get stored?

    Summary

    8. Tomcat Web Server Tuning

    JBoss Web server basics

    Configuring Connectors for optimal performance

    How do you calculate the threads for your application?

    A concrete example

    The long life of Web threads

    Is there a maximum amount of connections the Web server can handle?

    Using Apache Portable Runtime

    Integrating JBoss Web server with Apache Web server

    Load testing Apache-JBoss connectivity

    mod_cluster to the rescue?

    Last tips before rolling JBoss Web server in production

    Summary

    9. Tuning Web Applications on JBoss AS

    Choosing a framework for your web applications

    Comparing framework performance

    The performance of tabular data

    The performance of rich tree

    Increasing the performance of JSF and RichFaces

    Configuring JSF state saving efficiently

    Using Ajax to speed up your JSF applications

    Speeding up CSS and JavaScript file loading

    Tuning web services

    Performance of web services

    Elements influencing the performance of web services

    Reducing the size of SOAP messages

    Faster JBossWS provider

    The wisdom behind these benchmarks

    Summary

    A. A Tuned Mind

    Index

    JBoss AS 5 Performance Tuning


    JBoss AS 5 Performance Tuning

    Copyright © 2010 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: December 2010

    Production Reference: 1291110

    Published by Packt Publishing Ltd.

    32 Lincoln Road

    Olton

    Birmingham, B27 6PA, UK.

    ISBN 978-1-849514-02-6

    www.packtpub.com

    Cover Image by Duraid Fatouhi (<duraidfatouhi@yahoo.com>)

    Credits

    Author

    Francesco Marchioni

    Reviewers

    Devon Hillard

    Kushal Paudyal

    Acquisition Editor

    Sarah Cullington

    Development Editor

    Meeta Rajani

    Technical Editors

    Sakina Kaydawala

    Kartikey Pandey

    Manasi Poonthottam

    Indexers

    Hemangini Bari

    Rekha Nair

    Editorial Team Leader

    Mithun Sehgal

    Project Team Leader

    Priya Mukherji

    Project Coordinator

    Shubhanjan Chatterjee

    Proofreader

    Kevin McGowan

    Graphics

    Nilesh Mohite

    Production Coordinator

    Adline Swetha Jesuthas

    Cover Work

    Adline Swetha Jesuthas

    About the Author

    Francesco Marchioni is a Sun Certified Enterprise Architect employed by an Italian company based in Rome. He started learning Java in 1997 and since then he has followed the path to the newest Application Program Interfaces released by Sun. Since 2000, he has joined the JBoss Community when the application server was running release 2.X.

    He has spent many years as a software consultant, where he has created many successful software migrations from vendor platforms to the open source products like JBoss AS, fulfilling the tight budget requirements of current times.

    In the past five years he has started authoring technical articles for O'Reilly Media and running an IT portal focused on JBoss products (http://www.mastertheboss.com).

    In December 2009, he published the title, JBoss AS 5 Development, which describes how to create and deploy Java Enterprise applications on JBoss AS—http://www.packtpub.com/jboss-as-5-development/book.

    I'd like to thank Packt Publishing for offering another opportunity to write about my favorite application server. I'd also like to thank my family for supporting me during the creation of this book, in particular my father for teaching me all the tricks of the glorious C-64 when I was a kid.

    Also a special thanks to the people that collaborated to this book: my friend Luca Viola who lent me the hardware for these benchmarks. JBoss guys Carlo de Wolf and Alessio Soldano for their precious advices. And last but not least the technical reviewers - Devon Hillard and Kushal Paudyal—and all the Packt Pub staff for their competent cooperation.

    About the Reviewers

    Devon Hillard is a J2EE Architect with over 12 years of experience working on some of the largest e-commerce sites in the world including AT&T, Target, JCrew, and many more. Working with large-scale enterprise environments has led to a natural focus on performance and security.

    Devon created http://10MinuteMail.com, a popular temporary e-mail service, which is one of the top 10,000 sites in the world (based on http://www.alexa.com/ ranking). Devon is also a founding partner at Spark::red, a premier hosting company for Fortune 500 clients using ATG e-commerce software, and often consults in the e-commerce, performance, and security arenas. He has also reviewed several technical book manuscripts on topics such as JBoss, GWT, and JBoss Seam.

    Kushal Paudyal has been a professional Software Engineer for over five years on the Java/J2EE platform. He currently works as a Technical Lead for one of the biggest companies in USA that provides warranty management software. Apart from design, development, testing, and global delivery of the software, Kushal has extensive experience of leading a team of support analysts in supporting the enterprise applications deployed to top notch automotive industries in USA and optimizing the performance of production applications deployed to JBoss and WebSphere application servers.

    Kushal's domain of expertise is warranty, fleet, and service lifecycle management. He holds a masters degree in Computer Science and a bachelor's degree in Computer Engineering.

    Apart from work, Kushal is a hobbyist photographer. He can be reached at <kushalzone@gmail.com>.

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    You might want to visit www.PacktPub.com for support files and downloads related to your book.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    http://PacktLib.PacktPub.com

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. 

    Why Subscribe?

    Fully searchable across every book published by Packt

    Copy & paste, print and bookmark content

    On demand and accessible via web browser

    Free Access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

    Quod non fecerunt barbari, Barberini fecerunt. Quod non fecerunt Barberini, fecit Berlusconi.

    We're living in Italy the last days of Pompeii: defend our cultural heritage before it's too late!

    Preface

    JBoss AS 5 Performance Tuning will teach you how to deliver fast applications on the JBoss Application Server and Apache Tomcat, giving you a decisive competitive advantage over your competitors. You will learn how to optimize hardware resources, meeting your application requirements with less expenditure.

    The performance of Java Enterprise applications is the sum of a set of components including the Java Virtual Machine configuration, the application server configuration (in our case, JBoss AS), the application code itself, and ultimately the operating system. This book will show you how to apply the correct tuning methodology and use the tuning tools that will help you to monitor and address any performance issues.

    By looking more closely at the Java Virtual Machine, you will get a deeper understanding of what the available options are for your applications, and how their performance will be affected. Learn about thread pool tuning, EJB tuning, and JMS tuning, which are crucial parts of enterprise applications.

    The persistence layer and the JBoss Clustering service are two of the most crucial elements which need to be configured correctly in order to run a fast application. These aspects are covered in detail with a chapter dedicated to each of them.

    Finally, Web server tuning is the last (but not least) topic covered, which shows how to configure and develop web applications that get the most out of the embedded Tomcat web server.

    What this book covers

    Chapter 1, Performance Tuning Concepts, discusses correct tuning methodology and how it fits in the overall software development cycle.

    Chapter 2, Installing the Tools for Tuning, shows how to install and configure the instruments for tuning, including VisualVM, JMeter, Eclipse TPTP Platform, and basic OS tools.

    Chapter 3, Tuning the Java Virtual Machine, provides an in-depth analysis of the JVM heap and garbage collector parameters, which are used to start up the application server.

    Chapter 4, Tuning the JBoss AS, discusses the application server's core services including the JBoss System Thread Pool, the Connection Pool, and the Logging Service.

    Chapter 5, Tuning the Middleware Services, covers the tuning of middleware services including the EJB and JMS services.

    Chapter 6, Tuning the Persistence Layer, introduces the principles of good database design and the core concepts of Java Persistence API with special focus on JBoss's implementation (Hibernate).

    Chapter 7, JBoss AS Cluster Tuning, covers JBoss Clustering service covering the low-level details of server communication and how to use JBoss Cache for optimal data replication and caching.

    Chapter 8, Tomcat Web Server Tuning, covers the JBoss Web server performance tuning including mod_jk, mod_proxy, and mod_cluster modules.

    Chapter 9, Tuning Web Applications on JBoss AS, discusses developing fast web applications using JSF API and JBoss richfaces libraries.

    What you need for this book

    A technical prerequisite for this book is knowledge of and expertise with the Java Enterprise API and the basics of the JBoss application server. Besides the technical skills, which are necessary to grasp the tuning concepts, no other requirements are necessary. As a matter of fact, all the software discussed in this book can be freely downloaded and used both in development and in production systems.

    Who this book is for

    This book is for Java architects who design and configure Enterprise applications. It is great for Java developers who want to get into the inner details of the application server and of the correct tuning methodology. Application testers will also find this book useful as they will learn how to monitor the performance of the middleware with the correct instruments.

    Conventions

    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 are shown as follows: If you then request the ordered items through the customer.getItems() method, this would also fill the collection of items ordered with another database hit.

    A block of code is set as follows:

    @NamedQueries(

    {

      @NamedQuery(

        name = listCustomers,

        query = FROM Customer c WHERE c.name = :name

      )

    })

     

    public class Customer implements Serializable  {

     

    }

    When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    Session session =HibernateUtil.getSessionFactory().openSession();

     

    session.beginTransaction();

     

    for (int index = 0; index <1000;index++) {

     

      Person person = new Person();

      book.setCountry(Usa);

      book.setCity(NY);

      person.setName(Inhabitant n. + index);

     

      session.save(person);

      // Flush every 50 records

     

    if (index % 50== 0) {session.flush();session.clear();

    }

     

    session.getTransaction().commit();

    session.close();

    Any command-line input or output is written as follows:

    export JAVA_HOME=/installDir/jdk1.6.0_20

    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: Then pick up the method you want to test and select Configure which automatically configures your web service properties.

    Note

    Warnings or important notes appear in a box like this.

    Note

    Tips and tricks appear like this.

    Reader feedback

    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 <feedback@packtpub.com>, and mention the book title via the subject of your message.

    If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

    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.

    Customer support

    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.

    Tip

    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.

    Errata

    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/support, 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

    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 <copyright@packtpub.com> with a link to the suspected pirated material.

    We appreciate your help in protecting our authors, and our ability to bring you valuable content.

    Questions

    You can contact us at <questions@packtpub.com> if you are having a problem with any aspect of the book, and we will do our best to address it.

    Chapter 1. Performance Tuning Concepts

    All slow application abandon, ye who enter here. (Freely adapted from Dante's Divine Comedy Poem—http://en.wikipedia.org/wiki/Divine_Comedy)

    Preface

    One day like many, on a JBoss AS Forum:

    "Hi

    I am running the Acme project using JBoss 5.1.0. My requirement is to allow 1000 concurrent users to access the application. But when I try to access the application with 250 users, the server slows down and finally throws an exception Could not establish a connection with the database. Does anyone have an idea please help me to solve my problem.

    In the beginning, performance was not a concern for software. Early programming languages like C or Cobol were doing a decent job of developing applications and the end user was just discovering the wonders of information technology that would allow him to save a lot of time.

    Today we are all aware of the rapidly changing business environment in which we work and live and the impact it has on business and information technology. We recognize that an organization needs to deliver faster services to a larger set of people and companies, and that downtime or poor responses of those services will have a significant impact on the business.

    To survive and thrive in such an environment, organizations must consider it an imperative task for their businesses to deliver applications faster than their competitors or they will risk losing potential revenue and reputation among customers.

    So tuning an application in today's market is firstly a necessity for survival, but, there are even more subtle reasons, like using your system resources more efficiently. For example, if you manage to meet your system requirements with fewer fixed costs (let's say by using eight CPU machine instead of a 16 one) you are actually using your resources more efficiently and thus saving money. As an additional benefit you can also reduce some variable costs like the price of software licenses, which are usually calculated on the amount of CPUs used.

    On the basis of these premises, it's time to reconsider the role of performance tuning in your software development cycle, and that's what this book aims to do.

    What you will get from this book?

    This book is an exhaustive guide to improving the performance of your Java EE applications running on JBoss AS and on the embedded web container (Jakarta Tomcat). All the guidelines and best practices contained in this book have been patiently collected through years of experience from the trenches and from the suggestions of valuable people, and ultimately in a myriad of blogs, and each one has contributed to improve the quality of this book.

    The performance of an application running on the application server is the result of a complex interaction of many aspects. Like a puzzle, each piece contributes ultimately to define the performance of the final product. So our challenge will be to teach how to write fast applications on JBoss AS, but also how to tune all the components

    Enjoying the preview?
    Page 1 of 1