J2EE Performance And Scalability Bp


Published on

A presentation on best practices for J2EE scalability from requirements gathering through to implementation, including design and architecture along the way.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

J2EE Performance And Scalability Bp

  1. 1. Best Practices For Performance and Scalability With J2EE Chris Adkin 16 th February 2009 Last update 5 th April 2009
  2. 2. Introduction <ul><li>There is a wealth of material on the internet and in the blogosphere on J2EE best practices for performance and scalability. </li></ul><ul><li>What follows are recommendations that mostly come from my own professional experience. </li></ul><ul><li>These will be broken down into three areas:- </li></ul><ul><ul><li>Requirements capture </li></ul></ul><ul><ul><li>Architecture </li></ul></ul><ul><ul><li>Design patterns </li></ul></ul><ul><ul><li>Design </li></ul></ul><ul><ul><li>Implementation </li></ul></ul>
  3. 3. Introduction <ul><li>The J2EE application server that I use is IBM WebSphere, hence the slight WebSphere flavour of the presentation. </li></ul><ul><li>Where WebSphere specific functionality has been mentioned, e.g. DynaCache, there will undoubtedly be something similar available with your own application server of choice. </li></ul>
  4. 4. Introduction <ul><li>Overlap </li></ul><ul><ul><li>There will be overlap in some parts of this presentation. </li></ul></ul><ul><ul><li>For example, if you bring most of the data closer to the business logic using a caching solution, this is an architectural decision. </li></ul></ul><ul><ul><li>If you only cache data relating to a specific piece of functionality on the application server, this is more of a design decision. </li></ul></ul><ul><ul><li>The same goes for StAX, i.e. you can use this to parse XML with or without the involvement of web services. </li></ul></ul>
  5. 5. Introduction <ul><li>SOA and Web Services </li></ul><ul><ul><li>Due to the popularity of SOA, this presentation includes web services best practices, but excludes REST on the grounds that:- </li></ul></ul><ul><ul><ul><li>REST is a convention rather than a standard and therefore cannot guarantee inter operability. </li></ul></ul></ul><ul><ul><ul><li>Cannot provide reliable messaging in the same way that WS* over JMS does. </li></ul></ul></ul><ul><ul><ul><li>Is not as secure as WS*. </li></ul></ul></ul><ul><ul><ul><li>May become similar to WS* if it ever facilitates attachments. </li></ul></ul></ul>
  6. 6. Feedback <ul><li>If you see this presentation on www.slideshare.net or my blog, all constructive feedback is welcome. </li></ul>
  7. 7. The Performance and Design Trade Off <ul><li>The fastest way to do anything is by using the shortest code path possible, however, this may undermine code:- </li></ul><ul><ul><li>maintainability </li></ul></ul><ul><ul><li>extensibility </li></ul></ul><ul><ul><li>Reusability </li></ul></ul><ul><li>However, producing the most elegant design possible may undermine performance and scalability. </li></ul><ul><li>Be pragmatic about achieving the most elegant design possible and the best performance and scalability possible simultaneously. </li></ul><ul><ul><li>Achieving both goals can require trade offs. </li></ul></ul>
  8. 8. “ Picking The Low Hanging Fruit” <ul><li>The final section focuses on performance features that can be used without any impact on the architecture, design or code. </li></ul><ul><li>The “low hanging fruit” to use tuning speak. </li></ul>
  9. 9. Requirements Capture
  10. 10. #1 Its Never Too Early To Think About Performance <ul><li>Capture performance requirements as early in the project life cycle as possible, preferably at use case level where applicable. </li></ul>
  11. 11. #2 Allow For Scalability In The Requirements <ul><li>Allow for software scalability, in terms of:- </li></ul><ul><ul><li>Transaction volume growth </li></ul></ul><ul><ul><li>User population growth </li></ul></ul><ul><ul><li>Data growth </li></ul></ul><ul><li>You want to avoid an application that performs adequately on day one of production and then deteriorates in performance from that point onwards. </li></ul>
  12. 12. #3 Specify Resource Utilisation In The None Functional Requirements <ul><li>Specify response, throughput and CPU utilisation when multiple batch processes and on-line usage is taking place at the same time, if applicable. </li></ul><ul><li>CPU utilisation at this early stage ?!? </li></ul><ul><ul><li>Yes, anyone can write code that abuses systems resources through things such as excessive remote method calls. </li></ul></ul><ul><ul><li>Or, anyone can write code that under utilises resources through locking on singleton resources etc. </li></ul></ul><ul><ul><li>What happens if multiple processes need to run in ‘catch-up’ scenarios, when a single process saturates CPU ?. </li></ul></ul><ul><li>Do what you can, this may be easier when a new application is being built to replace a legacy application. </li></ul>
  13. 13. #4 Specify The Target Environment For Performance Acceptance Testing Up Front <ul><li>Its no good if the developers test their code on a sixteen core machine, when the production server only has four cores !!!. </li></ul><ul><li>Specify the performance testing acceptance environment as tightly as possible in terms of:- </li></ul><ul><ul><li>Software versions: operating systems, application server and relational databases etc </li></ul></ul><ul><ul><li>Hardware </li></ul></ul><ul><ul><li>Topology </li></ul></ul><ul><ul><li>Data set </li></ul></ul><ul><ul><li>General configuration </li></ul></ul>
  14. 14. Architecture
  15. 15. What Is Architecture ? <ul><li>One of the most over loaded terms in the IT industry right now. </li></ul><ul><li>IEEE Standard 1471 defines this as:- “ Architecture : the fundamental organization of a system embodied in its components, their relationships to each other and to the environment and the principles guiding its design and evolution”. </li></ul><ul><li>Some people define this as the characteristics of a system that are “hard to change”. </li></ul>
  16. 16. What Is Design ? <ul><li>Design focuses on how to deliver the functionality required in order to satisfy use cases within the constraints of the architecture. </li></ul><ul><li>Carnegie Melon University’s Software Engineering Institute have produced some interesting essays on this:- </li></ul><ul><ul><li>Defining The Terms Architecture, Design and Implementation </li></ul></ul><ul><ul><li>What Is The Difference Between Architecture And Design? </li></ul></ul>
  17. 17. #1 Avoid Distributed Object Architectures <ul><li>This is Martin Fowler’s first law of distributed object architectures . </li></ul><ul><li>These are an anti-pattern to scalability, though the remote call overheads they incur, specifically around:- </li></ul><ul><ul><li>Network latency </li></ul></ul><ul><ul><li>Network round trips </li></ul></ul><ul><ul><li>Object serialisation </li></ul></ul><ul><li>Prefer “Shared nothing” architectures for scaling as per “Lessons learned from failed projects” in this article . </li></ul>
  18. 18. #1 Avoid Distributed Object Architectures <ul><li>Most application servers now have the ability for remote method calls between beans within the same container to be turned into local calls. </li></ul><ul><li>If the application is symmetrically deployed across a cluster with workload management and remote method call optimisation, this might not be a complete disaster. </li></ul><ul><li>However, do not waste your time:- </li></ul><ul><ul><li>Architecting a distributed object architecture </li></ul></ul><ul><ul><li>Architecting, designing and coding the service locator and business delegate ‘plumbing’ for such a solution. </li></ul></ul>
  19. 19. #1 Avoid Distributed Object Architectures <ul><li>This practice also applies to service oriented architectures, as per “Build a resilient SOA infrastructure” Parts 1 and 2 , from part 1:- “ Established best practices and lessons learned from related technologies provide strong guidance for building a resilient SOA. For example, from Java™ 2 Platform, Enterprise Edition (J2EE) technology, the collocation of dependant Enterprise JavaBeans (EJB) components on the same application server allows for optimizations like pass by reference as opposed to pass by value, and also reduces the consumption of server resources , specifically the use of one application server worker thread in one server compared to N threads across N servers. It follows analogously in the context of SOA that the collocation of tightly-coupled services should yield similar benefits as those observed in J2EE.” </li></ul>
  20. 20. #2 Be Aware Of The Performance Penalties That Tiers Incur <ul><li>Security conscious industries such as finance, prefer architectures subdivided into tiers, each of which goes into it’s own DMZ. </li></ul><ul><li>Tiers can have the same performance overheads as distributed object architectures. </li></ul><ul><li>Performance penalties might be acceptable when there is minimal chatter between tiers, but not tolerable for ‘chatty’ applications. </li></ul><ul><ul><li>E.g. batch processes </li></ul></ul><ul><li>‘ Chatty-ness’ refers to conversational traffic between tiers. </li></ul>
  21. 21. #3 Choose Clustering Solutions With “Prefer local resources” Optimisation <ul><li>The purpose of avoiding distributed object architectures and tiered architectures is to avoid performance death via pass by copy overheads. </li></ul><ul><li>On the same theme, prefer clustering solutions that will try to direct method calls to beans deployed to the same container as those which the method calls originated from. </li></ul>
  22. 22. #4 Iterative Development And Architecture Do Not Always Mix <ul><li>In recent times, iterative approaches to software development, agile etc, have become very popular. </li></ul><ul><li>The architecture should be “over arching”. </li></ul><ul><li>Developing the architecture iteratively can lead to problems. </li></ul><ul><li>May be Ok if you know from the outset where you are going with the architecture, or if the architecture is extremely simple and will remain so. </li></ul>
  23. 23. #5 Avoid Tightly Coupled Components <ul><li>“ Loosely coupled and highly cohesive” feature prominently in the vocabulary of most architects and designers. </li></ul><ul><li>Vertical and horizontal layers should always be loosely coupled. </li></ul><ul><li>I have seen projects where the same vertical layers are always invoked together. </li></ul><ul><ul><li>Avoid this in order to achieve performance gains through code path shortening and SQL statement consolidation. </li></ul></ul><ul><li>This is an obvious point, but one I consider well worth reiterating. </li></ul>
  24. 24. #6 Minimise Data Access Latency In The Architecture <ul><li>Minimise latency when accessing data by either:- </li></ul><ul><ul><li>Moving some of the business logic closer to the database, i.e. use PL/SQL or Java stored procedures in the database. </li></ul></ul><ul><ul><li>Move the data closer to the business logic, i.e. use caching and / or a grid style caching solutions. </li></ul></ul><ul><li>If the same data item is rarely used more than once during processing, move the processing closer to the database rather than using a caching solution. </li></ul>
  25. 25. #6 Minimise Data Access Latency In The Architecture <ul><li>Some caching solutions are code invasive and need to factored into the software at the architecture development stage. </li></ul><ul><li>There are caching products have APIs which minimise the impact of using the solution on the code, e.g.:- </li></ul><ul><ul><li>Gigaspaces have a JMS API </li></ul></ul><ul><ul><li>WebSphere eXtreme scale has hooks into the Java Persistence Architecture via annotations. </li></ul></ul><ul><li>Harnessing grid processing capabilities will probably require usage of custom APIs. </li></ul><ul><li>Check this out up front !!!. </li></ul>
  26. 26. #6 Minimise Data Access Latency In The Architecture <ul><li>There are generally two types of caching solution:- </li></ul><ul><ul><li>Object caches </li></ul></ul><ul><ul><li>Memory resident relational databases, e.g. Oracle TimesTen and IBM SolidDb. </li></ul></ul><ul><li>Choosing which one to use depends upon:- </li></ul><ul><ul><li>Whether your application is expecting objects or relational data. </li></ul></ul><ul><ul><li>Some solutions, e.g. memory resident relational databases are easier to retrofit with minimal code changes than other solutions. </li></ul></ul>
  27. 27. #7 Include Caching In The Architecture <ul><li>This point overlaps with the last one somewhat, but concerns more than just access to the core data. </li></ul><ul><li>The fastest way to do anything is not to do it at all. </li></ul><ul><li>In the context of a J2EE application server, cache results, objects, servlets, java server pages so as to minimise processing. </li></ul><ul><ul><li>WebSphere dynamic cache (DynaCache) facilitates the caching of all of these objects plus command classes and web services output. </li></ul></ul>
  28. 28. #7 Include Caching In The Architecture <ul><li>The layers of layered / tiered architectures 101:- </li></ul><ul><ul><li>Presentation </li></ul></ul><ul><ul><li>Service </li></ul></ul><ul><ul><li>Business Logic </li></ul></ul><ul><ul><li>Integration </li></ul></ul><ul><li>This basic model should also include a caching layer in an ideal world. </li></ul><ul><li>I have seen software where beans used to access standing data from a database were the most active in the application until caching was used, !!! AVOID THIS !!! . </li></ul>
  29. 29. Design Patterns
  30. 30. What Is A Design Pattern ? <ul><li>To quote the design patterns section of Sun’s blue prints for J2EE web site :- </li></ul><ul><li>“ A pattern describes a proven solution to a recurring design problem, placing particular emphasis on the context and forces surrounding the problem, and the consequences and impact of the solution”. </li></ul>
  31. 31. Why Use Design Patterns ? <ul><li>Again, from the design patterns section of Sun’s blueprints for J2EE:- </li></ul><ul><ul><li>“ They have been proven . Patterns reflect the experience, knowledge and insights of developers who have successfully used these patterns in their own work. </li></ul></ul><ul><ul><li>They are reusable . Patterns provide a ready-made solution that can be adapted to different problems as necessary. </li></ul></ul><ul><ul><li>They are expressive . Patterns provide a common vocabulary of solutions that can express large solutions succinctly” </li></ul></ul>
  32. 32. #1 Session Façade Pattern <ul><li>Use stateless session beans with coarse grained interface as the API to the business logic. </li></ul><ul><li>This will allow clients to be serviced with a minimal amount of network round trips and remote method calls. </li></ul><ul><li>A core J2EE design pattern as detailed here . </li></ul>
  33. 33. #2 Service Locator Pattern <ul><li>A core J2EE design pattern . </li></ul><ul><li>Allows calls to EJBs and JMS components to be encapsulated into one place. </li></ul><ul><li>This pattern lends itself to caching of EJB local and remote home interfaces, topics, queues, etc . . ., thus minimising JNDI lookups. </li></ul>
  34. 34. #3 Data Transfer Object Pattern <ul><li>This is a core J2EE design pattern as per this description . </li></ul><ul><li>Design the service layer API so that data can be passed to clients as serial-isable objects. </li></ul><ul><li>Helps to avoid multiple get method calls and performance loss due to network latency, round trips. </li></ul>
  35. 35. #4 Proxy Service Pattern <ul><li>Consider the proxy service pattern for ‘parallelising’ batch oriented work loads. </li></ul><ul><li>This essentially involves a ‘service’ that partitions the workload and then distributes it amongst worker threads or beans. </li></ul><ul><li>This is used to parallelise batch workloads with WebSphere Compute grid . </li></ul>
  36. 36. #5 The Business Delegate Pattern <ul><li>This de-couples the business logic from the presentation layer. </li></ul><ul><li>It also aims to minimise the number of network round trips between the presentation and business logic tiers. </li></ul><ul><li>Further details of this pattern can be found here . </li></ul>
  37. 37. Design
  38. 38. #1 Do Not Abuse The Database <ul><li>If using raw JDBC and SQL/J make the code bind friendly. </li></ul><ul><li>Use batching APIs where possible, e.g. the JDBC batching API. </li></ul><ul><li>Set the pre fetch size to minimise network round trips for result set retrieval. </li></ul><ul><li>Acquire connections and statement handles late and release them early. </li></ul><ul><li>Do not hammer the database with repeated calls for the same standing data, cache it in the application server. </li></ul>
  39. 39. #2 Respect The “ Holy Trinity Of Database Performance ” <ul><li>This is really a follow on from the last point, however, its importance means that it warrants a mention in it’s own right. </li></ul><ul><li>The “ Holy trinity ” consists of:- </li></ul><ul><ul><li>Connection management </li></ul></ul><ul><ul><li>Cursor management </li></ul></ul><ul><ul><li>‘ Good’ schema design </li></ul></ul>
  40. 40. #2 Respect The “ Holy Trinity Of Database Performance ” <ul><li>Connection management </li></ul><ul><ul><li>Always use JDBC connection pooling. </li></ul></ul><ul><ul><li>No matter what persistence method you use, you will usually end up using JDBC under the covers of your ORM somewhere. </li></ul></ul><ul><ul><li>Set the min and max connections on the pool to be the same. </li></ul></ul><ul><ul><ul><li>A rapid increase in the connection rate can cause a bad phenomenon called “Connection storms” . </li></ul></ul></ul><ul><ul><li>Acquire connection handles late and release them early. </li></ul></ul>
  41. 41. #2 Respect The “ Holy Trinity Of Database Performance ” <ul><li>Cursor management </li></ul><ul><ul><li>Make SQL statements bind friendly. </li></ul></ul><ul><ul><li>Try and reuse statement objects where possible:- </li></ul></ul><ul><ul><ul><li>Create a statement outside of a loop, bind to it and execute within the loop. </li></ul></ul></ul><ul><ul><li>Watch out for hard parses in the database and statements with large version counts. </li></ul></ul><ul><ul><li>For OLTP style applications, there should be few (if any) statements which have the same SQL text but more than one execution plan. </li></ul></ul>
  42. 42. #2 Respect The “ Holy Trinity Of Database Performance ” <ul><li>Good Schema Design </li></ul><ul><ul><li>Avoid tables with one to one relationships, such tables should be consolidated. </li></ul></ul><ul><ul><li>Balance normalisation against performance. </li></ul></ul><ul><ul><ul><li>Normalisation means the application only has to maintain the same data in the same place within the database. </li></ul></ul></ul><ul><ul><ul><li>However, some performance requirements may require some de-normalisation of the schema design. </li></ul></ul></ul><ul><ul><li>Consider the joins required by performance critical queries and the join paths the schema enforces in order for these queries to be executed. </li></ul></ul>
  43. 43. #3 Eliminate Bottlenecks, Don’t Replicate Them <ul><li>Only scale out after all reasonable design and coding efforts have been expended to achieve the desired levels of response time and / or throughput. </li></ul><ul><li>Eliminate bottlenecks, do not replicate them !!! </li></ul><ul><li>This rule is ‘borrowed’ from Designing and Coding For Scalability in WebSphere Application Server </li></ul>
  44. 44. #4 Make Logging Infrastructures Fine Grained <ul><li>Build flexibility into the way in which logging frameworks are used, such as log4j. </li></ul><ul><li>Avoid having to turn on debug logging across the entire application, by having the ability to increase the logging level around areas of interest. </li></ul><ul><li>The Java Utility Logging framework is less flexible than log4j, but allows logging levels to be specified at class level via the WebSphere administration console. </li></ul><ul><li>The Apache Commons logging framework allows different logging implementations to be easily swapped in and out of you application. </li></ul><ul><ul><li>Details of how to do this can be found here . </li></ul></ul>
  45. 45. #4 Make Logging Infrastructures Fine Grained <ul><li>Usually relational databases are I/O bound and J2EE application servers are CPU bound. </li></ul><ul><li>The rigid and none flexible use of logging frameworks can make your J2EE application I/O bound !!!. </li></ul>
  46. 46. #5 Carry Out Processing Closest To The Resource That Requires It <ul><li>If the application if data modification intensive, consider moving this type of processing closer to persistence layer (database):- </li></ul><ul><ul><li>Consider stored procedures. </li></ul></ul><ul><ul><li>Some databases allow for Java stored procedures, thus allowing the skills of the J2EE developers to be leveraged closer to the database. </li></ul></ul><ul><ul><li>For processing involving the validation of data against static rules, cache the data relating to the ‘rules’ and perform the validation in the application server. </li></ul></ul>
  47. 47. #6 Avoid ‘Chatty’ Designs <ul><li>When dealing with integration end points that require ‘Conversations’ and hand shakes, try to consolidate calls to such places in order to minimise ‘Chatter’. </li></ul><ul><li>Otherwise, you can end up spending more time on the network than in performing productive work. </li></ul><ul><li>Leverage features for ‘bundling’ calls to integration and persistence end points together. </li></ul>
  48. 48. #7 Do Not Reinvent The Wheel <ul><li>All J2EE application server vendors have gone to great lengths in honing the performance and scalability of their offering. </li></ul><ul><li>Use the fruits of these vendors efforts. </li></ul><ul><li>Replicating functionality in the application server, is unlikely to result in the same ‘performant’ results achieved using vendor provided functionality. </li></ul>
  49. 49. #8 Be Pragmatic Before Designing For Database Independence <ul><li>Ask how likely it is that your software will need to support databases from different vendors:- </li></ul><ul><ul><li>Likely if you are producing and selling software. </li></ul></ul><ul><ul><li>Less likely if the software is for an ‘in-house’ project. </li></ul></ul><ul><li>There are great performance features in each vendors database offering, the benefits of which will never be realised with the “Take advantage of nothing” approach. </li></ul><ul><ul><li>The Oracle JDBC array interface is but one example of this. </li></ul></ul><ul><li>If you need to use vendor specific features, encapsulate the use of these into as few places in the design and code as possible. </li></ul>
  50. 50. #9 Be Pragmatic Before Designing For Application Server Independence <ul><li>The whole ethos behind Java and J2EE is write once and then run anywhere !?!? </li></ul><ul><li>However, consider:- </li></ul><ul><ul><li>Scripting, administration tools and the application server management infrastructure may be vendor specific. </li></ul></ul><ul><ul><li>Do not go outside the J2EE specification on a whim, however, using vendor specific performance features can save considerable time and money. </li></ul></ul><ul><ul><li>In reality, how likely are you to deploy your code to different vendors application servers ?. </li></ul></ul>
  51. 51. #10 Make Designs Cluster Friendly <ul><li>Leverage cluster friendly features such as the distributed map in WebSphere. </li></ul><ul><li>Prefer designs that allow workloads to distributed amongst cluster nodes. </li></ul><ul><ul><li>i.e. in the case of WebSphere network deployment, allow workloads to be distributed via the workload manager. </li></ul></ul><ul><li>Avoid designs where multiple beans contend for the singleton resources. </li></ul><ul><li>Prefer stateless session beans to state-full session beans as calls to stateless beans can be load balanced across a cluster. </li></ul><ul><ul><li>!!! Not all J2EE resources can be shared across a cluster, e.g. timer beans and file resources. !!! </li></ul></ul>
  52. 52. #11 Seriously Consider JPA For Your ORM Requirements <ul><li>Due to short comings with entity beans, many object relational mapping tools and frameworks have emerged, the most popular of which is hibernate. </li></ul><ul><li>These short comings have been addressed in JEE5 (EJB 3.0) with the Java Persistence Architecture. </li></ul><ul><li>Many vendors have put a great deal of effort into honing the performance of JPA, e.g.: EJB 3.0 Performance Improvements in WAS v7.0 . </li></ul><ul><ul><li>Therefore, give serious consideration to JPA for your ORM requirements. </li></ul></ul><ul><li>If you need to take advantage of performance features such as the Oracle array interface, there is absolutely no reason why you cannot mix raw JDBC with JPA. </li></ul>
  53. 53. #11 Seriously Consider JPA For Your ORM Requirements <ul><li>JPA includes the following performance features:- </li></ul><ul><ul><li>A caching framework </li></ul></ul><ul><ul><li>SQL statement batching </li></ul></ul><ul><ul><li>Ability to write queries in conventional SQL </li></ul></ul><ul><ul><li>ObjectGrid integration by additional annotations </li></ul></ul><ul><ul><ul><li>However, you will not get the grid processing capabilities of ObjectGrid by doing this. </li></ul></ul></ul><ul><ul><li>DB2 static SQL access support </li></ul></ul><ul><li>Hibernate entity provides a JPA API, as this requires a JEE 5 application server, it is not clear why you would not want to use native JPA with JEE5. </li></ul>
  54. 54. #11 Seriously Consider JPA For Your ORM Requirements <ul><li>JPA is part of the JEE standard, it is therefore likely to be subject to more performance honing by J2EE application server vendors than hibernate. </li></ul><ul><li>In the context of Oracle the only practical benefit in using raw JDBC over JPA is the ability to use the Oracle array interface . </li></ul><ul><li>Refer to the WebSphere and Java Persistence blog for more information on WebSphere and JPA. </li></ul>
  55. 55. #12 Prefer JMS Over RMI For Mass Asynchronous Style Communication <ul><li>When using remote devices or sites to communicate with a central J2EE application server, prefer JMS over RMI, especially if the communication style is asynchronous. </li></ul><ul><li>RMI requires a separate Java thread per connection and therefore has inherent scalability limits built in. </li></ul><ul><li>If a send and retry mechanism needs to be written using RMI, this is unlikely to be as scalable or as robust as what is available out of the box with JMS. </li></ul>
  56. 56. #13 Use The Most Appropriate XML Parsing API <ul><li>StAX ( ST reaming A PI for X ML) came about to address short comings with SAX ( S imple A PI for X ML) and DOM ( D omain O bject M odel). </li></ul><ul><li>DOM reads entire XML documents into memory and parses them into a tree. </li></ul><ul><ul><li>May give acceptable performance for simple documents the entire contents of which are required by the program. </li></ul></ul><ul><li>StAX, a streaming pull parser has:- </li></ul><ul><ul><li>lower memory requirements than DOM both in terms of smaller libraries and not having to read entire XML documents at a time. </li></ul></ul><ul><ul><li>Allows multiple documents to be read using a single application thread. </li></ul></ul><ul><ul><li>You only parse what you require from the document, i.e. no overhead in parsing XML that you might never use. </li></ul></ul><ul><li>Refer to this article from Sun for more information on StAX versus DOM. </li></ul>
  57. 57. #14 Use The Most Efficient Web Services Engine Available <ul><li>The overheads in parsing XML and marshalling objects to XML (and back) can be significant. </li></ul><ul><li>The two most popular ways for ‘rendering’ web services are to use Apache Axis or the native application server platform. </li></ul><ul><li>Use the method that gives you the greatest performance. </li></ul><ul><li>For example, massive strides have been made in improving web services performance in WebSphere 7.0 which go beyond the addressing of marshalling overheads. </li></ul><ul><ul><li>Refer to this article . </li></ul></ul>
  58. 58. #15 Prefer JAX-WS Over JAX-RPC <ul><li>JAX-WS implementations are generally faster than their JAX-RPC counterparts, this is due in part to JAX-WS using StAX. </li></ul><ul><li>Refer to this Sun article for further information on JAX-WS versus JAX-RPC performance. </li></ul>
  59. 59. #16 Use Coarse Grained Interfaces For Web Services <ul><li>Use coarse grained interfaces for web services, this will result in:- </li></ul><ul><ul><li>Improved web service reusability. </li></ul></ul><ul><ul><li>Web services requests can be satisfied in fewer requests by the consumer, hence less network usage, round trips etc . . . </li></ul></ul>
  60. 60. #17 Avoid Sparse SOAP Documents <ul><li>Avoid documents that are ‘Sparse’, i.e. complex in structure and low in data content. </li></ul><ul><li>Such documents will involve a high parsing overhead with little benefit in terms meaningful data extraction. </li></ul>
  61. 61. #18 Be Mindful Of The Performance Overheads Of WS-Security <ul><li>From “Best Practices For Web Services: Part 9” :- </li></ul><ul><li>“ It's probably safe to say that enabling security through WS-Security technologies is at least twice the cost of proving similar capabilities using traditional SSL with HTTP” </li></ul>
  62. 62. Implementation
  63. 63. #1 Leverage None Code Intrusive Application Server Performance Features <ul><li>Leverage application server performance features that require no code changes. </li></ul><ul><li>In WebSphere some of these include:- </li></ul><ul><ul><li>Object Request Broker pass by reference. </li></ul></ul><ul><ul><li>The cache servlets ‘switch’ on the web container. </li></ul></ul><ul><ul><li>DynaCache. </li></ul></ul>
  64. 64. #2 Take Advantage Of The Oracle Client Side Cache <ul><li>Oracle 11g introduces a client side result cache. </li></ul><ul><li>This requires the thick JDBC driver. </li></ul><ul><li>Result sets are cached on the application server host transparently to the application. </li></ul><ul><li>On a benchmark performed by an Oracle , this results in:- </li></ul><ul><ul><ul><li>Up to 6.5 times less CPU usage on the database server host </li></ul></ul></ul><ul><ul><ul><li>15-22% response time improvement </li></ul></ul></ul><ul><ul><ul><li>7% improvement in mid tier CPU usage </li></ul></ul></ul><ul><li>The client result cache is detailed in the Oracle document here . </li></ul>
  65. 65. #3 Always Use The Latest Version Of The Apache Xerces XML Parser <ul><li>When using the Apache Xerces XML parser, use the latest version available for the best possible performance. </li></ul>
  66. 66. Useful Resources <ul><li>Design and architecture resources </li></ul><ul><ul><li>Carnegie Melon SEI Essays On Software Architecture </li></ul></ul><ul><ul><li>Sun BluePrints > J2EE Design Patterns </li></ul></ul><ul><ul><li>“Errant Architectures” by Martin Fowler </li></ul></ul><ul><ul><li>Martin Fowler’s ‘ bliki ’ </li></ul></ul>
  67. 67. Useful Resources <ul><li>IBM resources </li></ul><ul><ul><li>Designing and Coding Applications For Performance and Scalability in WebSphere Application Server </li></ul></ul><ul><ul><li>WebSphere Application Server Best Practices for Performance and Scalability </li></ul></ul><ul><ul><li>WebSphere Community Blog </li></ul></ul><ul><ul><li>Developerworks Best Practices For Web Services Part 9 </li></ul></ul><ul><ul><li>Developerworks Best Practices For Web Services Part 10 </li></ul></ul>
  68. 68. Useful Resources <ul><li>IBM resources </li></ul><ul><ul><li>WebSphere Compute grid </li></ul></ul><ul><ul><li>WebSphere Dynamic Cache: Improving J2EE Application Performance </li></ul></ul><ul><ul><li>Using logging and tracing in Websphere Commerce custom code </li></ul></ul><ul><ul><li>WebSphere Network Deployment DistributedMap </li></ul></ul><ul><ul><li>EJB 3.0 Performance Improvements In WAS 7.0 </li></ul></ul><ul><ul><li>Web Service Improvements in WAS 7.0 </li></ul></ul>
  69. 69. Useful Resources <ul><li>IBM resources </li></ul><ul><ul><li>WebSphere Persistence Blog </li></ul></ul><ul><ul><li>Build a resilient SOA infrastructure, Part 1: Why blocking application server threads can lead to brittle SOA </li></ul></ul><ul><ul><li>Build a resilient SOA infrastructure, Part 2: Short-term solutions for issues involving tightly coupled SOA components </li></ul></ul>
  70. 70. Useful Resources <ul><li>Sun Resources </li></ul><ul><ul><li>Scaling Your J2EE Applications Part 1 </li></ul></ul><ul><ul><li>Scaling Your J2EE Applications Part 2 </li></ul></ul><ul><ul><li>Java Tuning White Paper </li></ul></ul><ul><ul><li>J2SE and J2EE Performance Best Practices, Tips And Techniques </li></ul></ul><ul><ul><li>Why StAX ? </li></ul></ul><ul><ul><li>Implementing High Performance Web Services Using JAX-WS 2.0 </li></ul></ul>
  71. 71. Useful Resources <ul><li>Oracle Resources </li></ul><ul><ul><li>Upscaling Your Database Application Performance: The Array Interface </li></ul></ul><ul><ul><li>360 Degree Blog Post On The Client Results Cache </li></ul></ul><ul><ul><li>Oracle Documentation On Using The 11g Client Results Cache </li></ul></ul>