You are on page 1of 33

WebLogic Optimization Basics Guide#9

Description: BISP is committed to provide BEST learning material to the beginners and advance learners. In the same series, we have prepared a list of WebLogic learning documents for beginners and Advance learner. The given documents specify various parameters for WebLogic Performance related activities in Linux Operating System. Join our professional training program and learn from experts.

History: Version 0.1 2011 0.1

Description Change Author Initial Draft Kuldeep Review#1 Amit Sharma

Publish Date 12th Aug 18th Aug 2011

www.bispsolutions.com Page 1

www.bisptrainigs.com

www.hyperionguru.com

Contents
Understanding Performance Tuning and Oracle WebLogic Portal..................................3 Top Tuning Recommendations for WebLogic Server......................................................5 ....................................................................................................................................... 6 1. Tune Pool Sizes......................................................................................................... 6 2 Use the Prepared Statement Cache............................................................................6 4 Tune Connection Backlog Buffering...........................................................................6 5 Tune the Chunk Size..................................................................................................6 6 Use Optimistic or Read-only Concurrency.................................................................6 7 Use Local Interfaces...................................................................................................7 8 Use eager-relationship-caching..................................................................................7 9 Tune HTTP Sessions................................................................................................... 7 10 Tune Messaging Applications...................................................................................7 Understand Our Performance Objectives......................................................................7 Measure Our Performance Metrics..............................................................................8 Monitor Disk and CPU Utilization..................................................................................8 Linux CPU Utilization : ................................................................................9 ..................................................................................................................................... 33

www.bispsolutions.com Page 2

www.bisptrainigs.com

www.hyperionguru.com

Understanding Performance Tuning and Oracle WebLogic Portal


Performance tuning is a process which spans development, staging and deployment. During all phases, performance should be monitored and appropriate adjustments made. We establish an environment where we can performance test the installation for the following reasons: Testing under realistic load may uncover bugs not seen during development or QA. Testing our prototype under load will help us validate design decisions early in the development cycle that may significantly alter the performance of our application. Any configuration change can dramatically affect application performance (hardware, database, clustering environment, application tuning parameters, and so on). Load testing our application whenever design changes are made provides a way to narrow down performance problems to a particular area. Testing early and often increases the likelihood that our site implementation and deployment will perform well. The recommended approach for performance testing is to start with the simplest aspect of the installation and then move into areas of increased complexity. If we observe slow behavior in any portion of this testing process, we should begin a more thorough investigation into its causes.

General Architecture
First, perform the following steps to identify performance issues with our network, database, or other software that is independent of WebLogic Portal. 1. Test our database (independent of any web components) to determine how well our schema and SQL work. Note any areas where the schema or SQL may not be optimized for performance. 2. Test our network for sufficient bandwidth, and check that the TCP/IP parameters on the servers operating system can sufficiently handle the application load we expect. It is possible that the network is the slowest aspect of our deployment. Ensure that our IP Multicast for cluster deployment is configured correctly. Test our web server, ensuring that it has sufficient capacity to serve static HTML pages when many concurrent threads are running. 3. Ensure that we have enough resources available to meet application requirements. Most large applications are clustered, but keep in mind that a clustered environment requires resources to perform load-balancing tasks. 4. Test our servlet engine by running a load test against a trivial servlet such as a HelloWorld servlet. If this simple servlet does not perform and scale horizontally (meaning that as we add Java Virtual Machines, performance
www.bispsolutions.com Page 3 www.bisptrainigs.com www.hyperionguru.com

increases accordingly), the performance problems we encounter may be related to an infrastructure or resource issue.

www.bispsolutions.com Page 4

www.bisptrainigs.com

www.hyperionguru.com

WebLogic Portal After performing the steps in the General Architecture, perform the following steps to identify performance issues with WebLogic Portal: 1. Verify that our Oracle WebLogic Portal database configuration is optimal WebLogic Portal makes extensive use of the database. Check that our connection pool is large enough and verify that our database handles connection failures in an efficient manner. For example, the size of the JDBC connection pool should be set to handle the maximum number of concurrent users as possible, and it should be set on server startup rather than growing as connections are needed. This will increase the server startup time but will decrease the overhead creating those connections under server load.. 2. Verify that each portlet is optimized for speed as follows i)If a portlet uses forms that update the data within the portlet this will cause the entire portal to refresh its data, which can be very time consuming. Therefore, portlets that have this behavior should have asynchronous rendering enabled via AJAX or iFrames so that the overall rendering of the portal is not affected. AJAX is supported at the portal desktop and individual portlet levels. ii)Place items that require heavy processing in an edit page or a maximized URL. If we do not, the portal must wait for the portlet to process, and this considerably slows down the eventual rendering of the portal. Process intensive portlets may benefit from parallel portlet rendering (also known as pre-render and render forking.). iii) Enable caching on portlets that do not rely on dynamic data. 3. Test our applications components. Test our applications components, starting from the data access layer. Then proceed toward the GUI one step at a time. Pay attention to performance and scalability differences at each component and between each layer of our application. Finally, do end-to-end testing from a browser-based load-testing tool. 4. Test the behavior and performance of our application under simulated, real-world conditions. Be sure to use both anonymous and logged-in users simultaneously.

Top Tuning Recommendations for WebLogic Server


Tuning WebLogic Server and our WebLogic Server application is a complex and iterative process. To get our started, we have created a short list of recommendations to help us optimize our application's performance. These tuning techniques are applicable to nearly all WebLogic applications. 1 "Tune Pool Sizes" 2 "Use the Prepared Statement Cache" 3 "Use Logging Last Resource Optimization" 4 "Tune Connection Backlog Buffering" 5 "Tune the Chunk Size" 6 "Use Optimistic or Read-only Concurrency" 7"Use Local Interfaces" 8 "Use eager-relationship-caching"
www.bispsolutions.com Page 5 www.bisptrainigs.com www.hyperionguru.com

9"Tune HTTP Sessions" 10 "Tune Messaging Applications"

1. Tune Pool Sizes


Provide pool sizes (such as pools for JDBC connections, Stateless Session EJBs, and MDBs) that maximize concurrency for the expected thread utilization. A server instance uses a self-tunedthread-pool. The best way to determine the appropriate pool size is to monitor the pool's current size, shrink counts, grow counts, and wait counts. Tuning MDBs are a special case, In general, the number of connections should equal the number of threads that are expected to be required to process the requests handled by the pool. The most effective way to ensure the right pool size is to monitor it and make sure it does not shrink and grow.

2 Use the Prepared Statement Cache

The prepared statement cache keeps compiled SQL statements in memory, thus avoiding a round-trip to the database when the same statement is used later.

3 Use Logging Last Resource Optimization


When using transactional database applications, consider using the JDBC data source Logging Last Resource (LLR) transaction policy instead of XA. The LLR optimization can significantly improve transaction performance by safely eliminating some of the 2PC XA overhead for database processing, especially for two-phase commit database insert, update, and delete operations.

4 Tune Connection Backlog Buffering

We can tune the number of connection requests that a WebLogic Server instance accepts before refusing additional requests. This tunable applies primarily for Web applications.

5 Tune the Chunk Size


A chunk is a unit of memory that the WebLogic Server network layer, both on the client and server side, uses to read data from and write data to sockets. A server instance maintains a pool of these chunks. For applications that handle large amounts of data per request, increasing the value on both the client and server sides can boost performance.

6 Use Optimistic or Read-only Concurrency

Use optimistic concurrency with cache-between-transactions or read-only concurrency with query-caching for CMP EJBs wherever possible. Both of these two options leverage the Entity Bean cache provided by the EJB container.
www.bispsolutions.com Page 6 www.bisptrainigs.com www.hyperionguru.com

i) Optimistic-concurrency with cache-between-transactions work best with readmostly beans. Using verify-reads in combination with these provides high data consistency guarantees with the performance gain of caching. ii) Query-caching is a WebLogic Server 9.0 feature that allows the EJB container to cache results for arbitrary non-primary-key finders defined on read-only EJBs. All of these parameters can be set in the application/module deployment descriptors.

7 Use Local Interfaces


Use local-interfaces or use call-by-reference semantics to avoid the overhead of serialization when one EJB calls another or an EJB is called by a servlet/JSP in the same application. Note the following: i)In Weblogic Server call-by-reference is turned on by default. For releases of WebLogic Server, call-by-reference is turned off by default. Older applications migrating to WebLogic Server 8.1 and higher that do not explicitly turn on call-by-reference may experience a drop in performance. ii) This optimization does not apply to calls across different applications. Use eager-relationship-caching wherever possible. This feature allows the EJB container to load related beans using a single SQL statement. It improves performance by reducing the number of database calls to load related beans in transactions when a bean and it's related beans are expected to be used in that transaction.

8 Use eager-relationship-caching

9 Tune HTTP Sessions


Optimize our application so that it does as little work as possible when handling session persistence and sessions. We should also design a session management strategy that suits our environment and application. Oracle provides messaging users a rich set of performance tunables. In general, we should always configure quotas and paging.

10 Tune Messaging Applications

Understand Our Performance Objectives


To determine our performance objectives, we need to understand the application deployed and the environmental constraints placed on the system. Gather information about the levels of activity that components of the application are expected to meet, such as: i) The anticipated number of users. ii) The number and size of requests. iii) The amount of data and its consistency.

www.bispsolutions.com Page 7

www.bisptrainigs.com

www.hyperionguru.com

iv) Determining your target CPU utilization. Our target CPU usage should not be 100%, we should determine a target CPU utilization based on our application needs, including CPU cycles for peak usage. If our CPU utilization is optimized at 100% during normal load hours, we have no capacity to handle a peak load. In applications that are latency sensitive and maintaining the ability for a fast response time is important, high CPU usage (approaching 100% utilization) can reduce response times while throughput stays constant or even increases because of work queuing up in the server. For such applications, a 70% - 80% CPU utilization recommended. A good target for nonlatency sensitive applications is about 90%. Performance objectives are limited by constraints, such as v) The configuration of hardware and software such as CPU type, disk size vs. disk speed, sufficient memory. There is no single formula for determining our hardware requirements. The process of determining what type of hardware and software configuration is required to meet application needs adequately is called capacity planning. Capacity planning requires assessment of our system performance goals and an understanding of our application. Capacity planning for server hardware should focus on maximum performance requirements. vi) The ability to interoperate between domains, use legacy systems, support legacy data. vii)Development, implementation, and maintenance costs. We will use this information to set realistic performance objectives for our application environment, such as response times, throughput, and load on specific hardware.

Measure Our Performance Metrics


After we have determined our performance criteria take measurements of the metrics we will use to quantify our performance objectives. The following sections provide information on measuring basic performance metrics: Run our application under a high load while monitoring the: i) Application server (disk and CPU utilization) ii) Database server (disk and CPU utilization) The goal is to get to a point where the application server achieves our target CPU utilization. If we find that the application server CPU is underutilized, confirm whether the database is bottle necked. If the database CPU is 100 percent utilized, then check our application SQL calls query plans. For example, are our SQL calls using indexes or doing linear searches? Also, confirm whether there are too many ORDER BY clauses used in our application that are affecting the database CPU. If we discover that the database disk is the bottleneck (for example, if the disk is 100 percent utilized), try moving to faster disks or to a RAID (redundant array of
www.bispsolutions.com Page 8 www.bisptrainigs.com www.hyperionguru.com

Monitor Disk and CPU Utilization

independent disks) configuration, assuming the application is not doing more writes then required.

Linux CPU Utilization :


Whenever a Linux system CPU is occupied by a process, it is unavailable for processing other requests. Rest of pending requests must wait till CPU is free. This becomes a bottleneck in the system. Following command will help you to identify CPU utilization, so that you can troubleshoot CPU related performance problems. Finding CPU utilization is one of the important tasks. Linux comes with various utilities to report CPU utilization. With these commands, you will be able to find out: * CPU utilization * Display the utilization of each CPU individually (SMP cpu) * Find out your system's average CPU utilization since the last reboot etc * Determine which process is eating the CPU(s) Top command to find out Linux cpu usage Type the top command:

Command Output:

www.bispsolutions.com Page 9

www.bisptrainigs.com

www.hyperionguru.com

You can see Linux CPU utilization under CPU stats. The tasks share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment (multiple CPUS), top will operate in number of CPUs. Please note that you need to type q key to exit the top command display. The top command produces a frequently-updated list of processes. By default, the processes are ordered by percentage of CPU usage, with only the "top" CPU consumers shown. The top command shows how much processing power and memory are being used, as well as other information about the running processes. type q key to exit the top command display.

www.bispsolutions.com Page 10

www.bisptrainigs.com

www.hyperionguru.com

Display the utilization of each CPU individually using mpstat If you are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually. It report processors related statistics. For example, type command:

Command Output:

www.bispsolutions.com Page 11

www.bisptrainigs.com

www.hyperionguru.com

The mpstat command display activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.:

Command Output:

Another output from my HP Dual Opteron 64 bit server: Type the mpstat -P ALL command

www.bispsolutions.com Page 12

www.bisptrainigs.com

www.hyperionguru.com

Report CPU utilization using sar command You can display todays CPU activity, with sar command:

Command Output:

Comparison of CPU utilization The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters. For example display comparison of CPU utilization; 2 seconds apart; 5 times, use:

www.bispsolutions.com Page 13

www.bisptrainigs.com

www.hyperionguru.com

Output (for each 2 seconds. 5 lines are displayed):

Where, -u 12 5 : Report CPU utilization. The following values are displayed: a) %user: Percentage of CPU utilization that occurred while executing at the user level (application). b) %nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority. c) %system: Percentage of CPU utilization that occurred while executing at the system level (kernel). d) %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. e) %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. To get multiple samples and multiple reports set an output file for the sar command. Run the sar command as a background process using. Type the sar -u 2 5 command

www.bispsolutions.com Page 14

www.bisptrainigs.com

www.hyperionguru.com

Better use nohup command so that you can logout and check back report later on:

Find out who is monopolizing or eating the CPUs Finally, you need to determine which process is monopolizing or eating the CPUs. Following command will displays the top 10 CPU users on the Linux system.

OR # ps -eo pcpu,pid,user,args | sort -r -k1 | less Command Output:

www.bispsolutions.com Page 15

www.bisptrainigs.com

www.hyperionguru.com

Now you know vmware-vmx process is eating up lots of CPU power. ps command displays every process (-e) with a user-defined format (-o pcpu). First field is pcpu (cpu utilization). It is sorted in reverse order to display top 10 CPU eating process. iostat command You can also use iostat command which report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions. It can be use to find out your system's average CPU utilization since the last reboot.

Command Output:

www.bispsolutions.com Page 16

www.bisptrainigs.com

www.hyperionguru.com

You may want to use following command, which gives you three outputs every 5 seconds (as previous command gives information since the last reboot):

Command Output:

GUI tools for your laptops/desktops


www.bispsolutions.com Page 17 www.bisptrainigs.com www.hyperionguru.com

Above tools/commands are quite useful on remote server. For local system with X GUI installed you can try out gnome-system-monitor. It allows you to view and control the processes running on your system. You can access detailed memory maps, send signals, and terminate the processes.

Command Output:

In addition, the gnome-system-monitor provides an overall view of the resource usage on your system, including memory and CPU allocation.

www.bispsolutions.com Page 18

www.bisptrainigs.com

www.hyperionguru.com

Linux Disk utilization: You can use same iostat command to find out disk utilization and for monitoring system input/output device loading by observing the time the physical disks are active in relation to their average transfer rates. iostat syntax for disk utilization report

Command Output:

-d : Display the device utilization report (d == disk) -x : Display extended statistics including disk utilization

www.bispsolutions.com Page 19

www.bisptrainigs.com

www.hyperionguru.com

interval : It is time period in seconds between two samples . iostat 2 will give data at each 2 seconds interval. count : It is the number of times the data is needed . iostat 2 5 will give data at 2 seconds interval 5 times

Display 3 reports of extended statistics at 5 second intervals for disk Type the iostat -d -x 5 3 command:

Monitor Data Transfers Across the Network Check the amount of data transferred between the application and the application server, and between the application server and the database server. This amount should not exceed our network bandwidth; otherwise, our network becomes the bottleneck. Locate Bottlenecks in Your System If you determine that neither the network nor the database server is the bottleneck, start looking at our operating system, JVM, and WebLogic Server configurations. Most importantly, is the machine running WebLogic Server able to get our target CPU utilization with a high client load? If the answer is no, then check if there is any locking taking place in the application. We should profile our application using a commercially available tool (for example, JProbe or OptimizeIt) to pinpoint bottlenecks and improve application performance. Minimize Impact of Bottlenecks
www.bispsolutions.com Page 20 www.bisptrainigs.com www.hyperionguru.com

In this step, we tune our environment to minimize the impact of bottlenecks on our performance objectives. It is important to realize that in this step you are minimizing the impact of bottlenecks, not eliminating them. Tuning allows us to adjust resources to achieve our performance objectives. i)Tune Our Application ii)Tune Our DB iii)Tune WebLogic Server Performance Parameters iv)Tune Our JVM v)Tune the Operating System vi)Tuning the WebLogic Persistent Store Tune Our Application To quote the authors of Oracle WebLogic Server: Optimizing WebLogic Server Performance: "Good application performance starts with good application design. Overlycomplex or poorly-designed applications will perform poorly regardless of the system-level tuning and best practices employed to improve performance." In other words, a poorly designed application can create unnecessary bottlenecks. For example, resource contention could be a case of poor design, rather than inherent to the application domain. Tune Our DB Our database can be a major enterprise-level bottleneck. Database optimization can be complex and vender dependent. Tune WebLogic Server Performance Parameters The WebLogic Server uses a number of OOTB (out-of-the-box) performancerelated parameters that can be fine-tuned depending on your environment and applications. Tuning these parameters based on your system requirements (rather than running with default settings) can greatly improve both single-node performance and the scalability characteristics of an application. . Tune Our JVM The Java virtual machine (JVM) is a virtual "execution engine" instance that executes the bytecodes in Java class files on a microprocessor. Tune the Operating System
www.bispsolutions.com Page 21 www.bisptrainigs.com www.hyperionguru.com

Each operating system sets default tuning parameters differently. For Windows platforms, the default settings are usually sufficient. However, the UNIX and Linux operating systems usually need to be tuned appropriately. Achieve Performance Objectives Performance tuning is an iterative process. After you have minimized the impact of bottlenecks on your system, and determine if you have met your performance objectives. Tuning Tips This section provides tips and guidelines when tuning overall system performance: 1.Performance tuning is not a silver bullet. Simply put, good system performance depends on: good design, good implementation, defined performance objectives, and performance tuning. 2.Performance tuning is ongoing process. Implement mechanisms that provide performance metrics which we can compare against our performance objectives, allowing us to schedule a tuning phase before our system fails. 3.The object is to meet our performance objectives, not eliminate all bottlenecks. Resources within a system are finite. By definition, at least one resource (CPU, memory, or I/O) will be a bottleneck in the system. Tuning allows us minimize the impact of bottlenecks on our performance objectives. 4.Design our applications with performance in mind: i) Keep things simple - avoid inappropriate use of published patterns. ii) Apply Java EE performance patterns. iii) Optimize our Java code. Setting TCP Parameters With the ndd Command This section lists important TCP tuning parameters that when tuned, can enhance application performance: /dev/tcp /dev/tcp /dev/tcp /dev/tcp /dev/tcp /dev/tcp /dev/tcp /dev/tcp /dev/tcp /dev/tcp tcp_time_wait_interval tcp_conn_req_max_q tcp_conn_req_max_q0 tcp_ip_abort_interval tcp_keepalive_interval tcp_rexmit_interval_initial tcp_rexmit_interval_max tcp_rexmit_interval_min tcp_smallest_anon_port tcp_xmit_hiwat
www.bisptrainigs.com www.hyperionguru.com

www.bispsolutions.com Page 22

/dev/tcp tcp_recv_hiwat /dev/ce instance /dev/ce rx_intr_time Tip: Use the netstat -s -P tcp command to view all available TCP parameters.
Set TCP-related tuning parameters using the ndd command, as demonstrated in the following example: Note ndd -set /dev/tcp tcp_conn_req_max_q : 16384

Setting Parameters In the /etc/system File This section lists important /etc/system file tuning parameters that when tuned, can enhance application performance. Each socket connection to the server consumes a file descriptor. To optimize socket performance, we may need to configure our operating system to have the appropriate number of file descriptors. Therefore, we should change the default file descriptor limits, as well as the hash table size and other tuning parameters in the /etc/system file. Not We must reboot our machine anytime we modify /etc/system parameters. e: set rlim_fd_cur set rlim_fd_max set tcp:tcp_conn_hash_size (Solaris 8 and 9)
set ip:ipcl_conn_hash_size (Solaris 10) set shmsys:shminfo_shmmax Note: This should only be set for machines that have at least 4 GB RAM or higher.

set autoup set tune_t_fsflushr CE Gigabit Network Card Settings This section lists important CE Gigabit Network Card tuning parameters that when tuned, can enhance application performance: set ce:ce_bcopy_thresh set ce:ce_dvma_thresh set ce:ce_taskq_disable set ce:ce_ring_size set ce:ce_comp_ring_size set ce:ce_tx_ring_size Linux Tuning Parameters This section lists important Linux tuning parameters that when adjusted, can enhance application performance: /sbin/ifconfig lo mtu kernel.msgmni kernel.sem fs.file-max
www.bispsolutions.com Page 23 www.bisptrainigs.com www.hyperionguru.com

kernel.shmmax net.ipv4.tcp_max_syn_backlog. HP-UX Tuning Parameters This section lists important HP-UX operating system tuning parameters that when adjusted, can enhance application performance: tcp_conn_req_max tcp_xmit_hiwater_def tcp_ip_abort_interval tcp_rexmit_interval_initial tcp_keepalive_interval Windows Tuning Parameters For Windows platforms, the default settings are usually sufficient. However, under sufficiently heavy loads it may be necessary to adjust the MaxUserPort and TcpTimedWaitDelay. These parameters determine the availability of user ports requested by an application.

By default, ephemeral (that is, short-lived) ports are allocated between the values of 1024 and 5000 inclusive using the MaxUserPort parameter. The TcpTimedWaitDelay parameter, which controls the amount of time the OS waits to reclaim a port after an application closes a TCP connection, has a default value of 4 minutes. During a heavy loads, these limits may be exceeded resulting in an address in use: connect exception. If we experience address in use: connect exceptions try setting the MaxUserPort and TcpTimedWaitDelay registry values under the

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
key: MaxUserPort = dword:00004e20 (20,000 decimal) TcpTimedWaitDelay = dword:0000001e (30 decimal) Increase the value of the MaxUserPort parameter if the exception persists. .

Other Operating System Tuning Information Maximum memory for a user process Check our operating system documentation for the maximum memory available for a user process. In some operating systems, this value is as low as 128 MB. Also, refer to our operating system documentation. Tuning Java Virtual Machines (JVMs) The Java virtual machine (JVM) is a virtual execution engine instance that executes the bytecodes in Java class files on a microprocessor. How we tune our JVM affects the performance of WebLogic Server and our applications. envelope
The following sections discuss JVM tuning options for WebLogic Server: 1)JVM Tuning Considerations 2)Which JVM for Our System? 3)Garbage Collection 4)Enable Spinning for IA32 Platforms www.bispsolutions.com Page 24 www.bisptrainigs.com www.hyperionguru.com

JVM Tuning Considerations JVM tuning considerations for WebLogic Server. Tuning Factor JVM vendor and version Information Reference Use only production JVMs on which WebLogic Server has been certified. This release of WebLogic Server supports only those JVMs that are J2SE 5.0-compliant. For WebLogic Server heap size tuning details Depending on our application, there are a number of GC schemes available for managing our system memory Deployments using different JVM versions for the client and server are supported in WebLogic Server Choices we make about Solaris threading models can have a large impact on the performance of our JVM on Solaris. We can choose from multiple threading models and different methods of synchronization within the model, but this varies from JVM to JVM

Tuning heap size and garbage collection Choosing a GC (garbage collection) scheme Mixed client/server JVMs

UNIX threading models

Which JVM for Our System? Although this section focuses on Sun Microsystems J2SE 5.0 JVM for the Windows, UNIX, and Linux platforms, the BEA JRockit JVM was developed expressly for server-side applications and optimized for Intel architectures to ensure reliability, scalability, manageability, and flexibility for Java applications.

Garbage Collection
Garbage collection is the VMs process of freeing up unused Java objects in the Java heap. The following sections provide information on tuning our VMs garbage collection:
1. 2. 3. 4. 5. 6. 7. VM Heap Size and Garbage Collection Choosing a Garbage Collection Scheme Using Verbose Garbage Collection to Determine Heap Size Specifying Heap Size Values Automatically Logging Low Memory Conditions Manually Requesting Garbage Collection Requesting Thread Stacks

VM Heap Size and Garbage Collection


www.bispsolutions.com Page 25 www.bisptrainigs.com www.hyperionguru.com

The Java heap is where the objects of a Java program live. It is a repository for live objects, dead objects, and free memory. When an object can no longer be reached from any pointer in the running program, it is considered garbage and ready for collection. A best practice is to tune the time spent doing garbage collection to within 5% of execution time. The JVM heap size determines how often and how long the VM spends collecting garbage. An acceptable rate for garbage collection is application-specific and should be adjusted after analyzing the actual time and frequency of garbage collections. If we set a large heap size, full garbage collection is slower, but it occurs less frequently. If we set our heap size in accordance with our memory needs, full garbage collection is faster, but occurs more frequently. The goal of tuning our heap size is to minimize the time that our JVM spends doing garbage collection while maximizing the number of clients that WebLogic Server can handle at a given time. To ensure maximum performance during benchmarking, we might set high heap size values to ensure that garbage collection does not occur during the entire run of the benchmark. We might see the following Java error if we are running out of heap space: java.lang.OutOfMemoryError <<no stack trace available>> java.lang.OutOfMemoryError <<no stack trace available>> Exception in thread "main"

Increase heap size: We can Increase jvm heap size from the console.
Goto Environment-->Server-->ManagedServer_1-->General(Server start)-->Argument Enter the below entry in arguments -Xms1024m -Xmx1024m -XX:MaxPermSize=256m

www.bispsolutions.com Page 26

www.bisptrainigs.com

www.hyperionguru.com

If we want to do the same from back end Then Follow the below steps Make changes in SetdomainEnv.sh location Weblogic_home/user_projects/domains/base_domain/bin if [ "${JAVA_VENDOR}" = "Sun" ] ; then WLS_MEM_ARGS_64BIT="-Xms1024m -Xmx1024m" export WLS_MEM_ARGS_64BIT WLS_MEM_ARGS_32BIT="-Xms1024m -Xmx1024m" export WLS_MEM_ARGS_32BIT After making these changes excute SetdomainEnv.sh and Just restart the managed server Choosing a Garbage Collection Scheme Depending on which JVM we are using, we can choose from several garbage collection schemes to manage our system memory. For example, some garbage collection schemes are more appropriate for a given type of application. Once we have an understanding of the workload of the application and the different garbage collection algorithms utilized by the JVM, we can optimize the configuration of the garbage collection. Using Verbose Garbage Collection to Determine Heap Size www.bispsolutions.com Page 27 www.bisptrainigs.com www.hyperionguru.com

The verbose garbage collection option (verbosegc) enables us to measure exactly how much time and resources are put into garbage collection. To determine the most effective heap size, turn on verbose garbage collection and redirect the output to a log file for diagnostic purposes. The following steps outline this procedure: 1.Monitor the performance of WebLogic Server under maximum load while running our application. 2.Use the -verbosegc option to turn on verbose garbage collection output for our JVM and redirect both the standard error and standard output to a log file. This places thread dump information in the proper context with WebLogic Server informational and error messages, and provides a more useful log for diagnostic purposes. For example, on Windows and Solaris, enter the following:

% java -ms32m -mx200m -verbosegc -classpath $CLASSPATH -Dweblogic.Name=%SERVER_NAME% -Dbea.home="C:\bea" -Dweblogic.management.username=%WLS_USER% -Dweblogic.management.password=%WLS_PW% -Dweblogic.management.server=%ADMIN_URL% -Dweblogic.ProductionModeEnabled=%STARTMODE% -Djava.security.policy="%WL_HOME%\server\lib\weblogic.policy" weblogic.Server >> logfile.txt 2>&1
where the logfile.txt 2>&1 command redirects both the standard error and standard output to a log file. On HPUX, use the following option to redirect stderr stdout to a single file:

-Xverbosegc:file=/tmp/gc$$.out
where $$ maps to the process ID (PID) of the Java process. Because the output includes timestamps for when garbage collection ran, we can infer how often garbage collection occurs. 1.Analyze the following data points: a. How often is garbage collection taking place? In the weblogic.log file, compare the time stamps around the garbage collection. b. How long is garbage collection taking? Full garbage collection should not take longer www.bispsolutions.com Page 28 www.bisptrainigs.com www.hyperionguru.com

than 3 to 5 seconds. c. What is our average memory footprint? In other words, what does the heap settle back down to after each full garbage collection? If the heap always settles to 85 percent free, we might set the heap size smaller. 4.Review the New generation heap sizes (Sun) or Nursery size (BEA Jrockit). 1.Make sure that the heap size is not larger than the available free RAM on our system. Use as large a heap size as possible without causing our system to swap pages to disk. The amount of free RAM on our system depends on our hardware configuration and the memory requirements of running processes on our machine. See our system administrator for help in determining the amount of free RAM on our system. 2.If we find that our system is spending too much time collecting garbage (our allocated virtual memory is more than our RAM can handle), lower our heap size. Typically, we should use 80 percent of the available RAM (not taken by the operating system or other processes) for our JVM. 3.If we find that we have a large amount of available free RAM remaining, run more instances of WebLogic Server on our machine. Remember, the goal of tuning our heap size is to minimize the time that our JVM spends doing garbage collection while maximizing the number of clients that WebLogic Server can handle at a given time. Specifying Heap Size Values System performance is greatly influenced by the size of the Java heap available to the JVM. This section describes the command line options we use to define the heap sizes values. We must specify Java heap size values each time we start an instance of WebLogic Server. This can be done either from the java command line or by modifying the default values in the sample startup scripts that are provided with the WebLogic distribution for starting WebLogic Server. 1.Tuning Tips for Heap Sizes 2. BEA JRockit JVM Heap Size Options 3. Java HotSpot VM Heap Size Options Tuning Tips for Heap Sizes The following section provides general guidelines for tuning VM heap sizes: i) The heap sizes should be set to values such that the maximum amount of memory used by the VM does not exceed the amount of available physical RAM. If this value is exceeded, the OS starts paging and performance degrades significantly. The VM always uses more memory than the heap size. The memory required for internal VM www.bispsolutions.com Page 29 www.bisptrainigs.com www.hyperionguru.com

functionality, native libraries outside of the VM, and permanent generation memory (for the Sun VM only: memory required to store classes and methods) is allocated in addition to the heap size settings. ii) When using a generational garbage collection scheme, the nursery size should not exceed more than half the total Java heap size. Typically, 25% to 40% of the heap size is adequate. iii) In production environments, set the minimum heap size and the maximum heap size to the same value to prevent wasting VM resources used to constantly grow and shrink the heap. This also applies to the New generation heap sizes (Sun) or Nursery size (BEA Jrockit). BEA JRockit JVM Heap Size Options Although BEA JRockit provides automatic heap resizing heuristics, they are not optimal for all applications. In most situations, best performance is achieved by tuning the VM for each application by adjusting the heaps size options.

BEA JRockit JVM Heap Size Options


Task Setting the Nursery Options Comments Optimally, we should try to make the nursery as large as possible while still keeping the garbage collection pause times acceptably low. This is particularly important if our application is creating a lot of temporary objects. The maximum size of a nursery cannot exceed 95% of the maximum heap size. Setting minimum heap size -Xms BEA recommends setting the minimum heap size (Xms) equal to the maximum heap size (-Xmx) to minimize garbage collections. Setting a low maximum heap value compared to the amount of live data decrease performance by forcing frequent garbage collections.

-Xns

Setting maximum heap size Setting garbage collection Performs adaptive optimizations as early as possible in the Java

-Xmx

-Xgc: parallel XXaggressive :memory


To do this, the bottleneck detector will run with a higher frequency from the start and then gradually lower its frequency. This options also tells BEA JRockit to use the available memory aggressively.

www.bispsolutions.com Page 30

www.bisptrainigs.com

www.hyperionguru.com

application run. Java HotSpot VM Heap Size Options We achieve best performance by individually tuning each application. However, configuring the Java HotSpot VM heap size options listed in when starting WebLogic Server increases performance for most applications. These options may differ depending on our architecture and operating system. See our vendors documentation for platform-specific JVM tuning options. Java Heap Size Options Task Setting the New generation heap size Option Comments As a general rule, set -XX:NewSize to be one-fourth the size of the heap size. Increase the value of this option for larger numbers of short-lived objects. Be sure to increase the New generation as we increase the number of processors. Memory allocation can be parallel, but garbage collection is not parallel. Setting the maximum New generation heap size Setting New heap size ratios

-XX:NewSize

-XX:MaxNewSize

Set the maximum size of the New Generation heap size. The New generation area is divided into three sub-areas: Eden, and two survivor spaces that are equal in size. Configure the ratio of the Eden/survivor space size. Try setting this value to 8, and then monitor our garbage collection.

XX:SurvivorRat io

Setting minimum heap size

Xm s

As a general rule, set minimum heap size (-Xms) equal to the maximum heap size (-Xmx) to minimize garbage collections. Set the maximum size of the heap.

Setting maximum heap size Setting Big Heaps and Intimate Shared www.bispsolutions.com Page 31

-Xmx -XX:+UseISM -XX:

www.bisptrainigs.com

www.hyperionguru.com

Memory

+AggressiveHeap

Other Java HotSpot VM Options Sun provides other standard and non-standard command-line options to improve the performance of our VM. How we use these options depends on how our application is coded. Test both our client and server JVMs to see which options perform better for our particular application. The Sun Microsystems Java HotSpot VM Options document provides information on the command-line options and environment variables that can affect the performance characteristics of the Java HotSpot Virtual Machine. Automatically Logging Low Memory Conditions WebLogic Server enables us to automatically log low memory conditions observed by the server. WebLogic Server detects low memory by sampling the available free memory a set number of times during a time interval. At the end of each interval, an average of the free memory is recorded and compared to the average obtained at the next interval. If the average drops by a user-configured amount after any sample interval, the server logs a low memory warning message in the log file and sets the server health state to warning. Manually Requesting Garbage Collection We may find it necessary to manually request full garbage collection from the Administration Console. When we do, remember that garbage collection is costly as the JVM often examines every living object in the heap. Requesting Thread Stacks We may find it necessary to display thread stacks while tuning our applications Enable Spinning for IA32 Platforms If we are running a high-stress application with heavily contended locks on a multiprocessor system,we can attempt to improve performance by using spinning. This option enables the ability to spin the lock for a short time before going to sleep. Sun JDK Sun has changed the default lock spinning behavior in JDK 5.0 on the Windows IA32 platform. For the JDK 5.0 release, lock spinning is disabled by default. For this release, BEA has explicitly enabled spinning in the environment scripts used to start WebLogic Server. To enable spinning, use the following VM option: -XX:+UseSpinning BEA JRockit The BEA JRockit VM automatically adjusts the spinning for different locks, eliminating the need set this parameter.

www.bispsolutions.com Page 32

www.bisptrainigs.com

www.hyperionguru.com

www.bispsolutions.com Page 33

www.bisptrainigs.com

www.hyperionguru.com

You might also like