JBoss AS 7 Performance Tuning (1)

Source: Internet
Author: User
Tags jboss application server

Original article: http://www.mastertheboss.com/jboss-performance/jboss-as-7-performance-tuning

 

JBoss Application Server Tuning

Although many architects and software engineers agree that the performance of about 70-80% of applications depends on the code of the application itself, improper configuration of the server environment can significantly affect your user experience, and ultimately affect the performance of your application.

Many configuration elements can significantly affect the performance of your server. Some of their configurations deserve special attention:

• JVM Tuning
• Application Server resource pool
• Logs
• Cache data

Let's take a look at the details of each element.

JVM Optimization

JBoss AS7 running in Java Virtual Machine (JVM) can provide better performance with the correct configuration of JVM parameters.

JVM optimization has been developed for many years. In fact, every Java version has changed. In J2SE version 5.0, JVM provides some default configurations ("ergonomics") that are consistent with your environment "). However, Ergonomics does not always provide the optimal smart choice, and the performance may be lower than you expected when the user settings are inappropriate.

Basically, the JVM optimization process can be divided into the following steps:

• Select a correct JVM heap size. It is divided into a suitable initial heap value (-Xms) and a maximum heap value (-Xmx ).
• Select an appropriate garbage collection algorithm.

Let's take a look at the details of these two elements.

Select the appropriate JVM heap size

Java objects are created on the stack. Each heap is divided into three parts or three garbage collection generations (Young generation), Old generation (TenuredOrOld generation), And permanent generation (Permanent).

The new generation can be further divided into three spaces: Eden, Alibaba vor 1, and Alibaba vor 2. When an object is first created in the heap, it is created in the Eden space of the new generation, and after the subsequent generation GC (minor GC), if the object survive, it is transferred to ikevor 1 and then moved to ikevor 2 until the age GC (major GC) occurs, and the object is moved to the age.

The permanent substitution space is special. It is used to store the metadata of classes and methods in JVM, and also stores the String pool provided in JVM.

To adjust the JVM, you should select the correct ratio between the new generation (where the object was originally placed after instantiation) and the old generation (where the object with a long retention period is moved here.

For most applications, the correct ratio between the new generation and the old generation is between 1/3 and 1/2.

The appropriate heap maximum value can be determined by testing within a period of time that enables your application to Load peak loads. Once you have determined the memory quota required by the application, depending on the nature of the application, you can add an additional 25-40% memory as the maximum heap value.

As for the initial heap size, a good rule is to set it to the same as the maximum value of the heap. This increases predictability and avoids extending the heap when memory needs to be allocated. This is especially useful in the production environment, and developers (with limited resources) may choose a smaller initial heap size.

We recommend that you keep this configuration as a small environment. It can also be used as a reference for a larger environment:
Java-Xmx1024m-Xms1024m-XX: MaxNewSize = 448m-XX: NewSize = 448 m-XX: Export vorratio = 6
Java-Xmx2048m-Xms2048m-XX: MaxNewSize = 896m-XX: NewSize = 896 m-XX: Export vorratio = 6

Adjust GC

GC is provided by the Java Virtual Machine and is a mechanism to reclaim heap space from objects conforming to garbage collection.

An object that meets the GC condition means that it is not from any active thread or any static reference that can be referenced. In other words, if all its references are null, an object meets the garbage collection condition.

Choosing the correct garbage collector algorithm is a key (but often overlooked) factor. There are several available garbage collectors:

Serial collector (-XX: + UseSerialGC ):It uses a single thread and stops other JVM threads for execution. This collector is suitable for small applications and is not recommended for enterprise applications.
Parallel collector (-XX: + UseParallelGC ):It executes the new generation GC in parallel, and J2SE 5.0 can also execute the old generation GC (-XX: + UseParallelOldGC) in parallel ). This collector is suitable for multi-processor machines and applications that require high throughput. It is also recommended to be used in applications that generate more Java heap fragments and allocate large-size objects at different times.
Concurrent collector (-XX: + UseConcMarkSweepGC ):It uses a single GC thread and executes most of the work in parallel with the application. It is suitable for applications with fast processor machines and strict service level protocols. It may be the best choice, and is also suitable for applications that use HttpSessions with a large set of long-lived periods.

New G1 collector

In Java 7, the new G1 ("spam first") Low-latency garbage collector is primarily enhanced to plan to replace CMS in the Hotspot JVM, a server-type collector, it targets multi-processor machines and uses a large amount of memory.

The collection of G1 is separated from the collector with physical isolation between the new generation and the old generation. G1 collector, even if there are generations, there is no physical isolation between the two generations.This collector divides the entire space into multiple intervals, allowing a group of intervals to be collected, instead of dividing the space into an absolute new generation and an old generation.

The key features of the G1 collector are:

1. G1 adopts the parallel architecture that is widely used in today's Hardware (Parallelism), The main advantage of G1 is the design of such a method, using all available CPU and utilization of all CPU processing capabilities, in order to improve performance and speed up garbage collection.
2. Another feature is that it treats younger objects (new objects) and older objects (surviving for a period of time) differently, which plays a key role in improving garbage collection. G1 focuses on young objects, which can recycle space by becoming old objects.
3. Heap compression (Heap compaction) To eliminate the fragmentation problem. Essentially, because G1 compresses data during processing, it copies objects from one interval in the heap to another. Due to compression, it will not encounter CMS fragmentation issues. This may always be allocated from the continuous available space, so that G1 has a consistent pause time over time.

Compared with CMS, G1 collectors are easier to use because they have fewer switches, making it easier to adjust virtual machines. G1 has been provided in JDK 7, and now people can try to use it. To use G1, you need to pass these two switch parameters:
-XX: + UnlockExperimentalVMOptions-XX: + UseG1GC

Use Large Memory Page

In another area of JVM tuning, applications can be significantly improved by using large memory pages. A large memory page is a feature of modern CPUs. It allows applications that require large memory to allocate memory in 2-4 MB instead of the standard 4 kb. From Java SE5.0, there is a cross-platform flag that requires large memory page settings:-XX: + UseLargePages (by default, Solaris is enabled, while Windows and Linux are disabled ).

The goal supported by the big page is to optimize the processor conversion backup buffer (TLB ). A Conversion backup buffer is a page conversion cache that stores the recently used virtual-to-physical address conversion. TLB is a scarce system resource. The loss of TLB may cause expensive processors to be read from hierarchical page tables, which may require access to multiple memories. By using a large page size, a single TLB item can represent a large memory range, which puts less pressure on TLB and improves the performance of memory-sensitive applications.

You can set a large memory page in a 64-bit JVM. (Red Hat Enterprise Linux 32-bit operating systems can allocate large pages, but you will get an invalid parameter error when starting JVM ). Sun JVM is the same as OpenJDK. To use a large page, you must pass the following options on the command line:-XX: + UseLargePages.

Application resource pool
The Application Server Pool provides the following benefits:

• Improved performance: You can reassign resource-sensitive objects, such as database connections, instead of creating and destroying them each time you use them.
• Enhanced Security: by granting a limited number of resources, you can prevent excessive use of server resources by applications, which may lead to service interruption.

The JBoss Application Server AS7 uses multiple resource pools to manage different types of services. The default configurations for all resource pools attached to the application server may only apply to simple applications. For critical applications, You need to properly configure the resource pool.

We will discuss the following pools that play an important role in performance tuning in the next chapter:
• Database Connection Pool
• The EJB pool and MDB used by stateless EJB
• Web Server Thread Pool

At the time of writing this article, the application server did not show the performance indicators of all subsystems we mentioned here. Even so, it is still the best way to monitor the application server pool through the management interface. You can still use other tools or observe the application server pool with the smallest sample application. This is what we will talk about in the next section. (Once performance adjustment indicators are available, we will update this article in time !)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.