Chapter 28. Performance Tuning WebLogic Server

Performance Tuning Goals for WebLogic Server

In general, performance tuning involves inspecting a fully functional and operational technical domain for potential inefficiencies (bottlenecks) and resolving (tuning) any identified inefficiencies so that an improved level of behavior can be achieved from that target technical domain. In the context of WebLogic Server, performance is measured through three interdependent behaviors:

  • Response Time—The duration of time the WebLogic Server takes to provide a response to an incoming request

  • Throughput—The number of clients WebLogic Server can service at any given point in time

  • Latency—The roundtrip time it takes a client to make a request to WebLogic Server and for WebLogic Server to fulfill that request and provide a response back to the calling client

If you want to achieve the optimum performance from your WebLogic Server, increasing the server’s response time and throughput and decreasing any latency should be your goals. The scalability of WebLogic Server is also affected by its performance because business requirements to introduce additional concurrent users or resources, such as applications, should be facilitated without any degradation to WebLogic Server’s performance.

A WebLogic Server Performance Tuning Roadmap

Because your WebLogic Server will exist in a computing environment and will interact with other technology and application infrastructures, such as legacy and relational database systems, performance bottlenecks can potentially exist in any aspect of a WebLogic Server environment. For this reason, performance tuning WebLogic Server cannot be an isolated activity; environmental factors that can influence WebLogic Server’s operating behavior and performance also need to be considered. Hence, performance tuning WebLogic Server can include the following activities:

  • Reviewing and setting performance-related WebLogic Server startup and application deployment properties

  • Ensuring the applications deployed to WebLogic Server contain efficient Java and J2EE programming code

  • Tuning the Java Virtual Machine (JVM) so that its memory management options are correctly configured for executing the types of applications deployed to WebLogic Server

  • Configuring the hardware (CPU and disk systems) and operating system to ensure they provide optimal processing power and I/O

  • Performance tuning any relational database management systems serving as data stores to WebLogic Server applications

  • Ensuring the network infrastructure has enough bandwidth to support client connections and additional WebLogic Server–related network traffic, such as IP Multicasting between WebLogic Servers

From the preceding list of activities, you can see that performance tuning WebLogic Server is a multiskilled, multifaceted operation, involving a team of people (WebLogic Server administrators, J2EE developers, database administrators, hardware and network engineers) who together have detailed knowledge of the entire WebLogic Server production environment, including the applications deployed to the server. As a WebLogic Server administrator, you are expected to tune the performance of the WebLogic Server product and the associated Java Virtual Machine (for example, Hotspot or JRockit), and leverage the experience and skills of other people to tune the performance of the WebLogic Server environment as a whole.

There are no hard and fast techniques detailing how you can tune the performance of WebLogic Server and its environment because this task involves a patient and iterative test process in which you try to identify bottleneck factors and determine whether they are indeed impeding the performance of your WebLogic Server. However, having a structured and methodical roadmap showing how you intend to conduct these tests does ease—and instill discipline into—the performance tuning process.

The following sections methodically describe activities you should use as a guide to formulating a performance-tuning roadmap for your WebLogic Server environment.

Step 1: Understand Your WebLogic Server Environment

Identify the technical domain of your WebLogic Server environment, which will include WebLogic Server, deployed applications, hardware platform, operating system, databases, legacy systems, and so on. To perform this activity, you need to bring together a team of experts who can technically address each aspect of your WebLogic Server environment.

Step 2: Document Your WebLogic Server Environment

Have the team document the exact configuration of your WebLogic Server environment. For example, keep track of the following:

  • The WebLogic Server and JVM startup parameters, such as the heap allocation sizes, the JVM garbage collection parameters, the number of execute threads, the percentage of socket readers, and the accept backlog amount

  • The deployment descriptors of the applications deployed to WebLogic Server

  • The hardware configuration of the server, such as the hardware platform of the production server, disk space, CPU processing power, and memory

  • Any services or programs running on the server machine such as virus scanners, Web servers, networking services, and so on

This exercise is essential because it documents a control environment for your WebLogic Server, which will serve as a baseline configuration for all your performance-tuning activities. It is also good practice to version-control all configuration files related to creating the WebLogic Server environment, which enables you to audit changes to the environment, as well as re-create the baseline configuration very easily.

Step 3: Develop Test Scenarios for Your WebLogic Server Environment

Develop multiple repeatable test scenarios that simulate an end-to-end usage of the WebLogic Server environment in production. Ideally, these tests should encompass the following:

  • The most important functional areas or use cases of your WebLogic Server application, as defined by the business. Typically, these are the places where the end users will spend most of their time interacting with the WebLogic Server application and performing their work.

    Note

    These use cases and functional areas of the WebLogic Server application must be working correctly, as defined by their business requirements, before their performance can be examined for improvement.

  • Scenarios where WebLogic Server will be required to interact with external systems, such as databases, legacy systems, or Web services.

  • Mirroring the workload that WebLogic Server will expect in production. For example, if in a production environment, the average workload on WebLogic Server is 1000 requests/sec, your test scenarios should mirror this load. A test carried out with 100 requests/sec will not be realistic and not be sufficient to tune WebLogic Server or its environment appropriately.

The performance of these scenarios will greatly affect the perception of the WebLogic Server application and contribute to its success or failure from the perspective of the sponsors, business customers, and, most importantly, the end users.

Step 4: Benchmark Your Test Scenarios

Run your test scenarios and measure (benchmark) the baseline performance of your WebLogic Server environment, collecting metrics related to WebLogic Server’s response time, throughput, and latency, as well as the metrics related to the memory management of your JVM. You will also need to leverage your performance-tuning team to collect other relevant performance metrics from the WebLogic Server environment, such as the latency of any database systems and the hardware resource consumption rates (memory and CPU). It is important to document what is being benchmarked and why. This understanding should be coherent across the performance tuning.

To benchmark your WebLogic Server environment in an automated manner, you need to use a performance analysis tool. A performance analysis tool should not only be able to simulate your test scenarios, but also be capable of collecting the desired performance metrics and possibly reveal the areas of the WebLogic Server environment where potential bottlenecks exist. Many performance analysis tools are available in the market. Some are free, and some provide more sophisticated testing mechanisms and options than others. Table 28.1 lists a few of these tools and links indicating where you can retrieve more information about them.

Table 28.1. Performance Analysis Tools for Benchmarking Your WebLogic Server Environment

Performance Analysis Tool

Product Link

Borland Optimizeit Suite

http://www.borland.com/optimizeit/

Sitraka JProbe

http://www.sitraka.com/software/jprobe

HPjmeter

http://www.hp.com/products1/unix/java/hpjmeter/

Mercury Interactive’s Topaz solutions

http://www-svca.mercuryinteractive.com

SE Toolkit

http://www.setoolkit.com/

Microsoft’s Web Application Stress Tool

http://www.microsoft.com

Grinder (Free)

http://sourceforge.net/projects/grinder/

Web Benchmark (Free)

http://dev2dev.bea.com

Most of the performance analysis tools are typically available for download so that you can test-drive them.

Note

An example of using the Web Benchmark tool in a benchmarking exercise is provided later in this chapter in the “Run and Monitor a Load Test Against Your WebLogic Server Application” section.

Step 5: Identify the Potential Bottlenecks Affecting the Performance of Your Test Scenarios

Using the benchmark results of your test scenarios, you and your team should be able to identify

  • Whether the performance requirements of the test scenarios are being met in terms of response time, throughput, and latency. This can also be further substantiated through exposing end users to the test scenarios and gathering their feedback.

  • Potential areas of the WebLogic Server environment for which you can tune the performance. This information can be derived either from the performance analysis tool or from expert members of your performance-tuning team who have conducted their own performance metrics based on the test scenarios.

After you determine which test scenarios do not meet their performance-tuning requirements, you and your team need to examine how those test scenarios can be tuned. Solving the performance-tuning issues in these important test scenarios will generally improve the performance of a WebLogic Server environment as a whole.

Performance tuning generally involves modifying one or more configuration properties—whether they are application related, WebLogic server related, JVM related, or hardware related. The J2EE programming code should be modified only for a test scenario, only if it is deemed to be inefficient by the J2EE developer in your performance-tuning team.

Step 6: Resolve the Performance Bottlenecks in Your Test Scenarios

To resolve the identified bottlenecks in your test scenarios, you and your team need to coordinate the modification (tuning) of a single property of your WebLogic Server environment and benchmark the effects of modifying that specific property. For example, you can modify a property of WebLogic Server by modifying its associated parameter value in the server’s configuration file (config.xml).

