Professional Documents
Culture Documents
”
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!
2004 Forrester
• 66% of time developers find out about performance
problems from user calls!
J2EE Application Complexity
Client Side Server-Side Server-Side Enterprise
Presentation Presentation Business Logic Information Systems
Web EJB
Browser
Server Container
Pure
HTML JSP EJB
Java
Applet Servlet EJB
Desktop
Java
JSP EJB
Application
Device
J2EE J2EE J2EE
Platform Platform
Client
“Premature optimization is the
root of all evil”
- Professor Sir Charles Anthony
Richard Hoare
• Background
• Approach
• J2EE Tier by Tier
• Tuning
• Scaling
• Monitoring
Methodical approach to
performance evaluation
Develop
Evaluate Identify
Test Design
Know your application
Applications
Application Server
Database
• Background
• Approach
• J2EE Tier by Tier
• Tuning
• Scaling
• Monitoring
J2EE Application Tuning
Client Side Server-Side Server-Side Enterprise
Presentation Presentation Business Logic Information Systems
Web EJB
Browser
Server Container
Pure
HTML JSP EJB
Java
Applet Servlet EJB
Desktop
Java
JSP EJB
Application
Device
J2EE J2EE J2EE
Platform Platform
Client
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
Application uses
available connections
RacingFacade
Connection Pooling
From the Container
• create
• teamOrders
•...
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
List PhoneNumber
Tune Your SQL!
JDBC
Performance
J2EE Application Tuning
Client Side Server-Side Server-Side Enterprise
Presentation Presentation Business Logic Information Systems
Web EJB
Browser
Server Container
Pure
HTML JSP EJB
Java
Applet Servlet EJB
Desktop
Java
JSP EJB
Application
Device
J2EE J2EE J2EE
Platform Platform
Client
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
•create
•findBy
System.out.println(“<Create Test>");
•createTopicSetfor(int i=0;i<3;i++) •getTopicId
{ •getTopicDesc
•printTopicSet TopicLocal topic = •getTopicName
•deleteTopicSet topicHome.create( •setTopicId
new Integer(i),("topic " + i));
topic.setDesc("desc" + i); •setTopicDesc
} •setTopicName
System.out.println(“</Create Test>");
tx:None tx:Required
Resulting Transactional Activity
<Create Test>
Tx create TopicBean: ejbCreate id = 0
TopicBean: ejbStore id = 0
TopicBean: ejbLoad id = 0
Tx setDesc
TopicBean: ejbStore id = 0
Tx create TopicBean: ejbCreate id = 1
TopicBean: ejbStore id = 1 Requires:
TopicBean: ejbLoad id = 1 12 lifecycle
Tx setDesc
TopicBean: ejbStore id = 1 calls
TopicBean: ejbCreate id = 2
Tx create
TopicBean: ejbStore id = 2
TopicBean: ejbLoad id = 2
Tx setDesc TopicBean: ejbStore id = 2
</Create Test>
Session Bean - Tx:Required
Entity Bean - Tx:Required
TopicSessionFacade Topic
•create
•findBy
System.out.println(“<Create Test>");
•createTopicSetfor(int i=0;i<3;i++) •getTopicId
{ •getTopicDesc
•printTopicSet TopicLocal topic = •getTopicName
•deleteTopicSet topicHome.create( •setTopicId
new Integer(i),("topic " + i));
topic.setDesc("desc" + i); •setTopicDesc
} •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 Same code:
Tx : createTopic </Create Test 6 lifecycle
TopicBean: ejbStore id = 0 calls
TopicBean: ejbStore id = 1
TopicBean: ejbStore id = 2
Take Advantage of Your EJB
Container Configuration
Example Type Performance Characteristic Impacted
Parameter
call- Session & Specifies the maximum time to wait for any resource that the EJB container
timeout Entity needs before the container calls the EJB method (excluding DB).
max-tx- Session & Specifies the number of times to retry a transaction that was rolled back due
retries Entity to system level failures.
do-select- CMP Set to false to avoid the extra select before insert (checks if entity already
before-insert exists before doing the insert). Detects a duplicate during insert.
update- CMP Specifies whether the container updates only modified fields or all fields
changed- when ejbStore is invoked. Default true.
fields-only
pool-cache- Stateless Specifies how long to keep stateless sessions cached in the pool.
timeout Session
D E M O N S T R A T I O N
EJB Tuning
J2EE Application Tuning
Client Side Server-Side Server-Side Enterprise
Presentation Presentation Business Logic Information Systems
Web EJB
Browser
Server Container
Pure
HTML JSP EJB
Java
Applet Servlet EJB
Desktop
Java
JSP EJB
Application
Device
J2EE J2EE J2EE
Platform Platform
Client
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 Server-Side Server-Side Enterprise
Presentation Presentation Business Logic Information Systems
Web EJB
Browser
Server Container
Pure
HTML JSP EJB
Java
Applet Servlet EJB
Desktop
Java
JSP EJB
Application
Device
J2EE J2EE J2EE
Client Platform Platform
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 Thread Group Lock Contention
300 50.00%
45.00%
250 40.00%
35.00%
200
30.00%
150 25.00%
20.00%
100 15.00%
10.00%
50
5.00%
0 0.00%
2 4 8 16 32 64 2 4 8 16 32 64
18.00% 50.00%
16.00% 45.00%
14.00% 40.00%
35.00%
12.00%
30.00%
10.00%
25.00%
8.00% 20.00%
6.00% 15.00%
4.00% 10.00%
2.00% 5.00%
0.00% 0.00%
2 4 8 16 32 64 2 4 8 16 32 64
JVM Tuning
Agenda
• Background
• Approach
• J2EE Tier by Tier
• Tuning
• Scaling
• Monitoring
Sizing
•Scalability
•The ability of a system to
expand, accommodating
increased load with little
or no effect on
performance
Sizing Goals
• Background
• Approach
• J2EE Tier by Tier
• Tuning
• Scaling
• Monitoring
Performance Monitoring
•From amazon.com
reviews:
•“Required Enterprise
Transactions Reading”
•“All J2EE developers
should read this book”
Q&
A
QUESTIONS
ANSWERS