Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jonathan Maron Principal Product Manager Oracle Corporation.

Similar presentations


Presentation on theme: "Jonathan Maron Principal Product Manager Oracle Corporation."— Presentation transcript:

1 Jonathan Maron Principal Product Manager Oracle Corporation

2 Tuning J2EE Applications Tier by Tier

3 Agenda Background Methodology J2EE Optimizations Performance Monitoring

4 Agenda Background Methodology J2EE Optimizations Performance Monitoring

5 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!

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

7 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. 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

8 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

9 Agenda Background Methodology J2EE Optimizations Performance Monitoring

10 Methodical approach to performance evaluation Develop Identify Design Test Evaluate

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

12 Dont Forget That There are Tools to Help Profilers Debuggers Code audits and metrics Load testing tools Vendor performance and configuration guidelines

13 Agenda Background Methodology J2EE Optimizations Performance Monitoring

14 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

15 No Connection Pooling RacingFacade J2EE Container create teamOrders... Make connection, do Query Return result and disconnect (unless application itself does connection pooling)

16 With Connection Pooling RacingFacade J2EE Container create teamOrders... Application uses available connections Connection Pooling From the Container

17 Tune Your SQL! Easier said than done – What is the real SQL running in CMP EJB? Look at the SQL on the wire – Tools like P6Spy, Oracle Enterprise Manager Become good friends with your DBA – Tune using traditional techniques Explain plan Tools like SQLPlus and Oracle9 i JDeveloper

18 D E M O N S T R A T I O N JDBC Performance

19 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

20 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

21 Session Bean - Tx:None Entity Bean - Tx:Required TopicSessionFacade createTopicSet printTopicSet deleteTopicSet Topic create findBy getTopicId getTopicDesc getTopicName setTopicId setTopicDesc setTopicName tx:Nonetx:Required System.out.println( "); for(int i=0;i<3;i++) { TopicLocal topic = topicHome.create( new Integer(i),("topic " + i)); topic.setDesc("desc" + i); } System.out.println( ");

22 Resulting Transactional Activity 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 Tx create Tx setDesc Tx create Tx setDesc Tx create Tx setDesc Requires: 12 lifecycle calls

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

24 Resulting Transactional Activity TopicBean: ejbCreate id = 0 TopicBean: ejbCreate id = 1 TopicBean: ejbCreate id = 2

25 Take Advantage of Your EJB Container Configuration Specifies how long to keep stateless sessions cached in the pool.Stateless Session cache- timeout Specifies whether the container updates only modified fields or all fields to when ejbStore is invoked. Default true. CMP update- changedfield -only Multiple users can execute the entity bean in parallel. The container does not allow any updates to the bean's state. CMP read-only Recommend setting to false to avoid the extra select before insert which checks if the entity already exists before doing the insert. This will then detect a duplicate, if there is one, during the insert. CMP do-select- beforeinsert max-tx- retries Specifies the maximum time to wait for any resource that the EJB container needs before the container calls the EJB method (excluding DB). Session & Entity call- timeout Performance Characteristic ImpactedTypeExample Parameter Session & Entity Specifies the number of times to re-try a transaction that was rolled back due to system level failures.

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

27 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

28 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.setMaxInactiveInterval() Remove session objects when no longer in use Use in JSP pages where you do not need a session

29 Look for Bottlenecks with Load Testing Tools Mercury Loadrunner Open source – Apache JMeter – Grinder Altaworks Panorama …

30 Scalability under varying load

31 Manage Application Server JVMs and Requests Per Application Load balance across server instances OC4J Process 2 JVM OC4J Process 1 JVM OC4J Instance HTTP Requests......

32 D E M O N S T R A T I O N Apache JMeter

33 Threads – more arent 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 Dont get discouraged!

34 More threads – more contention!

35 Objects – be economical! Object creation is expensive – Especially exceptions Assess whether unnecessary object creation is occurring

36 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

37 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...

38 Agenda Background Methodology J2EE Optimizations Performance Monitoring

39 Optimization doesnt end with deployment Monitoring tools key to continued application responsiveness – Oracle Enterprise Manager – HP OpenView –...

40 Oracle Enterprise Manager

41 Final Thoughts Performance tuning is an iterative process An object pool is not always faster Do not add threads haphazardly Exceptions are expensive

42 Shameless Self Promotion


Download ppt "Jonathan Maron Principal Product Manager Oracle Corporation."

Similar presentations


Ads by Google