Note

As a WebLogic Server administrator, you need to understand the various tuning parameters available in the server’s configuration file (config.xml) and the subsystems of WebLogic Server they affect.

Tuning more than a single property at a time can make the results difficult to analyze. This benchmark result should be compared to the baseline results to determine if tuning that property increased or decreased the performance of the test scenario.

If there is no effect on the performance of your test scenario, you should continue tuning and benchmarking the other relevant properties of your WebLogic Server environment until you see an increase in performance in your test scenario. When you see an increase in performance, the related benchmark results will become your baseline benchmark for comparing the benchmark results from tuning additional properties of your WebLogic Server environment.

After you exhaust your tuning options for one test scenario, resolve the performance bottlenecks in your remaining test scenarios using the same approach. This iterative process will help you to approach the optimum configuration for your WebLogic Server environment.

Tuning the Core Server Performance: The Thread Pool

WebLogic Server is a Java-based multithreaded application server. The processing tasks of WebLogic Server are conducted in parallel by multiple threads known as execute threads inside WebLogic Server’s thread pool. By default, WebLogic Server allocates 15 execute threads to the thread pool, which, for most application scenarios, is a sufficient thread count.

A percentage of these execute threads (the default is 33%) is reserved for socket-reading purposes, and they are appropriately known as socket reader threads. These socket reader threads read inbound work requests from sockets and dispatch them to an appropriate execute queue. The remaining percentage of the execute threads performs the actual processing work inside WebLogic Server; hence, these threads are termed worker threads. Worker threads pick up work requests from the execute queue and process them.

As a WebLogic Server administrator, you are responsible for finding the optimum balance between the number of execute threads you configure as socket reader threads and those you configure as worker threads inside the WebLogic Server thread pool.

Note

The terms execute threads and worker threads can be used interchangeably to denote threads in WebLogic Server where work requests are executed.

The Socket Reader Implementation in WebLogic Server

WebLogic Server provides two types of socket reader implementations:

  • Java socket readers—This is a pure-Java implementation of the socket readers and hence portable. In this implementation, the socket reader threads must actively poll all the opened sockets on the server to determine whether there is any data to read off them. Polling becomes expensive because time is wasted in polling inactive sockets that have no data. The problem is magnified when there are more open sockets than socket reader threads. In this scenario, each Java socket reader thread must poll more than one open socket, which lets an active socket go unserviced until a socket reader thread polls it.

  • Native socket readers—This is an efficient native socket reader implementation specific to your operating system. In this implementation, the socket reader threads are notified (via an interrupt) when a socket becomes active—for example, when there is data to read at the socket. The efficiency comes from the fact that the socket reader threads do not poll all the sockets (active and inactive) and service only the active sockets.

Note

▸ For information on the use of socket readers in a WebLogic cluster, see “Understanding How WebLogic Servers Communicate within a Cluster,” p. 845.

For optimum socket reader performance, you should use the native socket readers. WebLogic Server comes bundled with a platform-specific performance pack, which allows the native socket readers to make use of platform-specific asynchronous system calls to read data. The Java-based socket reader implementation is synchronous and can be slow.

Note

Performance packs use a platform-optimized, native socket multiplexor to improve server performance.

You can use native socket readers with all the primary platforms supported by WebLogic Server—for example, Windows, Solaris, HPUX, Linux, and AIX. On platforms where the performance pack is not available, you must use the Java-based socket reader implementation, which is discussed in detail later in the “Tuning the Java Socket Reader Threads” section.

You can verify if a performance pack is available for your hardware platform on the Certifications pages of the BEA documentation at the following URL:

http://e-docs.bea.com/wls/certifications/certifications/index.html

Even though the performance pack is enabled by default for those platforms that support the native socket multiplexor, as a WebLogic Server administrator, you should always ensure that the performance pack is enabled by following these steps:

  1. Start your Administration Server and access the Administration Console.

  2. Expand the Servers node in the navigation tree in the left pane.

  3. Click the server for which you want to enable or disable the performance pack.

  4. In the right pane, click the Configuration, Tuning tab.

  5. If the Enable Native IO option checkbox is not selected, enable the option by selecting the check box, as shown in Figure 28.1.

    Enable the performance pack for WebLogic Server through the Administration Console.

    Figure 28.1. Enable the performance pack for WebLogic Server through the Administration Console.

  6. Click on the Apply button to save changes to the config.xml file.

    Note

    Enabling the option sets the NativeIOEnabled attribute of the ServerMBean to true and disabling it sets the attribute to false.

  7. Restart your WebLogic Server for the changes to take effect.

The performance pack binary (wlntio.dll file on Windows, a libmuxer.so or libmuxer.sl file depending on the flavor of Unix) should be in your WebLogic Server’s PATH. Depending on the platform on which you are running WebLogic Server, the binary is set appropriately in the setWLSEnv.sh script on Unix platforms and setWLSEnv.cmd on the Windows platform. This script is present in the $WL_HOME/server/bin directory of your WebLogic server installation.

With the Native IO option enabled, you will notice the following log statements in your WebLogic Server’s log file.

Note

▸ For information on how to use and view your WebLogic Server log files, see “Understanding the WebLogic Server Logs,” p. 827.

For Windows:

<Dec 5, 2002 11:58:02 PM PST> <Info> <socket> <000406> <NTSocketMuxer was built
 on Jun 24 2002 17:35:19>
<Dec 5, 2002 11:58:02 PM PST> <Info> <socket> <000408> <Allocating 2 NT
 reader threads>

For Unix

<Nov 7, 2002 10:49:39 AM CST> <Info> <Posix Performance Pack> <devsun2>
 <adminserver> <ListenThread> <system> <> <000000> <System has file descriptor
 limits of - soft: '1024', hard: '1024'>
####<Nov 7, 2002 10:49:39 AM CST> <Info> <Posix Performance Pack> <devsun2>
 <adminserver> <ListenThread> <system> <> <000000> <Using effective file
 descriptor limit of: '1024' open sockets/files.>
####<Nov 7, 2002 10:49:39 AM CST> <Info> <Posix Performance Pack> <devsun2>
 <adminserver> <ListenThread> <system> <> <000000> <Allocating: '3' POSIX
 reader threads>

Hence, by default, when you use the performance pack on the Windows platform, the number of socket reader threads is twice the number of CPUs on that specific server machine. On a Unix platform, the number of socket reader threads is set to 3 by default.

WebLogic clients do not have performance packs and have to rely on the Java socket multiplexor implementation to read data. The following section discusses how you can tune the threads using the Java socket multiplexor implementation.

Tuning the Java Socket Reader Threads

Whenever possible, it is recommended that you use the performance pack provided while running any WebLogic Server instance. This makes for a very efficient native implementation of the socket multiplexor as compared to the pure-Java implementation.

In cases when this is not possible, you have to use the Java socket reader implementation, and configuring the appropriate number of socket reader threads for each WebLogic Server instance and client will improve performance.

The socket reader threads are a part of the default execute queue. The ThreadPoolPercentSocketReaders attribute of the ServerMBean allows you to set the percentage of execute threads from the default queue that will be used for socket reading. The default value for this attribute is 33 (percent) and the range of legal values is 1–99.

Increasing the value of the ThreadPoolPercentSocketReaders attribute will improve the socket-reading performance of the server because there will be a greater number of execute threads dedicated to socket reading. However, because the socket reader threads are a part of the default execute queue, increasing this value cuts down on the number of threads available for actually executing the tasks.

The value you assign to the ThreadPoolPercentSocketReaders attribute depends on your application type. For example:

  • If your application requests are CPU intensive or database intensive and take a longer amount of time to respond, you will need a greater number of actual execute threads than socket reader threads.

  • If your application requests can be serviced in a very short time, increasing the socket reader threads will yield a better performance.

To set the number of socket reader threads for WebLogic Server, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Expand the Server node in the navigation tree in the left pane.

  3. Click the server name for which you want to tune the socket reader threads.

  4. In the right pane, click the Configuration, Tuning tab.

  5. Set the value of the Socket Readers attribute. The value is a percentage of the total number of threads available in the default execute queue.

  6. Click the Apply button to apply the changes.

  7. Restart the server for the changes to take effect.

Note

Setting the Socket Readers attribute on the server makes sense only when you are using the pure-Java socket multiplexor implementation for your WebLogic Server.

On the client side, you cannot use the performance pack, so you must default to the Java socket multiplexor implementation. If your client is I/O intensive, making several remote calls, then increasing the socket reader count on the client side will improve performance. On the client side, you can do this by setting the value of the ThreadPoolPercentSocketReaders system property. You can also increase the total number of execute threads available on the client side by setting the value of the ThreadPoolSize system property.

