1 / 42

Jonathan Maron Principal Product Manager Oracle Corporation

Jonathan Maron Principal Product Manager Oracle Corporation. Tuning J2EE Applications Tier by Tier. Agenda. Background Methodology J2EE Optimizations Performance Monitoring. Agenda. Background Methodology J2EE Optimizations Performance Monitoring. Performance Issues Abound!.

bonita
Télécharger la présentation

Jonathan Maron Principal Product Manager Oracle Corporation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jonathan MaronPrincipal Product Manager Oracle Corporation

  2. Tuning J2EE ApplicationsTier 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. Client SidePresentation Server-SideBusiness Logic Server-SidePresentation EJB Container Web Server Browser PureHTML EJB JSP JavaApplet Servlet EJB Desktop JavaApplication JSP EJB Device J2EEPlatform J2EEPlatform J2EEClient J2EE Application Complexity EnterpriseInformation Systems

  7. “Premature optimization is the root of all evil” - Professor Sir Charles Anthony Richard Hoare • “There are two rules for when to optimize: • Don't do it. • (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 Evaluate Design Test

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

  12. Don’t 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. Make connection,do Query Return resultand disconnect(unless application itself doesconnection pooling) No Connection Pooling J2EE Container RacingFacade • create • teamOrders • . . .

  16. Application usesavailable connections With Connection Pooling J2EE Container RacingFacade • create • teamOrders • . . . 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 Oracle9i 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. TopicSessionFacade • createTopicSet • printTopicSet • deleteTopicSet Topic • create • findBy • getTopicId • getTopicDesc • getTopicName • setTopicId • setTopicDesc • setTopicName Session Bean - Tx:NoneEntity Bean - Tx:Required System.out.println(“<Create Test>"); for(int i=0;i<3;i++) { TopicLocal topic = topicHome.create( new Integer(i),("topic " + i)); topic.setDesc("desc" + i); } System.out.println(“</Create Test>"); tx:None tx:Required

  22. Tx create Tx create Tx create Tx setDesc Tx setDesc Tx setDesc Resulting Transactional Activity <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

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

  24. 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 Same code: 6 lifecycle calls Tx : createTopic

  25. Take Advantage of Your EJB Container Configuration ExampleParameter Type Performance Characteristic Impacted call-timeout Session &Entity 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 re-try a transaction that was rolled back due to system level failures. max-tx-retries Session &Entity do-select-beforeinsert CMP 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. read-only CMP Multiple users can execute the entity bean in parallel. The container does not allow any updates to the bean's state. update-changedfield-only CMP Specifies whether the container updates only modified fields or all fields to when ejbStore is invoked. Default true. cache-timeout StatelessSession Specifies how long to keep stateless sessions cached in the pool.

  26. 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 inhttp-website.xmlto 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

  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 <%@ page session="false"%> 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. ... ... HTTPRequests ... Manage Application Server JVMs and Requests Per Application • Load balance across server instances OC4J Process 1 JVM OC4J Process 2 JVM OC4J Instance

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

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

  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. Performance Monitoring • Optimization doesn’t 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

More Related