Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Diagnosing Application-Database Performance Bottlenecks

Diagnosing Application-Database Performance Bottlenecks

The Rise of J2EE
J2EE has arrived as the standard enterprise-computing platform for Web application development, and is gaining strength and popularity every day. J2EE supports legacy applications and interfaces, multiple operating systems, distributed and clustered environments, and high-volume mission-critical applications with support for security and managed operations.

By providing a framework and blueprint for developing distributed, scalable applications, J2EE allows companies and their developers to focus on writing modular pieces of custom application code and forget about the underlying details of security, resource management, and scalability.

Industry-leading application servers, such as BEA WebLogic Server, provide a great number of features and services. Reliability, availability, and scalability are provided by the clustering and fail-over features of multiple WebLogic Server instances. Other services like security and resource management - such as execute thread pools, EJB caches, and JDBC pools - are also provided. Third parties write Java Database Connectivity (JDBC) drivers to further abstract and simplify the coding of data access across different database management systems (DBMS).

The result is a powerful platform that greatly simplifies and abstracts the low-level details of developing distributed, high-volume enterprise applications.

The Challenge of J2EE Performance
Sounds like nothing can go wrong, right? Nothing, until the application fails to meet the performance criteria demanded by end users or service-level agreements. Success of a development project and business initiative can hinge on the ability to detect, diagnose, and resolve these performance problems quickly.

Due to their increased complexity, performance bottlenecks in these multi-tiered, distributed J2EE applications are much more difficult to diagnose than in earlier monolithic application environments. J2EE environments contain multiple interconnected layers of software and hardware components that all interact to service any given end-user request. Performance team members - the architect, developer, app server administrator, and database guru - have their own view of the system, and potentially their own silo or "device-centric" diagnosis tool. But how does this team work together to isolate problems? Without comprehensive visibility into all components in a J2EE system and their interactions with one another, how is a performance expert to figure out which server is slow? Which component is slow? Which resources are scarce? Is the database engine the primary bottleneck, or just a minor contributing factor?

The challenge can be daunting for the unprepared or ill equipped. Confusion can leave team members scratching their heads, or worse, pointing their fingers.

"Is It the Application, or Is It the Database?"
One of the most common frustrations heard from companies that are facing underperforming distributed J2EE applications is "Is it the application, or is it the database? Where do we start trying to fix this?" All too often, someone hazards a guess and ends up searching through reams of code looking for incorrect or inefficient algorithms, or combing through SQL statements and database tables. In other words, they pick either the application or the database (or in the worst case, both) and try to optimize that isolated piece of the puzzle.

Unfortunately, this view of problem solving is often overly simplistic as neither the application, nor the database, nor the WebLogic Server, operate in isolation. A comprehensive approach to solving this problem requires gaining visibility into all three pieces of this interrelated system: WebLogic resource utilization and configuration, the application architecture, and the database query execution, as well as underlying hardware infrastructure performance.

With insight into these subsystem interactions, performance team members can effectively isolate problematic components and triage the problem to the correct functional expert for repair.

Visibility into Interrelationships is Key
Visibility and interrelationships are the two key words here. Without both of these, detection and root cause diagnosis are extremely difficult.

We need visibility into the runtime JMX performance metrics of the WebLogic Server. We need visibility into the timing and structures of SQL queries and stored procedures run by the database engine. And most important, we need visibility into the end-to-end timing of the end-user requests across the distributed system, with all component interactions with the JDBC connection pools and DBMS calls explicitly mapped out on a per request basis.

Visibility is needed into not just method-level timings of the application, but into the way in which each component interacts with another to form the application architecture. Isolated metrics of method and JDBC timings without context to the application architecture, which are provided by most J2EE performance monitoring tools, are nearly useless. So are isolated response times of SQL statement execution, without regards to where the statement originated, how many times it was called, or what other interactions with the database its end-user request made.

The ideal tool solution provides insight into how the custom J2EE application interacts with the WebLogic server resources and DBMS, and how these interactions contribute to the overall response time of each end-user transaction. A high-level representation of these interactions is outlined in Figure 1.

Typical Application-Database Performance Bottlenecks
By now you're probably thinking, "Enough of the theory, how do I fix my application?" The following sections will discuss three main classes of performance bottlenecks, distilled from measuring and analyzing the performance of dozens of real-world J2EE applications, including J2EE systems of several prominent financial, telecommunications, and manufacturing Fortune 100 companies. By no means is this meant to be an exhaustive list, or a "debugging checklist" that can be followed step-by-step to tune any application. Each J2EE application, due to its distributed nature and complicated architecture, will have its own unique performance characteristics, but here are some common pitfalls to avoid.

I'll look at the three classes of application-database performance, with specific examples gathered by running the BEA PetStore sample application, and performance data collected and analyzed with Quest Software's PerformaSure.

Excessive Database Calls

  • "Client"-side data processing and ResultSet scrolling
    By far the most serious performance bottlenecks in J2EE-database applications come from excessive calls being made from the user application to the database engine. These unnecessary extra calls do not necessarily have to be the Execute() or Update() of SQL queries, but nearly always involve other interactions with the database, such as ResultSet operations. A common mistake is to specify too narrow a query, and then scroll through the returned data one row at a time using ResultSet.Next(). This leaves the performance of the application at the mercy of the dataset within the DBMS - for large table sizes, this scrolling can be massive; I have seen data at client sites where over 50,000 calls were made to ResultSet.Next() for each SQL query executed.

    If some data processing must be done within the application code, consider fetching the required data in bulk from the DBMS, to avoid the application having to call back to the database repeatedly to retrieve each row in the dataset.

    Example 1: Excessive ResultSet Scrolling
    Figure 2 shows the PerformaSure reconstruction of "commitorder" HTTP request within the PetStore application, as the request executes servlet, JSP, and EJB code, eventually calling a SQL statement in the DBMS. The color-coded scale on the right-hand side indicates which methods executed quickly (cool blue), as well as the expensive hotspot methods (hot red). The tooltip at the right provides the overall timing and call count of the request. Clearly the database node at right is a hot spot, and needs further investigation.

    By zooming into the hot spot identified, we can see a detailed timing and call count breakdown of all JDBC operations that were executed by this transaction, such as the opening of a JDBC connection, the creation and execution of a "SELECT" SQL statement, the ResultSet.Next() scrolling, and finally, the closing of the connection. The EJB method "GetItem" was called 7 times (corresponding to the seven commitorder HTTP requests), executed a fast running SQL statement 7 times, and then scrolled through the ResultSet 672 times. This excessive chatter with the DBMS took more time than executing the actual query! This is not a scalable architecture - as the dataset grows in the DBMS and more concurrent end- users execute transactions, this type of performance problem only worsens.

  • Two queries instead of one
    Another rule of thumb is to leave the design of SQL queries and updates to the database expert, who is intimately familiar with the various table schemas and indexes. Too often the developer writing an EJB has an idea of what data he or she would like to pull from the database engine, or the update needed. The difficulty lies in writing the fewest and most efficient queries and updates needed to perform the task. Learning to select only the data you really need in the application is crucial. It reduces the amount of processing the RDMS must perform as well as minimizing the number of queries and data sent across the network.

    Any set-based processing is implemented most efficiently by the DBMS rather than pulled over the network and performed within application logic in the EJB layer of WebLogic Server. While the EJB layer exists to hold the "business logic" that encapsulates the rules and conditions for which the application queries and updates data, the actual implementation details are best handled by the database engine. Low-level query-processing logic, such as selecting initial data into temporary tables and making further queries based upon that data, is best handled by the DBMS, in stored procedures.

    Database Connection Pool Problems (JBDC)

  • Connection Pool Leaks
    A connection pool "leak" occurs when a component (usually an EJB) within a user application requests a connection from a pool, queries or updates some data, and then fails to release the connection. While it is simple to detect that a connection pool has quickly reached its maximum by examining the WebLogic JMX performance metrics ("Connections" and "Waiters") and observing slow DataSource.GetConnection() response times, it is difficult to pinpoint the source of the leak within the application code itself. This becomes even more difficult if multiple end user requests, and hence multiple pieces of application code, allocate connections from the same JDBC pool. Which request isn't freeing connections?

    To solve this, a tool is needed that explicitly maps the application's interaction with the data source on a per request basis. The example below shows the "CommitOrder" HTTP request from PetStore allocating and freeing the connections to the data source

    Example 2: Connection Pool Leak
    Figure 4 shows two telltale WebLogic JDBC metrics that can indicate a connection pool leak. The first graph shows the number of connections in the pool quickly increasing to 400, the maximum size of the pool. At the same time that this maximum is reached, the number of waiters (requests waiting for a free connection) increases consistently, hinting that a connection leak may be occurring. But where in the source code is this happening?

    Figure 5 shows the "product" request and identifies two separate pieces of application code within the request that allocate and release JDBC pool connections. A quick pan and zoom into these areas provide details of how the connection pool is being used.

    In the second area we identified in Figure 5, we can immediately verify the source of our performance problem. The EJB calls GetProduct() a total of 804 times in this time period, resulting in 804 calls to executeQuery() (tooltip not shown). Checking the counts of the getConnection() and Connection.close() shows that while 1,012 JDBC connections were requested, only 756 were freed. Confirmation that this is causing performance degradation is evident by the red coloration and timing information for the GetConnection() call. It is important to note that while connection leaks are easy to detect with metric data, the root cause of these leaks is difficult, if not impossible, to pinpoint in the code if multiple transactions, or multiple pieces of code within a transaction, all allocate connections from the same JDBC pool.

  • Size of JDBC Connection Pool
    A good rule of thumb is to take the size of the execute thread pool size, multiply it by the average number of concurrent database connections that each end-user transaction (thread) utilizes, and add 10% for peak periods of load. This average number of connections per transaction is usually one, making the JDBC connection pool and the execute queue the same size notwithstanding any desired peak load buffer. This pool size can be iteratively tuned by running tests with large JDBC pools and observing the average and peak values of JDBC pool utilized for any given execute queue size. The timing of calls to Database.GetConnection() should also be monitored to ensure there is no significant waiting time for JDBC resources.

    A second point to remember when using JDBC pools in production systems is to always set the initial pool size equal to maximum pool size. By doing this, the performance overhead of creating all items in the pool occurs during the WebLogic Server startup, and not during end user runtime.

    Incorrectly Formed Database Queries

  • Poorly formed SQL statements or stored procedures
    This common problem is related to the "two queries instead of one" performance bottleneck discussed earlier. In this case, a single SQL statement or stored procedure is called only once (or the appropriate number of times) per end-user request, yet still takes a significant amount of time to execute. Luckily, long-running statements are easy to detect with advanced performance tools, and as long as it has been confirmed that the application is efficiently interacting with the database, the database administrator can be called in to tune the offending SQL statement or stored procedure.

    The key is having a tool that allows a single user to rule out the application design as a problem by breaking down the various JDBC operations that are performed for each statement with exclusive timing information and call counts. Then the problem can be triaged to the DBA for further drilldown into table schemas, indexes, and locking using his or her silo DBMS performance tools.

    Another performance problem with database operations is exceptions thrown during the execution of stored procedures or the failure of completing database transactions resulting in Rollback() calls. In several scenarios we encountered, these were very quick fixes for the DBA - turned around in a matter of hours. The problem was gaining visibility into what methods in the application code were calling what stored procedures that were throwing exceptions, and having the appropriate information triaged to the right expert. Exceptional exit information is provided by the tool tips shown in the previous examples, as are calls to Rollback() and Commit() operations, when the application makes use of such calls.

  • Not making effective use of statement caching
    When the structure of a query to be executed is known during application development, but will be executed with different parameters at runtime, it is best to use prepared statements, and pass parameters at runtime to these statements. This allows for caching of precompiled queries that can then be accessed through the WebLogic prepared statement cache, instead of being passed to the DBMS repeatedly and compiled there repeatedly.

    The default value is zero - no statements or data are cached without user modification of the setting. The effectiveness of the cache size limit you chose for your application can be validated by comparing values of the "Prepared Statement Cache Hits and Misses" within the WebLogic JMX performance metrics - generally, the cache size should be equal to the number of commonly executed queries amongst all end user request types.

    Applying rules of thumb such as these, within an organization that recognizes the value of testing early and often, can reduce the time spent in seemingly endless QA cycles, and greatly increase the production-readiness of the application. By dedicating resources to faithfully reproducing a staging environment that closely mirrors the production environment both in terms of hardware architecture and expected end user load, many performance bottlenecks can be detected, diagnosed, and resolved before causing production headaches and unsatisfied customers.

    By employing an effective J2EE performance diagnosis tool, in both staging and production environments, costly guesswork and departmental fingerpointing can virtually be eliminated. An effective tool and problem-solving methodology allows for the efficient triage of problems to the correct functional expert and his or her silo resolution tools. Reducing the number of people involved in tracking performance problems at any given time reduces frustration, costs, time to problem resolution, and hence time to market. The end result: happier performance teams and end users.

    Quest (Software) PerformaSure displays dynamic graphical maps of custom J2EE applications and how they utilize both the WebLogic Server resources and database management system on a per end-user request basis. Its unique Tag-and-Follow technology reconstructs the end-to-end transaction execution path across distributed J2EE systems, clearly identifying application-database performance bottlenecks, while relating application timing to application server resource metrics.

    Quest PerformaSure Application-Database Performance Bottleneck Data

  • Custom Application Performance Map on a per request basis
    Time spent and number of calls made to:
    - Obtain and Release a DBMS connection
    - Prepare SQL statement & pass parameters
    - Execute statement
    - Manipulate the returned Resultset
    - Commit or roll back a database transaction
    - Exceptions thrown

  • WebLogic JMX Resource Utilization Metrics
    JDBC Connection Pools
    Prepared Statement Caches
    EJB Pools + Caches

  • DBMS Execute and Update times
    SQL Statements and Stored Procedures.
  • More Stories By Rini Gahir

    Rini Gahir is the product marketing manager for J2EE Solutions at Quest Software. With more than eight years of experience in ERP, e-commerce, and software application marketing, Rini's responsibilities include identifying market needs, defining new technologies to meet customer requirements, and steering product development strategies.

    More Stories By Peter Chapman

    Peter Chapman is a product manager with Quest Software. With more than five years of experience in software architecture design and performance tuning,
    as well as high tech product management, Peter's responsibilities include identifying market needs, defining new product requirements, and developing product marketing strategies.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

    @ThingsExpo Stories
    To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
    "Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
    In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
    No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
    Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
    Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
    Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
    Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
    SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...
    The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
    "Digital transformation - what we knew about it in the past has been redefined. Automation is going to play such a huge role in that because the culture, the technology, and the business operations are being shifted now," stated Brian Boeggeman, VP of Alliances & Partnerships at Ayehu, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
    Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
    A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
    Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
    With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
    SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...