You can configure the number of socket reader threads on the client side by specifying the following options in the Java command line for the client:

  • -Dweblogic.ThreadPoolSize= value

  • -Dweblogic.ThreadPoolPercentSocketReaders=value

WebLogic Server Execute Queues

As mentioned earlier in this chapter, WebLogic Server is a multithreaded application server. The server maintains a pool of Java threads that do all the work. Using multiple threads allows the tasks to be executed in parallel and achieve high performance. These threads in WebLogic Server are called execute threads (or worker threads) because the tasks are executed by them.

The threads within WebLogic Server are partitioned into a set of queues called execute queues. Each queue has the responsibility of executing a specific type of task. The tasks can be application specific such as handling servlet/JSP requests, executing remote EJB methods, and establishing JDBC connections, or they can be server specific tasks such as handling Administration Console requests, handling transaction triggers, running dynamic garbage collection, handling replication requests, and so on. The execute threads are partitioned into execute queues so that one particular task does not take over all the thread resources and cause thread starvation for other types of tasks.

Examples of some of the execute queues in WebLogic Server include

  • __weblogic_admin_rmi_queue (10 threads)—. Requests from a managed server to Administration Server are executed in this queue.

  • __weblogic_admin_html_queue (2 threads)—. The Administration Console requests are executed in this queue.

  • _weblogic_dgc_queue (2 threads)—. Dynamic garbage collection is performed in the threads from this queue.

  • The Default queue (15 threads)Unless you have configured a custom execute queue for an application, all application requests, by default, are executed by the threads in this queue.

  • Multicast queue (1 thread)The threads in this queue are used for handling multicast communication while using Clustering.

As shown in Figure 28.2, work requests enter WebLogic Server through either the listen thread (listens on port 7001 by default) or the SSL listen thread (listens on port 7002 by default), depending on the protocol used for sending the request. These requests are read by the socket reader threads and then placed on an appropriate execute queue depending on the request type. If no custom execute queues are configured, the requests are placed on the default execute queue.

The internals of the WebLogic Server thread pool.

Figure 28.2. The internals of the WebLogic Server thread pool.

Note

WebLogic Server also allows you to configure custom execute queues on a per-application basis. These queues are discussed later in this chapter in the “Assigning Applications to Specific Execute Queues” section.

As execute threads (worker threads) within the specific queue become free, they pick up the requests from the execute queue, execute the task, and send back the response.

Determining the Appropriate Thread Count for an Execute Queue

WebLogic Server allows you to tune the number of execute threads (worker threads) within the default execute queue. You will need to tune this number if you want to control the degree of concurrency/parallelism possible within the server—for example, the number of simultaneous operations performed by the applications deployed on WebLogic Server. However, increasing this number does not necessarily guarantee better performance because more threads mean more context switching between threads and more memory usage, which could lead to a drop in performance.

Caution

Increasing the number of execute threads within the default execute queue inappropriately may degrade performance; therefore, you should be very careful while tuning the execute threads.

The optimum number of execute threads in your WebLogic Server’s default execute queue, from which you can derive performance value, is influenced by the following factors:

  • The number of concurrent requests being handled by the server (throughput)

  • The average response time for each request, which is specific to the type of application you have deployed to your server (response time)

  • The number of work requests waiting to be executed by the worker threads (queue length)

  • The number of idle worker threads during peak usage of your WebLogic Server application (idle threads)

  • The number of CPUs and their utilization on your server machine (CPU usage)

  • The amount of memory (RAM) dedicated to WebLogic Server on your machine (memory usage)

Taking into account these factors, the following sections describe how to tune your WebLogic Server’s execute thread count in the default execute queue.

Step 1: Start the Administration Server

Start your Administration Server. If you are not running the Administration Server in standalone mode, start the managed server(s) where your application(s) is deployed. By default, your WebLogic Server(s) will start with a default thread count of 15.

Step 2: Run and Monitor a Load Test Against Your WebLogic Server Application

To determine the ideal thread count for your default execute queue, you must run a load test against your WebLogic Server application and monitor the factors that can influence the queue’s performance, which were mentioned earlier (throughput, response time, queue length, idle threads, CPU usage, and memory usage). This load test must simulate the important functional areas of your application operating at peak usage, which should include access to Enterprise Information Systems, such as database and legacy systems.

