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.

    IoT & Smart Cities Stories
    René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
    Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
    In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
    Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
    Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.
    Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
    If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
    Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
    When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
    Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...