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
    "There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, 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.
    Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
    Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
    In their session at @ThingsExpo, Shyam Varan Nath, Principal Architect at GE, and Ibrahim Gokcen, who leads GE's advanced IoT analytics, focused on the Internet of Things / Industrial Internet and how to make it operational for business end-users. Learn about the challenges posed by machine and sensor data and how to marry it with enterprise data. They also discussed the tips and tricks to provide the Industrial Internet as an end-user consumable service using Big Data Analytics and Industrial C...
    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...
    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...
    DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO 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 over the long term.
    To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
    With privacy often voiced as the primary concern when using cloud based services, SyncriBox was designed to ensure that the software remains completely under the customer's control. Having both the source and destination files remain under the user?s control, there are no privacy or security issues. Since files are synchronized using Syncrify Server, no third party ever sees these files.
    Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
    In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
    "Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
    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...
    Internet-of-Things discussions can end up either going down the consumer gadget rabbit hole or focused on the sort of data logging that industrial manufacturers have been doing forever. However, in fact, companies today are already using IoT data both to optimize their operational technology and to improve the experience of customer interactions in novel ways. In his session at @ThingsExpo, Gordon Haff, Red Hat Technology Evangelist, shared examples from a wide range of industries – including en...
    "Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Rodrigo Coutinho is part of OutSystems' founders' team and currently the Head of Product Design. He provides a cross-functional role where he supports Product Management in defining the positioning and direction of the Agile Platform, while at the same time promoting model-based development and new techniques to deliver applications in the cloud.
    DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO 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 over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of bus...
    delaPlex is a global technology and software development solutions and consulting provider, deeply committed to helping companies drive growth, revenue and marketplace value. Since 2008, delaPlex's objective has been to be a trusted advisor to its clients. By redefining the outsourcing industry's business model, the innovative delaPlex Agile Business Framework brings an unmatched alliance of industry experts, across industries and functional skillsets, to clients anywhere around the world.
    Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
    Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...