“This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decision. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Jonathan Maron
Consultant Member Tech Staff

“This presentation is for informational purposes only and may not be incorporated into a contract or agreement.”

Performance Tuning for J2EE Applications
Tier by Tier

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

Performance Issues Abound!
2003 Wily Benchmark Survey shows • 60% of time Java applications fail to meet user expectations • Only 42% of applications perform as planned during deployment • 57% of application performance spent in data access 2004 Forrester • 66% of time developers find out about performance problems from user calls!

J2EE Application Complexity
Client Side Presentation Browser Pure HTML Java Applet Desktop Java Application Device J2EE Client J2EE Platform J2EE Platform JSP EJB Server-Side Presentation Web Server JSP Servlet Server-Side Business Logic EJB Container EJB EJB Enterprise Information Systems

“Premature optimization is the root of all evil”
- Professor Sir Charles Anthony Richard Hoare

“There are two rules for when to optimize: 1. Don't do it. 2. (For experts only) Don't do it yet.”
- Michael Jackson, Principles of Program Design

“Test driven design can lead to emergent optimization and code that is readily optimizable. If programmers develop test first, many of their upfront concerns about performance can be deferred.”

- Michael Feathers, Emergent Optimization in Test Driven Design

What is Performance Tuning?
• Anticipate Performance Requirements • Balance cost and benefits of optimal performance • Optimize
• Response time • Throughput • Wait time

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

Methodical approach to performance evaluation
Develop Evaluate Identify

Test

Design

Know your application
• • • • • J2EE (which components?) JDBC (which datasource class?) SSL? Single Sign On? …

Approach Tuning Issues Logically and Iteratively
Component Applications Application Server Java Virtual Machine Database Hardware and Operating System
Tuning and debugging are ongoing iterative processes. There are no magic bullets.

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

J2EE Application Tuning
Client Side Presentation Browser Pure HTML Java Applet Desktop Java Application Device J2EE Client J2EE Platform J2EE Platform JSP EJB Server-Side Presentation Web Server JSP Servlet Server-Side Business Logic EJB Container EJB EJB Enterprise Information Systems

Tuning JDBC Performance: Start with the Obvious
• Use connection pooling
• Connection objects are expensive • Tailor min and max connections to your application

• Avoid cycling physical database connections
• Look for database connections timing out

• Tune statement caching
• Cache distinct SQL statements

Connection Pooling
J2EE Container
Connection Pooling From the Container

RacingFacade • create • teamOrders •...

Application uses available connections

Toplink Indirection – Just in Time Reading
• • • Use of proxy to defer reading until required Very valuable performance feature Several Implementation Options
• • • • Explicit proxy Dynamic proxy (java.lang.reflect.Proxy) Development time class enhancement (source or byte codes) Dynamic class enhancement

Customer

ValueHolder

Address

List

PhoneNumber

Tune Your SQL!
• Easier said than done
• • • What is the real SQL running in CMP EJB? Tools like P6Spy, Oracle Enterprise Manager Toplink Indirection, join reading, and batch reading reduces DB round-trips Tune using traditional techniques

• Look at the SQL on the wire • Minimize database calls • Become good friends with your DBA

• Explain plan • Tools like SQLPlus and Oracle9i JDeveloper

D E M O N S T R A T I O N

JDBC Performance

J2EE Application Tuning
Client Side Presentation Browser Pure HTML Java Applet Desktop Java Application Device J2EE Client J2EE Platform J2EE Platform JSP EJB Server-Side Presentation Web Server JSP Servlet Server-Side Business Logic EJB Container EJB EJB Enterprise Information Systems

EJB - Locking-Mode and Isolation
• Pessimistic locking is generally slower
• May be required for applications where data collisions are likely

• Increasing isolation decreases performance
• Evaluate your data consistency requirements

Transactions and Performance
• Entity beans load/store data at transaction boundaries
• Transactions settings affect how often database is accessed • Poor performance can be caused by transaction settings

• Rules of thumb
• Always use transactions for entity bean methods • Scope the unit of work from a session bean

Session Bean - Tx:None Entity Bean - Tx:Required
TopicSessionFacade Topic

•create •findBy System.out.println(“<Create Test>"); •getTopicId •createTopicSetfor(int i=0;i<3;i++) { •getTopicDesc •printTopicSet TopicLocal topic = •getTopicName •deleteTopicSet topicHome.create( •setTopicId new Integer(i),("topic " + i)); •setTopicDesc topic.setDesc("desc" + i); •setTopicName }
System.out.println(“</Create Test>");

tx:None

tx:Required

Resulting Transactional Activity
Tx create Tx setDesc Tx create Tx setDesc Tx create Tx setDesc <Create Test> TopicBean: ejbCreate id = 0 TopicBean: ejbStore id = 0 TopicBean: ejbLoad id = 0 TopicBean: ejbStore id = 0 TopicBean: ejbCreate id = 1 TopicBean: ejbStore id = 1 TopicBean: ejbLoad id = 1 TopicBean: ejbStore id = 1 TopicBean: ejbCreate id = 2 TopicBean: ejbStore id = 2 TopicBean: ejbLoad id = 2 TopicBean: ejbStore id = 2 </Create Test>

Requires: 12 lifecycle calls

Session Bean - Tx:Required Entity Bean - Tx:Required
TopicSessionFacade Topic
•create •findBy System.out.println(“<Create Test>"); •getTopicId •createTopicSetfor(int i=0;i<3;i++) { •getTopicDesc •printTopicSet TopicLocal topic = •getTopicName •deleteTopicSet topicHome.create( •setTopicId new Integer(i),("topic " + i)); •setTopicDesc topic.setDesc("desc" + i); •setTopicName }
System.out.println(“</Create Test>");

tx:Required

tx:Required

Resulting Transactional Activity
<Create Test> TopicBean: ejbCreate id = 0 TopicBean: ejbCreate id = 1 TopicBean: ejbCreate id = 2 </Create Test TopicBean: ejbStore id = 0 TopicBean: ejbStore id = 1 TopicBean: ejbStore id = 2

Tx : createTopic

Same code: 6 lifecycle calls

Take Advantage of Your EJB Container Configuration
Example Parameter calltimeout max-txretries Type
Session & Entity Session & Entity

Performance Characteristic Impacted
Specifies the maximum time to wait for any resource that the EJB container needs before the container calls the EJB method (excluding DB). Specifies the number of times to retry a transaction that was rolled back due to system level failures. Set to false to avoid the extra select before insert (checks if entity already exists before doing the insert). Detects a duplicate during insert. Specifies whether the container updates only modified fields or all fields when ejbStore is invoked. Default true.

CMP do-selectbefore-insert

updatechangedfields-only pool-cachetimeout

CMP

Stateless Session

Specifies how long to keep stateless sessions cached in the pool.

D E M O N S T R A T I O N

EJB Tuning

J2EE Application Tuning
Client Side Presentation Browser Pure HTML Java Applet Desktop Java Application Device J2EE Client J2EE Platform J2EE Platform JSP EJB Server-Side Presentation Web Server JSP Servlet Server-Side Business Logic EJB Container EJB EJB Enterprise Information Systems

Tuning Servlet Performance: Load on Startup
• Increases application start-up time but decreases first-request latency for servlets • How?
• Add <load-on-startup> sub-element in http-website.xml to load the entire web module on startup • Add <load-on-startup> sub-element to the <servlet> element in web.xml to load the servlet on startup

Tuning JSP Performance: Pre-Translation
• Pre-compile JSPs into .class files ahead of time • In Oracle Application Server, ojspc provides this functionality
• jsp, and .java • Batch compilation of war, jar, ear and zip files
% ojspc -dir /myapp/mybindir -srcdir /myapp/mysrcdir MyPage.sqljsp MyPage2.jsp % ojspc -deleteSource myapp.war

Use HTTPSession Appropriately
• Minimize the objects you store in HTTPSession
• • Takes up memory Expensive serialization/deserialization if you use persistence/replication • Use transient variables to reduce serialization overhead

• Reduce default session timeout by using HttpSession.setM axInactiveInterval() • Remove session objects when no longer in use • Use <% @ page session="false"% > in JSP pages where you do not need a session

D E M O N S T R A T I O N

Web Tier

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

J2EE Application Tuning
Client Side Presentation Browser Pure HTML Java Applet Desktop Java Application Device J2EE Client J2EE Platform J2EE Platform JSP EJB Server-Side Presentation Web Server JSP Servlet Server-Side Business Logic EJB Container EJB EJB Enterprise Information Systems

Look for Bottlenecks with Load Testing Tools
• Mercury Loadrunner • Open source
• Apache JMeter • Grinder

• Altaworks Panorama • …

Threads – more aren’t necessarily better!
• The optimum number of threads required will probably vary based on application makeup and load • Reduction of thread contention is key
• Iterative process
• Don’t get discouraged!

More threads – more contention!
Transactions Per Second
300 250 200 150 100 50 0 2 4 8 16 32 64 Max Executor Pool Threads
50.00% 45.00% 40.00% 35.00% 30.00% 25.00% 20.00% 15.00% 10.00% 5.00% 0.00% 2 4 8 16 32 64 Max Executor Pool Threads Thread Group Lock Contention

Thread Group CPU 18.00% 16.00% 14.00% 12.00% 10.00% 8.00% 6.00% 4.00% 2.00% 0.00% 2 4 8 16 32 64 Max Executor Pool Threads

Thread Group Waiting 50.00% 45.00% 40.00% 35.00% 30.00% 25.00% 20.00% 15.00% 10.00% 5.00% 0.00% 2 4 8 16 32 64 Max Executor Pool Threads

Objects – be economical!
• Object creation is expensive
• Especially exceptions

• Assess whether unnecessary object creation is occurring

JVM Tuning
• A number of hotspot VM options are available for tuning
• -Xms, -Xmx, -Xmn, -XX:SuvivorRatio,…

• Some platform vendors provide additional options
• HP: -XX:+ForceMmapReserved

• Some platforms are not properly tuned out of the box for Java processing

Garbage Collection
• Change the JVM Heap size
• java –jar –Xms256m –Xmx256m oc4j.jar

• Monitor collection cycles
• verbose:gc • Profiling of heap
• • • • JDK 1.5 Jconsole Intel Vtune HPJtune ...

D E M O N S T R A T I O N

JVM Tuning

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

Sizing
• Sizing or Capacity Planning relates to either
• How many system resources are needed to accommodate users • How many users can be accommodated given a particular system

• Sizing in relation to Performance, Scalability, and Stress

Sizing and Scalability
•Scalability
•The ability of a system to expand, accommodating increased load with little or no effect on performance

Sizing Goals
• What are generally the goals leading to a sizing exercise? • Expected system throughput
• Operations per time interval (e.g., Hits/sec, Transactions/sec, Messages/sec)

• Total of concurrent users • Maximum response time • Application size

Sizing Methodology
• Decide on a test hardware configuration that can be scaled • Simulate sequence(s) of typical user actions
• Application specific • Time-of-day specific

• Apply varying load to the system
• Use an appropriate load generation software (e.g, Mercury LoadRunner, JMeter, etc.)

Sizing Methodology
• Scale hardware if needed to accommodate load • Stop when your defined criteria threshold is met
• Number of operations per time interval • Number of concurrent users • Maximum response time

• Iterate to optimize performance by tuning and adjusting the configuration parameters

Agenda
• • • • • • Background Approach J2EE Tier by Tier Tuning Scaling Monitoring

Performance Monitoring
• Optimization doesn’t end with deployment • Monitoring tools key to continued application responsiveness
• Oracle Enterprise Manager • HP OpenView

Oracle Enterprise Manager

Features: Grid Control
• • • • • • • • Application Server Discovery Application Server Home Page Out-of-box Monitoring Historical Collections & Analysis Consolidated Group Management J2EE Application Diagnostics Application Service Level Management Configuration Management

Application Server Home Page

Final Thoughts
• Do not optimize prematurely
• E.g. an object pool is not always faster

• Performance tuning is an iterative process • Do not add threads haphazardly • Exceptions are expensive

Next Steps
• Recommended Parallel Sessions • Simplify System Monitoring, Using Oracle Enterprise Manager 10g,
Monday @ 1:30 pm in Room 302 South @ 10:30 am in Room 308 South

• • •

Leveraging Advanced Features of Oracle Database in J2EE, Thursday

Related Demos/Exhibits
• Enterprise Manager, Toplink, and Oracle Container for J2EE (OC4J) pods located in Exhibit Hall http://www.oracle.com/technology/products/oem/as_mgmt/index.html

Related Web Sites For More Information

• •

http://downloadwest.oracle.com/docs/cd/B14099_11/core.1012/b14001/toc.htm http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html

Shameless Self Promotion
•From amazon.com reviews:
•“Required Enterprise Transactions Reading” •“All J2EE developers should read this book”

Q & A

QUESTIONS ANSWERS

Sign up to vote on this title
UsefulNot useful