You can perform a load test using a variety of performance analysis tools, as listed in Table 28.1. For example, a very easy performance analysis tool to use is the Web Benchmark tool, which you can download for free from BEA’s Dev2Dev Web site (http://dev2dev.bea.com). Load testing your WebLogic Server application using the Web Benchmark requires only a few configuration steps, as follows:

  1. Download the Web Benchmark zip file (bench.zip) from the Dev2Dev Web site into a directory on your machine—for example, <drive>:benchmark.

  2. Unzip the bench.zip file into its current directory.

  3. Because the Web Benchmark tool is a Java client, you must include its directory in the CLASSPATH environment variable for your operating system. For example, you can set the CLASSPATH in Windows using the following command:

    set CLASSPATH=<drive>enchmark;%CLASSPATH%
    

After you configure the Web Benchmark tool, you can run a load test against your WebLogic Server application using the following command-line syntax:

java BenchClient <#threads> <host> <port> "<URI>" <#iterations>

where

  • #threadsThe number of concurrent clients you want to simulate connecting with WebLogic Server

  • hostThe IP address or DNS name of the target WebLogic Server to load test

  • portThe port WebLogic Server is listening on

  • URIThe virtual mapping, extra path information, and query string of the URL

  • #iterationsThe number of requests each client will perform

For example, the following Web Benchmark command will simulate 15 clients, each performing 5,000 requests to the full URL of http://EINSTEIN:7001/HelloWorldApp/MyServlet:

java BenchClient 15 EINSTEIN 7001 "/HelloWorldApp/MyServlet" 5000

Note

The Web Benchmark tool allows you to hit Web pages in your application with multiple threads and multiple iterations. However, it does not support the use of POST requests or session tracking.

The output you get from running the Web Benchmark indicates the latency of each thread (client), listed from the shortest to the longest amount of time. The output of the Web Benchmark tool will be examined later in this section.

To monitor your load test, you can again use a performance analysis tool with built-in monitoring capabilities, or you can use the Administration Console’s monitoring capability, which should be sufficient for monitoring the influential performance tuning factors of the execute threads in the default execute queue.

To monitor the WebLogic Server environment, in conjunction with your performance analysis tool, you can also use the following system performance tools:

  • The Windows Performance Tool, which can be used to monitor and capture the performance statistics on many system characteristics, including the following:

    • CPU utilization

    • Memory utilization

    • Operating system and application thread usage

    • Active processes running on the system

    • Network activity

    • I/O statistics

  • Unix system performance monitoring utilities, such as the following:

    • sar—. System activity (Solaris)

    • mpstat—. Per-processor (Solaris)

    • vmstat—. Virtual memory statistics

    • netstat—. Network statistics

    • iostat—. I/O statistics

To showcase how you can use the Web Benchmark tool in conjunction with the Administration Console to load test and monitor the factors that can influence the execute queue’s performance, we’ll use a very simple example that will simulate 15 clients, each performing 10,000 requests to a simple URL. You can adjust the syntax of the Web Benchmark tool command according to your own WebLogic Server application pages.

Note

With the evaluation version of WebLogic Server, the maximum number of clients you can concurrently simulate is 15.

To monitor the load test using the Administration Console, follow these steps:

  1. Access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance that you want to monitor.

  4. Select the Monitoring, Performance tab, as shown in Figure 28.3.

    The Performance monitoring pane of the Administration Console.

    Figure 28.3. The Performance monitoring pane of the Administration Console.

From the Performance tab of the Administration Console, as shown in Figure 28.3, you can monitor the following factors during the load test:

  • The number of idle threads assigned to the queue

  • The time that the longest waiting request was placed in the queue

  • The number of requests that have been processed by this queue

  • The number of waiting requests in the queue

  • The current amount of free memory (in bytes) in the JVM heap

Tip

You can adjust the refresh rate of the Administration Console and the polling interval (milliseconds) for graph data from the Console, Preferences tab. The polling interval will affect your displayed data because it will display the results based on your polling interval.

To monitor the CPU utilization doing the load test, you can use either the Windows Performance Monitoring tool or an appropriate Unix utility, such as mpstat.

Now that you know how to run and monitor a simple load test, the next step is to actually start the load testing and monitoring activities, which begins with running the Web Benchmark command. The command used for this simple showcase is

java BenchClient 15 EINSTEIN 7001 "/HelloWorldApp/MyServlet" 10000

Note

Because the purpose of this test is to simulate actual client interaction with WebLogic Server, it should be run from an actual client machine.

As the Web Benchmark simulates your client load test, you can monitor the activity of your test via the Administration Console and other system monitoring tools. After the Web Benchmark completes its load test on your WebLogic Server application, it will display the results of the latency of the client requests to complete their iterations in the shortest to the longest time, as shown in Figure 28.4.

The results of running the Web Benchmark tool in a simulated load test.

Figure 28.4. The results of running the Web Benchmark tool in a simulated load test.

The results from the Administration Console, as shown in Figure 28.5, also provide valuable information, as follows:

The results of running the Web Benchmark tool through the Administration Console.

Figure 28.5. The results of running the Web Benchmark tool through the Administration Console.

  • The peak number of idle threads during the load test. However, you will need to refresh the Administration Console at multiple times during the load test to capture this value. From the test, there were a maximum of four idle threads.

  • The peak number of requests executed at the polling interval of the performance graph. From the test, there was a peak of 1,237 requests executed.

  • The peak number of requests waiting in the execute queue. From the test, there was a peak of 11 requests waiting to be executed in the queue.

  • The maximum memory utilization during the test.

A Windows Performance Monitor tool also used during the load test indicated a maximum of 100% and a low of 84% CPU utilization on a dual CPU machine, as shown in Figure 28.6.

The CPU utilization results of running the Web Benchmark tool through the Windows Performance Monitoring tool.

Figure 28.6. The CPU utilization results of running the Web Benchmark tool through the Windows Performance Monitoring tool.

You should perform your load test a number of times to a point where your results are relatively consistent, at which point you can analyze them.

In general, if the thread count is set too low, you will see the following results from your load test:

  • The CPU is waiting to do work, but there is work that can be performed.

  • The CPU utilization never consistently stays within the 85% to 95% optimal utilization range.

  • There is a high percentage of requests waiting to be executed (queue length) in comparison to the throughput of the queue. This is dependent on the type of application and the functional area of that application being tested.

  • The latency of the client requests is high based on the performance requirements for the functional areas of the WebLogic Server application being load tested.

In general, if the thread count is set too high, you will see the following results from your load test:

  • The CPU utilization is consistently at 100% utilization.

  • The latency of the client requests is still high based on the performance requirements for the functional areas of the WebLogic Server application being load tested.

  • The throughput has greatly increased, but the peak number of requests in the queue remains relatively constant, and there is also an increase in the memory utilization.

The hard and fast way to validate whether you are running your WebLogic Server with high or low thread count is to increase the thread count and compare your results. If there is an increase in performance, you need to repeat your tests by incrementing the thread count by a small amount (two to five threads only) until you reach a point where you see a performance degradation in the throughput and latency of the client requests. This will narrow your execute thread count to a small range for fine-tuning. The following section describes how you can modify the thread count in the default execute queue.

However, if you increase your thread count and see an immediate performance degradation, you will have to take the same iterative test approach, but this time by decreasing the thread count by a small amount until you see a performance increase. This will also narrow your execute thread count to a small range for fine tuning.

Step 3: Modifying the Thread Count in the Default Execute Queue

You can modify the number of execute threads in the default execute queue using the ThreadCount attribute of the ServerMBean. To set this attribute via the Administration Console, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance that contains the default execute queue you want to configure.

  4. Select the Monitoring, General tab in the right pane.

  5. Click the Monitor All Active Queues text link to display the active execute queues that the selected server uses, for example, as shown in Figure 28.7.

    The active execute queues in a default WebLogic Server installation.

    Figure 28.7. The active execute queues in a default WebLogic Server installation.

    Tip

    You can use the screen shown in Figure 28.7 for monitoring the thread activity in an execute queue. However, the refresh rates for an Administration Console screen are much longer than the data presented via the graph (refer to Figure 28.5).

  6. Click the Configure Execute Queue text link to display the execute queues that you can modify.

    Note

    You can modify only the default execute queue for a server or a user-defined execute queue.

  7. In the table of configured execute queues, click the name of the default execute queue to display the Execute Queue Configuration tab, as shown in Figure 28.8.

    The default execute queue’s Configuration tab.

    Figure 28.8. The default execute queue’s Configuration tab.

  8. From the displayed Execute Queue Configuration tab, increase or decrease the default thread count of 15 by a small amount (2 to 5 threads).

  9. Click Apply to apply your changes.

  10. Shut down and restart the selected server to enable the new thread count settings for the default execute queue.

Tuning Execute Queues for Overflow Conditions

The socket reader threads in WebLogic Server read requests and place them on the appropriate execute queue. The length of this execute queue will increase if the requests come in at a rate faster than they are processed. In such situations, the response time for the requests will be slower. WebLogic Server allows you to configure attributes for the execute queue, which helps in detecting such conditions.

The server detects an overflow condition if the length of the execute queue reaches a user-defined percentage of its maximum size. When this threshold is reached, the server’s state is changed to Warning, and depending on other attributes set for the queue, additional execute threads can be allocated to the queue. These additional execute threads then pick up the requests from the execute queue and thus help in reducing the queue length to an acceptable limit.

To detect the overflow conditions and handle them automatically, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance that contains the execute queue you want to configure.

  4. Select the Monitoring, General tab in the right pane.

  5. Click the Monitor All Active Queues text link to display the active execute queues that the selected server uses, for example, as shown in Figure 28.7.

  6. Click the Configure Execute Queue text link to display the execute queues that you can modify.

    Note

    You can configure these attributes only for the default queue or any custom execute queue that you have configured. Parameters for the WebLogic-specific execute queues (such as __weblogic_admin_rmi_queue) cannot be configured.

  7. In the table of configured execute queues, click the name of the default execute queue to display the Execute Queue Configuration tab (refer to Figure 28.8).

  8. From the displayed Execute Queue Configuration tab modify the following attributes:

    • The Queue Length parameter indicates the maximum number of requests that can be in the execute queue. The maximum size is 65535 and the minimum size is 256. In most cases, you don’t need to modify the Queue Length parameter.

    • Set the Queue Length Threshold Percent attribute. The default is set to 90%. This threshold attribute indicates a percentage of the queue length size and is monitored by the server for detecting overflow conditions. You can set this percentage to any value between 1 and 99. Queue length sizes below the threshold percentage are considered normal. If the queue length size reaches the percentage value you’ve set, an overflow condition is detected and handled by the server.

    • Set the Threads Increase parameter to the number of threads that the WebLogic Server should allocate to the execute queue when an overflow condition is detected. The server uses this attribute to automatically handle an overflow condition. The additional threads allocated will help in reducing the execute queue length. Enter 0 for the number of threads if you do not want the server to automatically allocate execute threads to the queue.

      Threads added to an execute queue after the detection of an overflow condition will not be removed even after the queue length drops back to an acceptable limit. The number of threads in the queue thus stands increased after an overflow condition is detected and if you have set a non-zero value for the Threads Increase parameter.

    • Set the Threads Maximum attribute to prevent the server from increasing threads to a very high number in response to an overflow condition. On detection of an overflow condition, the server will increase the threads in the execute queue by a number set in the Threads Increase parameter. This may hamper performance, so it is important to control the maximum number of threads using this parameter. The default value is 400.

    • Set the Threads Minimum attribute to specify the minimum number of threads that the server should maintain in the execute queue to prevent an unnecessary overflow condition. The default value is 5.

  9. Click the Apply button to apply the changes.

  10. Shutdown and restart the server for these changes to take effect.

The server prints the following message in the log file when it detects an overflow condition and adds ThreadsIncrease number of threads to the execute queue:

<Dec 5, 2002 4:59:08 PM PST> <Warning> <WebLogicServer> <000333> <Queue usage
is greater than QueueLengthThresholdPercent "5%" of the maximum queue size.
We will try to allocate ThreadsIncrease "2" thread(s) to help.>

Determining Stuck Threads

When tasks are put on an execute queue by the socket reader threads, the idle execute threads pick up the task, execute it, and send back the response. Idle execute threads should always be available within the execute queue to perform this task. If no idle threads are available, the tasks will not be performed. This is a critical condition because the requests will go unserved.

WebLogic Server automatically detects conditions in which an execute thread takes more than an acceptable amount of time to complete its task. The server marks such threads as stuck. If all the threads within an execute queue become stuck, the server changes its state to Critical or Warning, depending on the execute queue type. The server’s health state changes to Critical if all the threads in the “default” queue are determined to be stuck. The server’s health changes to Warning if all the threads in the weblogic_admin_html_queue, weblogic_admin_rmi_queue, or a user-defined execute queue become stuck.

Note

If a WebLogic Server’s health state changes to Critical, it is very likely the server’s health state will be labeled “failed,” at which point if you are using the Node Manager, it can be used to shut down and restart the “failed” WebLogic Server. However, a change of health state to Warning does not necessarily imply WebLogic Server will be labeled “failed.”

Note

▸ For information on WebLogic Server Self-Health monitoring capabilities, see “Monitoring the Health of Your WebLogic Domain Using the Node Manager,” p. 824.

To configure the detection of stuck threads in the server, follow these steps:

  1. Start the Administration Server, if it is not already running, and access the Administration Console.

  2. Expand the Servers node in the navigation tree in the left pane.

  3. Click the server name for which you want to configure the Stuck Thread detection parameters.

  4. Select the Configuration, Tuning tab in the right pane, as shown in Figure 28.9.

    Set attributes to determine Stuck Threads in WebLogic Server using the Administration Console.

    Figure 28.9. Set attributes to determine Stuck Threads in WebLogic Server using the Administration Console.

  5. Modify the following attributes in the Configuration, Tuning tab as necessary to tune thread detection behavior for your WebLogic Server:

    • Set the Stuck Thread Max Time attribute. This is the maximum amount of time that an execute thread can be busy. If it exceeds this time, the server marks the execute thread as stuck. The default value for this parameter is 600 seconds. Set the attribute to a value greater than the maximum acceptable time that your server can take to execute a request.

    • Set the Stuck Thread Timer Interval attribute to a time in seconds that the server should periodically check for stuck threads. The default value is 600 seconds, which means that the server will check at 10-minute intervals to find threads that have been working for longer than the Stuck Thread Max Time period.

  6. Click the Apply button to apply the changes.

  7. Shut down and restart the server for the changes to take effect.

You can verify whether your WebLogic Server is detecting stuck threads by reviewing your WebLogic Server log file. For example, the server prints the following message in the log file when it detects a stuck thread:

<Dec 5, 2002 4:56:52 PM PST> <Warning> <WebLogicServer> <000337>
<ExecuteThread: '10' for queue: 'default' has been busy for "38" seconds
working on the request "Http Request: /sleep.jsp", which is more than the
configured time (StuckThreadMaxTime) of "30" seconds.>

WebLogic Server also prints the following message in the log file when a thread marked Stuck by the server completes its work and becomes idle:

<Dec 5, 2002 7:50:48 PM PST> <Info> <WebLogicServer> <000339> <ExecuteThread:
'27' for queue: 'default' has become "unstuck".>

Configuring Custom Execute Queues

WebLogic Server has a default queue to handle all the application-specific requests. However, it also allows you to configure execute queues on a per-application basis.

You may want to configure these additional execute queues to achieve the following advantages:

  • Optimize the performance of critical applications—In the default scenario, when you have not configured any custom execute queues, all the applications deployed on WebLogic Server use the execute threads in the default queue to do their work. Because all the applications share the same default queue, it is possible that a critical application will be starved of threads because they are being used by some other applications. To prevent this thread starvation for critical applications, you can configure an execute queue dedicated to them. This solution always guarantees a fixed number of threads for the critical application.

  • Throttle the performance on nonessential applications—For applications that are nonessential but have a potential to take over server resources such as threads and memory, assigning a dedicated execute queue can help limit the resource starvation that such applications can cause to other applications on the same server.

  • Remedy deadlocks in threads—Configuring a dedicated execute queue can help prevent out-of-threads deadlock. Consider an application that, as a part of its task, has to talk to another subsystem on the same server—for example, a servlet calling remote EJB methods. If all the execute threads are processing servlet requests, there will be no threads to process the EJB methods. Because EJB methods are a part of the task, you see an out-of-threads deadlock for the EJBs. You can prevent this problem by assigning the servlet a separate execute queue so that it does not take over all the thread resources from the EJBs.

You need to be aware, however, that unnecessarily configuring custom execute queues for applications wastes resources. You can have a condition in which execute threads in a particular custom queue are idle, while there are no idle threads in another application-specific execute queue. In this case, the idle threads in one queue are wasted resources because they could have been used by the other application if the queues were not partitioned.

To configure custom execute queues using the Administration Console, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance where you want to configure a new custom execute queue.

  4. Select the Monitoring, General tab in the right pane.

  5. Click the Monitor All Active Queues text link to display the active execute queues that the selected server uses, for example, as shown in Figure 28.7.

  6. Click the Configure Execute Queue text link to display the execute queues that you can modify.

  7. Click the Configure a New Execute Queue link to show the Execute Queue Configuration tab, as shown in Figure 28.10.

    Configure a new execute queue using the Administration Console.

    Figure 28.10. Configure a new execute queue using the Administration Console.

  8. In the Execute Queue Configuration tab, modify the following attributes or accept the system defaults:

    • Enter a name for your new execute thread.

    • Set the Thread Count attribute to configure the number of execute threads in the custom execute queue.

    Set other parameters as discussed in the “Tuning Execute Queues for Overflow Conditions” section earlier in this chapter.

  9. Click the Apply button to apply the changes. The changes are persisted to the config.xml file.

  10. Restart the server for the changes to take effect.

Assigning Applications to Specific Execute Queues

In the previous section, we discussed the advantages of assigning dedicated execute queues to applications. In this section, we will discuss how applications such as servlets, JSPs, and EJBs can be assigned to dedicated execute queues.

Assigning Servlets and JSPs to Execute Queues

To assign servlets and JSPs to a dedicated execute queue that has been already configured in the server, you can use the <wl-dispatch-policy> parameter to specify the queue in which the servlet or JSP will be executed. This parameter is specified as an initialization parameter in the web.xml deployment descriptor of the Web application containing the servlets and JSPs.

The following snippet from the web.xml file assigns a dedicated execute queue called CriticalAppQueue to the SnoopServlet and the critical.jsp file. Any requests for these Web files will be executed by threads within the CriticalAppQueue:

<servlet>
<servlet-name>SnoopServlet</servlet-name>
<jsp-file>/myapp/critical.jsp</jsp-file>

<init-param>
<param-name>wl-dispatch-policy</param-name>
<param-value>CriticalAppQueue</param-value>
</init-param>
</servlet>

Assigning RMI Objects and EJBs to Execute Queues

To assign an RMI object or EJB to a dedicated execute queue that has already been configured in the server, you can use the -dispatchpolicy option while using the rmic and ejbc compilers. Use the rmic compiler as follows:

java weblogic.rmic -dispatchPolicy CriticalAppQueue examples.HelloImpl

If the RMI implementation class is compiled as shown, any requests for the HelloImpl remote object will be executed on the server in an execute thread from the CriticalAppQueue.

Use the ejbc compiler as follows:

java weblogic.ejbc -dispatchPolicy CriticalAppQueue std_AccountBean.jar
AccountBean.jar

If the EJB AccountBean is compiled as shown, any requests for the remote methods of the AccountBean will be executed on the server in an execute thread from the CriticalAppQueue.

Monitoring Execute Queues and Execute Threads

To monitor the execute queues, execute threads, and their attributes in WebLogic Server, follow these steps:

  1. Start the Administration Server, if it is not already running, and access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance that contains the execute queue you want to monitor.

  4. Select the Monitoring, General tab in the right pane.

  5. Click the Monitor All Active Queues text link to display the active execute queues that the selected server uses, for example, as shown in Figure 28.7. You will see a listing of all the active execute queues in the server and each queue’s attributes—number of threads, number of idle threads, throughput, and so on.

  6. Click a particular queue name in the table listing to view all the execute threads within that execute queue. For example, Figure 28.11 shows a listing of all execute threads within the default execute queue.

    A list of all the execute threads within the default execute queue.

    Figure 28.11. A list of all the execute threads within the default execute queue.

Tuning the Connection Backlog

The AcceptBackLog parameter allows you to configure the number of TCP connection requests that can be buffered in a wait queue before being accepted by the server. WebLogic Server, by default, listens on two ports: the plain-text port (default 7001) and the SSL port (default 7002). If work requests come to these ports at a rate faster than they are being processed, they will be buffered in a queue whose size is fixed by this parameter.

You will need to tune this parameter if either the connections are being dropped silently on the client side or the clients are receiving connection refused messages when trying to connect to WebLogic Server.

The default value of this parameter is 50, which means that a maximum of 50 connection requests can be buffered at any given time. If the queue becomes full, additional connection requests will be dropped and not accepted by the server.

Caution

Setting this parameter to 0 may prevent the server from accepting any connections on some operating systems.

To set this parameter, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Expand the Servers node in the navigation tree in the left pane.

  3. Click the name of the server instance that you want to configure.

  4. Select the Connection, Tuning tab in the right pane, as shown in Figure 28.12.

    Setting the AcceptBackLog parameter through the Administration Console.

    Figure 28.12. Setting the AcceptBackLog parameter through the Administration Console.

  5. Set the AcceptBackLog parameter as necessary to tune how many TCP connections can be buffered in a wait queue.

  6. Click the Apply button to persist the value to the config.xml file.

  7. Shut down and restart WebLogic Server for the changes to take effect.

To tune this parameter, start a realistic load test on the server. If you see connections being refused on the client side, increase the AcceptBackLog value by 25% and retest. Continue increasing the parameter by 25% until the queue size is large enough to buffer the connection requests generated by your load test.

Tuning JDBC Connection Pools in WebLogic Server

If your application uses database connections, you can improve performance of your application by using the WebLogic JDBC connection pools. Opening and closing a database connection are expensive operations and can be optimized by using connection pools. If you have configured a connection pool in WebLogic Server, the server will create database connections while starting. These connections will be stored in the pool and will be available to any server subsystems and clients. The client can fetch a connection from the pool, use it to perform some database activity, and then close it. When the client closes the connection that it has obtained from the pool, that connection is returned to the pool and is available to other clients. Thus, using connection pools, you can eliminate the overhead of creating and closing database connections each time.

The connection pools can be configured to define the initial number of connections, maximum number of connections, and the way the pool should grow and shrink. All these parameters need to be set appropriately to achieve optimum performance for your application.

The InitialCapacity attribute defines the number of connections the server will create while starting or when the connection pool is targeted to a server instance. The server opens the number of database connections defined in InitialCapacity and stores them in the pool.

During the development phase, when you want the server startup to be quick, you should set the attribute to a low value.

In a production phase, the value of InitialCapacity should be equal to the value of MaximumCapacity. As a result, the maximum number of database connections required by your application, depending on the maximum concurrent load, will be created by the server during startup time.

This will slow down the startup but will prevent the server resources from being wasted for creating additional connections after the server has started.

The MaxCapacity attribute defines the maximum number of database connections a connection pool can contain.

In production environments, you should set the MaxCapacity parameter depending on the number of concurrent client sessions that require database connections and the number of connections required by each request. This prevents any client session from waiting for some other client session to release a connection back to the pool. This parameter is independent of the number of execute threads in the server.

WebLogic Server also provides other parameters that can be configured for a connection pool, which would optimize resources in the server. It is a good practice to set the ShrinkingEnabled attribute for the connection pool to true. When this attribute is set, the pool will shrink back to its InitialCapacity size when the server detects that connections created during increased traffic are not being used. This frees WebLogic Server as well as database resources when the period of peak traffic ends. When you set this parameter, the size of the connection pool will fluctuate between InitialCapacity and MaxCapacity.

The RefreshMinutes attribute of the connection pool defines the period during which database connection tests will be carried out. During the test, each unused connection is tested using the test table configured. Connections that fail the test are closed and reopened to re-establish a valid database connection. Do not set the RefreshMinutes parameter to a very low value because doing so would increase the frequency of the tests and cause unnecessary overhead on the server.

It is also a good practice to close the JDBC connections immediately after you are done with the database operation in your application code. Database connections that are not closed could lead to unnecessary memory leaks and cause database resource starvation.

Caching Prepared SQL Statements

You can configure a prepared statement cache for each connection pool in WebLogic Server. The size of the cache can be set using the Administration Console. The prepared statements are stored in the cache until the size reaches the maximum limit. If an application calls any of the prepared statements stored in the cache, WebLogic Server reuses it. This eliminates the need for parsing the prepared statement in the database each time, as well as improves the current statement’s performance.

Tuning EJB Applications

The EJB container in WebLogic Server specifies an additional deployment descriptor file named weblogic-ejb-jar.xml, which contains parameters that define the concurrency, caching, clustering, and transaction behavior. These parameters can be tuned to achieve optimum performance for your EJB applications. This section describes the parameters that can be tuned for each type of EJB.

Stateless Session Beans

WebLogic Server maintains a free pool of bean instances for every stateless session bean. When a remote method is called on a stateless session bean, the EJB container picks a bean instance from the free pool and executes the remote method on it. On completion of the method execution, the bean instance is returned to the free pool. Because all stateless session bean instances are equal and because they do not have any state, it does not matter which instance is picked from the free pool. The EJB container in WebLogic Server thus saves time that would be wasted in creating a new stateless session bean instance each time a remote method is called. Pooling allows the EJB container to serve a large number of clients using a small number of bean instances.

The behavior of the free pool is controlled by two parameters: initial-beans-in-free-pool and max-beans-in-free-pool. These parameters are defined within the weblogic-ejb-jar.xml file. You need to tune these parameters to get good performance for your stateless session beans.

The initial-beans-in-free-pool parameter defines the number of bean instances the EJB container will create when the stateless session EJB is deployed to the server. Creating the bean instances immediately after deployment allows the container to immediately service remote method requests without having to instantiate new bean instances.

The max-beans-in-free-pool parameter defines the maximum number of stateless session bean instances in the free pool. This parameter puts an upper limit on the number of bean instances and controls the amount of concurrency that can be achieved with stateless session beans. When a remote method request arrives at the EJB container, the container grabs a bean instance from the free pool. If there are no free instances in the pool, the container will create one until the number reaches the max-beans-in-free-pool limit. If this upper limit is reached, the EJB container will wait until another bean instance becomes free and is released back to the pool.

As the remote method of each bean instance is executed in a WebLogic Server execute thread, the maximum concurrency is actually controlled by the number of available execute threads. By default, there is no limit to the number of instances the container will create. In most cases, it is recommended that you not tune the max-beans-in-free-pool parameter, which will let the EJB container create new instances as needed.

Under certain circumstances, however, you might need to set this limit. If your stateless session bean has a member variable that holds a connection to an external legacy system, and if the number of connections that can be established with the external system is limited, you should set the max-beans-in-free-pool parameter to the maximum number of connections that can be created. In this case, the max-beans-in-free-pool parameter can be used to limit the use of resources.

Note

The initial-beans-in-free-pool and max-beans-in-free-pool parameters work in the same way for message-driven beans also.

When you’re using clustered stateless session beans, if the EJB contains idempotent methods, you should set the stateless-bean-methods-are-idempotent flag to true in the weblogic-ejb-jar.xml file. Idempotent methods are methods that can be called multiple times and produce the same result as if the methods were called only once. Setting this flag to true enables the smart EJB stub to fail over to another server hosting the bean in case the server that was executing the remote method failed.

Stateful Session Beans

A stateful session EJB instance maintains state and is associated with a client that created it. There is a one-to-one correspondence between the clients and the bean instances on the server. Because each client has a reference to a specific stateful session bean instance on the server, there is no concept of pooling in the case of stateful session EJBs.

Because each client has its own stateful session bean instance on the server, when the number of clients grows large, so does the number of bean instances on the server. It is not always feasible to maintain all the bean instances in memory for the lifetime of a client. The EJB container is thus required to manage an active set of stateful session beans through mechanisms known as activation and passivation.

For more information on the activation and passivation mechanisms for stateful session beans, see Chapter 20.

Activation and passivation mechanisms allow the EJB container to maintain a working set of stateful session bean instances in memory and thus conserve the server’s memory resources. The max-beans-in-cache parameter in the weblogic-ejb-jar.xml deployment descriptor is used to configure the maximum number of stateful session bean instances that can be held in the in-memory cache.

Setting the max-beans-in-cache parameter to a low value limits the maximum number of active bean instances that the EJB container can hold in the cache, thus leading to excessive activation and passivation as more beans are created. Activation and passivation of beans are expensive operations and can certainly slow down performance. Setting this parameter to a high value can put unnecessary strain on the server’s memory resources. You need to tune this parameter appropriately based on factors such as the maximum heap available for the server, average life period of the stateful session bean, as well as the maximum number of stateful session bean requests.

Entity Beans

Entity beans are EJBs that provide an object view of data in the database. The state of an entity bean is transactional, and updates are persisted to the database only if the transaction commits. If the transaction rolls back, the bean returns to its last committed state.

Note

Entity beans are described in detail in Chapter 21, “Managing Persistence with Entity Beans.”

Tuning Pool Size for Entity Beans

WebLogic Server maintains a pool of entity beans that do not have an identity; for example, they do not have a primary key associated with them. Beans in this pool are used to invoke finder methods as well as home methods such as create and remove. The max-beans-in-free-pool parameter controls the number of anonymous instances in the free pool. If your clients create many entity beans or call finder methods a lot, increasing this number will improve performance. Set this parameter depending on the heap available for WebLogic Server.

Using the Appropriate Concurrency Strategy

WebLogic Server allows the user to select a concurrency control strategy for the entity beans. It provides four kinds of concurrency strategies for entity beans: Database, Exclusive, Optimistic, and ReadOnly.

The Concurrency strategy for the entity beans can be specified using the concurrency-strategy parameter in the weblogic-ejb-jar.xml file. The default strategy is database concurrency.

Database concurrency strategy improves concurrency by deferring lock management and deadlock detection to the database. In this kind of concurrency model, two clients can call the same entity bean (for example, an entity bean with the same primary key) in two separate transactions. If the two beans are modifying the same data at the same time, the database detects and resolves the conflict by rolling back one of the transactions. If the entity bean has been called by the clients for a read operation, this concurrency strategy provides the best performance because it allows the two transactions to proceed at the same time.

When using database concurrency strategy, the ejbLoad() method is called at the start of each transaction to obtain the most current EJB data.

Exclusive locking limits the concurrency because, in this case, the EJB container has a lock on the bean instance, and there can be only a single bean instance per primary key. As a result, there can be only one transaction active for an entity bean instance at a time, even in the case of a read operation.

When you’re using the exclusive locking behavior in a single server environment, consider using the cache-between-transactions parameter to limit the ejbLoad() method being called at the start of each transaction. By default, ejbLoad() is called at the start of each transaction as other sources may also be updating data. However, while using exclusive concurrency in a single server environment, there will be no other clients updating the data, so you can be assured that the cached EJB data is always up to date. You can set this parameter to true in weblogic-ejb-jar.xml to limit calls to ejbLoad(). In a clustered environment, the cache-between-transactions parameter is automatically disabled because the entity bean on any server in the cluster can update the data.

The Optimistic concurrency strategy does not hold any locks in the EJB container or the database. To enable the use of this strategy, you must specify the verify-columns attribute in the weblogic-cmp-rdbms-jar.xml deployment descriptor. In this case, the EJB container ensures that the data being updated by a transaction has not been modified by some other client.

Note

▸ For more information on the concurrency strategies available for entity beans, see “Choose the Right Concurrency Strategy,” p. 762.

The ReadOnly concurrency strategy creates an instance of a read-only entity bean for each transaction. This allows each transaction to proceed in parallel and improves concurrency. Also, to minimize reading data from the database, the EJB container copies the state from an existing instance in the cache while allocating a new instance after checking that the data is up-to-date. Using this strategy with ReadOnly entity beans provides good performance.

Using the Appropriate Transaction Isolation Level

The transaction isolation level defines the degree to which concurrent transactions accessing the database are isolated from each other for read operations. Setting lower isolation levels provides you with better concurrency between transactions accessing the database, at the cost of lesser isolation between transactions. Set the isolation level appropriately depending on your application and choice between concurrency and isolation.

Using Delay-Database-Insert-Until

The Delay-Database-Insert-Until attribute of the weblogic-cmp-rdbms-jar.xml file allows you to control when and how the EJB container inserts newly created beans in the database. The attribute can have three values: ejbCreate, ejbPostCreate, and commit.

The default value is ejbPostCreate, which means that the data will be inserted immediately after the ejbPostCreate() method. If you modify any of the bean’s fields in the ejbPostCreate method, setting the Delay-Database-Insert-Until attribute to ejbPostCreate will save an extra ejbStore() operation. If you do not modify any fields in the ejbPostCreate method, you may specify the value to ejbCreate.

You can specify the Delay-Database-Insert-Until value as commit and improve performance of CMP entity bean creation. This feature is known as bulk insert, and it allows the container to create multiple database inserts in just one SQL statement. As a result, multiple database insert calls are avoided and performance improved. Bulk insert applies only to inserts between a transaction marked by begin() and commit().

Optimizing HTTP Sessions

You can use the following guidelines for optimizing HTTP session usage within your application. Here are a few points to consider:

  • Use in-memory replication techniques for session replication if possible. This approach is 10 times faster than the JDBC-based session persistence.

  • When you’re using session replication in a WebLogic cluster, minimize the session.setAttribute() operations. Each update to the session with a setAttribute operation will cause the following updates to occur:

    • An update being made to the session state on the secondary server via a remote call, in case of in-memory replication.

    • An update being made to the session state maintained in the database with a database write, in case of JDBC-based session persistence.

    • An update being made to the session state maintained in the file with an I/O write, in case of file-based session persistence.

  • To minimize the session put operations, increase the granularity of the session update; for example, aggregate different put operations into one single put operation, if possible. Update the session with larger aggregate objects rather than multiple smaller objects.

  • Factor for the session size and the average number of active sessions while tuning the WebLogic Server heap.

  • Use sessions only when state cannot be maintained on the client side—for example, in cookies.

Tuning the Java Virtual Machine (JVM)

WebLogic Server is a Java-based application server and runs inside the Java Virtual Machine. To achieve optimum performance for your application deployed on WebLogic Server, you need to fine-tune various JVM parameters too. This section describes these parameters and how you can tune them.

Tuning the JVM Heap Size

To understand the process of tuning the JVM heap size, you need to understand what the JVM heap consists of, how it grows and shrinks, and how garbage collection is done. In this section, we explain these concepts. The Java heap consists of free memory, live objects (ones that are in use), and dead objects (ones that are not referenced). All the Java objects live in the Java heap. During the lifetime of a Java program, new objects may be created, and objects that were active earlier may become unused. The unused or dead objects cannot be reached from any pointer in a running program. During the execution of a Java program, more objects are created and the JVM starts running out of free memory in the heap. When the heap in use reaches a certain limit, the JVM initiates garbage collection. This process cleans up the unused objects and frees some memory. In the naïve garbage collection technique, also known as stop and run, when the garbage collection starts, the JVM stops execution. This is not good for server performance. The 1.3 Java HotSpot Virtual Machine provides another flavor known as generational garbage collection, which is better in performance.

Tuning the size parameter of the JVM heap is important because it controls the frequency of the garbage collection process as well as how long the garbage collection will run when the JVM starts it. If the heap size is large, the full garbage collection cycle will run longer but less frequently. If the heap size is smaller, the garbage collection will be much more frequent but run much faster. The heap size should be tuned such that the JVM spends less time doing the garbage collection and, at the same time, the server gives the maximum throughput.

Determining Heap Size for the WebLogic Server

You can specify the minimum and maximum heap size for a JVM using the -ms and -mx parameters, respectively. The minimum heap size parameter means that amount of memory will always be allocated for the virtual machine. The heap can grow until the -mx limit as more objects are created. After you determine the maximum heap required by your WebLogic server, set the minimum heap size equal to the maximum heap size. This will give better performance because the maximum heap required will be allocated while starting up instead of as needed after the server has started.

You should set the maximum heap size to be 80 to 85% of the actual available RAM. This will prevent swapping of pages to disk, which decreases performance. In addition, it is a good practice to run WebLogic Server instance on a dedicated machine so that its maximum heap size can be configured to 80 to 85% of the total RAM available on that machine.

You can specify the verbose garbage collection parameter -verbosegc to the JVM so that it logs out all the garbage collection–related information. The information printed out by the JVM includes the amount of time the garbage collection cycle ran as well as the amount of memory that was freed. You can redirect the -verbosegc output to a log file and then analyze it to determine the optimum heap size for your application. Set the -verbosegc flag as follows while starting WebLogic Server:

java -ms256m -mx256m -verbosegc ..... weblogic.Server >> log.txt 2>&1

This command sets the -verbosegc flag for the JVM and redirects both stdout and stderr to the log.txt file.

You get the following output when the -verbosegc flag is passed to the JVM:

[GC 25299K->23266K(204544K), 0.0512523 secs]
[GC 25314K->23175K(204544K), 0.0039530 secs]
[GC 25222K->23179K(204544K), 0.0058421 secs]
[GC 25227K->23209K(204544K), 0.0045444 secs]
[Full GC 24838K->23271K(204544K), 0.8871415 secs]

The Full GC cycle freed 24838KB – 23271KB = 1567KB of heap and took 0.8871415 seconds to do so. The number in parentheses is the total memory available, which is 204544KB, or 200MB. Therefore, after the Full GC cycle, the amount of memory in use is 23271KB.

In the verbosegc output, the line beginning with GC indicates a minor garbage collection cycle and the line beginning with Full GC indicates a major garbage collection cycle. The minor cycle reclaims memory in the young generational area, whereas the major cycle runs longer and reclaims memory in the old generation area. The generation areas—young and old—are concepts that are part of the generational garbage collection algorithm that the Java HotSpot VM uses and are explained later in this section.

With the verbosegc flag set, run a realistic load test and capture the garbage collection information. Analyze the following points from the log file:

  • The period for which the full garbage collection ran. When the full garbage collection cycle runs, the JVM pauses the execution of other threads. As a result, the WebLogic Server would not be able to respond to client requests during the period of the garbage collection cycle. A full garbage collection cycle should not take more than 3 to 5 seconds usually. If the cycle runs for a longer period of time, consider decreasing the heap size.

  • The frequency of the full garbage collection cycle. If this happens, the heap is set too low for your application and the client load it is handling, so the JVM runs out of heap frequently and has to start the full garbage collection cycle to free memory. You should increase the heap size and reprofile the application.

  • The heap size in use after a full garbage collection cycle. The verbosegc parameter outputs the amount of heap that was freed in a garbage collection cycle as well as the amount of heap that is in use currently by the JVM. Monitor the amount of heap in use after a full garbage collection cycle. This is the footprint of your application. Tune the heap such that the footprint size is at 80 to 85% of your available RAM.

In all these cases, you should tune the heap size, reprofile WebLogic Server with the new heap settings, and analyze the garbage collection information.

If you have a large amount of available free RAM on your machine, consider running more instances of WebLogic Server instead of increasing the heap for one instance.

Setting the JVM Heap Size Options

The most straightforward garbage collection algorithms examine every living object in the heap to check whether it is in use. This technique is prohibitively costly, especially for large Java applications, because the garbage collection algorithm takes time proportional to the number of living objects.

The 1.3 Java HotSpot VM uses a generational garbage collection algorithm that considers the lifetime of an object to avoid the extra collection work. It is based on the basic premise that a majority of objects die young and hence should not be considered for garbage collection at all. To do this, the JVM divides the heap into memory pools holding objects of different ages. The heap is divided into two areas: young and old. The young generation area is further divided into Eden and two survivor areas. There is also a portion of the heap called permanent generation, which holds the classes and method objects (see Figure 28.13).

Division of heap into young and old generational areas in the 1.3 Java HotSpot VM.

Figure 28.13. Division of heap into young and old generational areas in the 1.3 Java HotSpot VM.

New objects are created in the Eden generational area. Because most objects are short lived, they die in this area. One survivor space is kept empty at any time, and it allows for moving objects when the Eden area or the other survivor space fills up. This causes a minor garbage collection. When the number of objects in the survivor space reaches a certain threshold, the objects are moved out from the survivor space into the old generational area. When the old generational area is filled, there is a major or full garbage collection cycle.

The memory management based on the lifetime of objects provides significant improvement in the garbage collection efficiency of the Java HotSpot VM.

Because the default garbage collection parameters were designed for small applications, they are not optimal for large server applications such as WebLogic Server. To achieve optimum performance for your application deployed on WebLogic Server, consider tuning the following parameters depending on your application, client load, and available RAM:

  • Minimum heap size—This is specified with the -Xms option—for example:

    -Xms=64M
    

    This sets the minimum heap with which the JVM starts.

  • Maximum heap size—This is specified with the -Xms option—for example:

    -Xmx=200M
    

    This sets the maximum heap size allocated for the JVM. As more Java objects are created, the heap size will be increased until it reaches this limit.

  • NewRatioThis is specified with the -XX:NewRatio option—for example:

    -XNewRatio=3
    

    This controls the ratio between the young and the old generational areas. In this example, the ratio between young and old areas is 1:3.

    Note

    Because the entire heap is divided into the young and old areas, the larger the young area, the smaller will be the old area. If the ratio divides the heap such that the older area is smaller, this will increase the frequency of the major garbage collection cycles. This ratio should be tuned based on the lifetime distribution of objects created by your application.

  • New generation heap size—This is specified with the -XX:NewSize option—for example:

    -XXNewSize=128M
    

    This sets the minimum young generation size. Increase the young generation heap size if your application creates a large number of short-lived objects.

  • Maximum new generation heap size—This is specified with the -XX:MaxNewSize option—for example:

    XXMaxNewSize=128M
    

    This sets the maximum young generation size.

  • New heap size ratio—This is specified with the -XX:SurvivorRatio option—for example:

    -XX:SurvivorRatio=6
    

    This option configures the ratio between the Eden and survivor spaces. If the ratio is set to 6, the ratio of survivor space to Eden space will be 1:6. Because there are two survivor spaces, each survivor space will be one eighth of the young generation space.

Monitoring the WebLogic Server Heap and Forcing Garbage Collection

The Administration Console allows you to monitor the memory usage of WebLogic Server. To monitor the heap through the console, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance that you want to monitor the heap usage.

  4. Select the Monitoring, Performance tab in the right pane, as shown in Figure 28.3.

  5. Monitor the memory usage graph on this page. The graph shows the total memory in the top-left corner and the actual heap in use above the line graph.

To manually force garbage collection on the server, click the Force Garbage Collection button. If WebLogic Server was started with the -verbosegc option, you will see a Full GC cycle run in the server and the message printed to the stdout when the garbage collection is manually forced through the console.

Detecting Low Memory Conditions in WebLogic Server

WebLogic Server allows you to automatically detect and handle low memory conditions in the server. The server samples the available free memory over a period of time and, depending on the thresholds set, forces garbage collection if a low memory condition is detected.

To configure automatic detection of low memory, follow these steps:

  1. Start the Administration Server and access the Administration Console.

  2. Click the Servers node in the left pane to display the servers configured in your domain.

  3. Click the name of the server instance for which you want to configure the low memory detection.

  4. Select the Configuration, Memory tab in the right pane.

  5. Set the various attributes as follows:

    • Low Memory GCThreshold—Set this value as a percentage to represent the threshold at which the server will perform automatic garbage collection. The default value is 5%, which means that if the amount of free memory drops down to 5% of the free memory available at bootup time, the server will start garbage collection.

    • Low Memory Granularity Level—Set this value as a percentage that will be used by the server to log low memory conditions. The server’s health state is changed to Warning when this threshold is reached. By default, the value is set to 5%. The server samples the free heap periodically, and if the average free memory available drops by 5% or more over two sample intervals, it logs a low memory warning and changes the server’s health to Warning.

    • Low Memory Sample Size—Set this value to set the number of times the server will check the amount of free memory during a fixed time period. The default value is 10.

    • Low Memory Time Interval—Set this value to a time in seconds that will control the frequency at which the server calculates the average free memory. The default value is set to 3600 seconds. By default, the server will determine the average free heap with 10 samples taken over an hour.

  6. Click the Apply button to persist the changes to the config.xml file.

  7. Shut down and restart the server for the changes to take effect.

Summary

WebLogic Server is by far the most performance-proven, battle-tested, and leading J2EE application server in the application infrastructure market today. As a WebLogic Server administrator, you are responsible for ensuring you have throttled as much performance value from WebLogic Server as possible. Opting not to tune the performance of WebLogic Server not only forces your J2EE business solutions to operate in a nonoptimal environment, but you can be hinging the success or failure of a J2EE business solution solely based on its performance. In real-life terms, not performance tuning your WebLogic Server is analogous to buying a Formula One Ferrari and driving it around a Grand Prix track at 50mph.

From all perspectives, performance tuning WebLogic Server is a very time-consuming and meticulous exercise. This chapter has demystified the art of performance tuning WebLogic Server by describing a very easy-to-adopt roadmap, which can help you begin the process of identifying and resolving potential bottlenecks in your WebLogic Server environment. This approach stresses the importance of collaborating with a team of experts who collectively have detailed knowledge of how the entire WebLogic Server environment operates, as well as how performance analysis tools can greatly help you in profiling your WebLogic Server and the applications deployed to it.

This chapter also discussed in detail the concepts, techniques, and monitoring mechanisms for performance tuning the behavior of the primary aspects of WebLogic Server, from where you can derive performance value, such as execute threads, JDBC connection pools, the EJB container, HTTP sessions, and the memory management options of the JVM. You will be responsible for performance tuning all these elements as a WebLogic Server administrator.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset